mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Adapting the CMake and test for Visual Studio under Windows
This commit is contained in:
parent
66ac428732
commit
66ea7c7fa5
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,8 +6,12 @@ build
|
|||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
*sdf
|
*sdf
|
||||||
|
*.vc*
|
||||||
*~
|
*~
|
||||||
doc
|
doc
|
||||||
core
|
core
|
||||||
*ipch
|
*ipch
|
||||||
.settings/
|
.settings/
|
||||||
|
|
||||||
|
CMakeCache.txt
|
||||||
|
*.cmake
|
||||||
|
@ -1,16 +1,28 @@
|
|||||||
cmake_minimum_required (VERSION 2.6)
|
cmake_minimum_required (VERSION 2.6)
|
||||||
project (SQLiteCpp)
|
project (SQLiteCpp)
|
||||||
add_definitions(-rdynamic -fstack-protector-all -Wall -Wextra -pedantic -Weffc++ -Wformat-security -Winit-self -Wswitch-default -Wswitch-enum -Wfloat-equal -Wundef -Wshadow -Wcast-qual -Wconversion -Wlogical-op -Winline -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn)
|
|
||||||
|
if(MSVC)
|
||||||
|
include_directories ("${PROJECT_SOURCE_DIR}/sqlite3")
|
||||||
|
add_library (sqlite3 sqlite3/sqlite3.c sqlite3/sqlite3.h)
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
add_definitions(-rdynamic -fstack-protector-all -Wall -Wextra -pedantic -Weffc++ -Wformat-security -Winit-self -Wswitch-default -Wswitch-enum -Wfloat-equal -Wundef -Wshadow -Wcast-qual -Wconversion -Wlogical-op -Winline -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=noreturn)
|
||||||
|
endif()
|
||||||
|
|
||||||
# add the wrapper as a library
|
# add the wrapper as a library
|
||||||
add_library(SQLiteCpp
|
add_library(SQLiteCpp
|
||||||
|
src/SQLiteC++.h
|
||||||
src/Column.cpp
|
src/Column.cpp
|
||||||
|
src/Column.h
|
||||||
src/Database.cpp
|
src/Database.cpp
|
||||||
|
src/Database.h
|
||||||
|
src/Exception.h
|
||||||
src/Statement.cpp
|
src/Statement.cpp
|
||||||
|
src/Statement.h
|
||||||
src/Transaction.cpp
|
src/Transaction.cpp
|
||||||
|
src/Transaction.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# add the exmple1 executable, linked with the wrapper library
|
# add the exemple1 executable, linked with the wrapper library
|
||||||
add_executable(example1 examples/example1/main.cpp)
|
add_executable(example1 examples/example1/main.cpp)
|
||||||
target_link_libraries (example1 SQLiteCpp sqlite3)
|
target_link_libraries (example1 SQLiteCpp sqlite3)
|
||||||
|
|
||||||
|
@ -89,6 +89,9 @@ Solutions for Visual Studio 2008 and 2010 are provided in the "msvc/" directory,
|
|||||||
#### CMake and test
|
#### CMake and test
|
||||||
A CMake configuration file is also provided for better multiplatform support and testing.
|
A CMake configuration file is also provided for better multiplatform support and testing.
|
||||||
|
|
||||||
|
Generating the Visual Studio 2010 Solution (similar for any other VS up to 2013):
|
||||||
|
cmake . -G "Visual Studio 10"
|
||||||
|
|
||||||
Generating the Linux Makefile, building in Debug and executing the tests:
|
Generating the Linux Makefile, building in Debug and executing the tests:
|
||||||
mkdir Debug
|
mkdir Debug
|
||||||
cd Debug
|
cd Debug
|
||||||
|
420
src/Column.h
420
src/Column.h
@ -1,41 +1,41 @@
|
|||||||
/**
|
/**
|
||||||
* @file Column.h
|
* @file Column.h
|
||||||
* @ingroup SQLiteCpp
|
* @ingroup SQLiteCpp
|
||||||
* @brief Encapsulation of a Column in a row of the result pointed by the prepared SQLite::Statement.
|
* @brief Encapsulation of a Column in a row of the result pointed by the prepared SQLite::Statement.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
|
* Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
|
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
|
||||||
* or copy at http://opensource.org/licenses/MIT)
|
* or copy at http://opensource.org/licenses/MIT)
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable APIs that provide convenient access to meta-data about tables and queries.
|
* @brief Enable APIs that provide convenient access to meta-data about tables and queries.
|
||||||
*
|
*
|
||||||
* @see #getName()
|
* @see #getName()
|
||||||
*
|
*
|
||||||
* @warning Requires this SQLITE_ENABLE_COLUMN_METADATA preprocessor macro to be also defined at compile times of the SQLite library.
|
* @warning Requires this SQLITE_ENABLE_COLUMN_METADATA preprocessor macro to be also defined at compile times of the SQLite library.
|
||||||
*/
|
*/
|
||||||
#define SQLITE_ENABLE_COLUMN_METADATA
|
#define SQLITE_ENABLE_COLUMN_METADATA
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Statement.h"
|
#include "Statement.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SQLite
|
namespace SQLite
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
* @brief Encapsulation of a Column in a row of the result pointed by the prepared Statement.
|
||||||
*
|
*
|
||||||
* A Column is a particular field of SQLite data in the current row of result
|
* A Column is a particular field of SQLite data in the current row of result
|
||||||
* of the Statement : it points to a single cell.
|
* of the Statement : it points to a single cell.
|
||||||
*
|
*
|
||||||
* Its value can be expressed as a text, and, when applicable, as a numeric
|
* Its value can be expressed as a text, and, when applicable, as a numeric
|
||||||
* (integer or floating point) or a binary blob.
|
* (integer or floating point) or a binary blob.
|
||||||
*
|
*
|
||||||
* Thread-safety: a Column object shall not be shared by multiple threads, because :
|
* Thread-safety: a Column object shall not be shared by multiple threads, because :
|
||||||
* 1) in the SQLite "Thread Safe" mode, "SQLite can be safely used by multiple threads
|
* 1) in the SQLite "Thread Safe" mode, "SQLite can be safely used by multiple threads
|
||||||
@ -43,175 +43,175 @@ namespace SQLite
|
|||||||
* 2) the SQLite "Serialized" mode is not supported by SQLiteC++,
|
* 2) the SQLite "Serialized" mode is not supported by SQLiteC++,
|
||||||
* because of the way it shares the underling SQLite precompiled statement
|
* because of the way it shares the underling SQLite precompiled statement
|
||||||
* in a custom shared pointer (See the inner class "Statement::Ptr").
|
* in a custom shared pointer (See the inner class "Statement::Ptr").
|
||||||
*/
|
*/
|
||||||
class Column
|
class Column
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Encapsulation of a Column in a Row of the result.
|
* @brief Encapsulation of a Column in a Row of the result.
|
||||||
*
|
*
|
||||||
* @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object.
|
* @param[in] aStmtPtr Shared pointer to the prepared SQLite Statement Object.
|
||||||
* @param[in] aIndex Index of the column in the row of result
|
* @param[in] aIndex Index of the column in the row of result
|
||||||
*/
|
*/
|
||||||
Column(Statement::Ptr& aStmtPtr, int aIndex) throw(); // nothrow
|
Column(Statement::Ptr& aStmtPtr, int aIndex) throw(); // nothrow
|
||||||
/// @brief Simple destructor
|
/// @brief Simple destructor
|
||||||
virtual ~Column(void) throw(); // nothrow
|
virtual ~Column(void) throw(); // nothrow
|
||||||
|
|
||||||
// default copy constructor and assignment operator are perfectly suited :
|
// default copy constructor and assignment operator are perfectly suited :
|
||||||
// they copy the Statement::Ptr which in turn increments the reference counter.
|
// they copy the Statement::Ptr which in turn increments the reference counter.
|
||||||
|
|
||||||
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
||||||
/**
|
/**
|
||||||
* @brief Return a pointer to the column name
|
* @brief Return a pointer to the column name
|
||||||
*
|
*
|
||||||
* Require definition of the SQLITE_ENABLE_COLUMN_METADATA preprocessor macro :
|
* Require definition of the SQLITE_ENABLE_COLUMN_METADATA preprocessor macro :
|
||||||
* - for compilation of the SQLite library,
|
* - for compilation of the SQLite library,
|
||||||
* - and also when compiling this wrapper.
|
* - and also when compiling this wrapper.
|
||||||
*/
|
*/
|
||||||
const char* getName (void) const throw(); // nothrow
|
const char* getName (void) const throw(); // nothrow
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// @brief Return the integer value of the column.
|
/// @brief Return the integer value of the column.
|
||||||
int getInt (void) const throw(); // nothrow
|
int getInt (void) const throw(); // nothrow
|
||||||
/// @brief Return the 64bits integer value of the column.
|
/// @brief Return the 64bits integer value of the column.
|
||||||
sqlite3_int64 getInt64 (void) const throw(); // nothrow
|
sqlite3_int64 getInt64 (void) const throw(); // nothrow
|
||||||
/// @brief Return the double (64bits float) value of the column.
|
/// @brief Return the double (64bits float) value of the column.
|
||||||
double getDouble(void) const throw(); // nothrow
|
double getDouble(void) const throw(); // nothrow
|
||||||
/**
|
/**
|
||||||
* @brief Return a pointer to the text value (NULL terminated string) of the column.
|
* @brief Return a pointer to the text value (NULL terminated string) of the column.
|
||||||
*
|
*
|
||||||
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
|
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
|
||||||
* thus you must copy it before using it beyond its scope (to a std::string for instance).
|
* thus you must copy it before using it beyond its scope (to a std::string for instance).
|
||||||
*/
|
*/
|
||||||
const char* getText (void) const throw(); // nothrow
|
const char* getText (void) const throw(); // nothrow
|
||||||
/**
|
/**
|
||||||
* @brief Return a pointer to the binary blob value of the column.
|
* @brief Return a pointer to the binary blob value of the column.
|
||||||
*
|
*
|
||||||
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
|
* @warning The value pointed at is only valid while the statement is valid (ie. not finalized),
|
||||||
* thus you must copy it before using it beyond its scope (to a std::string for instance).
|
* thus you must copy it before using it beyond its scope (to a std::string for instance).
|
||||||
*/
|
*/
|
||||||
const void* getBlob (void) const throw(); // nothrow
|
const void* getBlob (void) const throw(); // nothrow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the type of the value of the column
|
* @brief Return the type of the value of the column
|
||||||
*
|
*
|
||||||
* Return either SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL.
|
* Return either SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL.
|
||||||
*
|
*
|
||||||
* @warning After a type conversion (by a call to a getXxx on a Column of a Yyy type),
|
* @warning After a type conversion (by a call to a getXxx on a Column of a Yyy type),
|
||||||
* the value returned by sqlite3_column_type() is undefined.
|
* the value returned by sqlite3_column_type() is undefined.
|
||||||
*/
|
*/
|
||||||
int getType(void) const throw(); // nothrow
|
int getType(void) const throw(); // nothrow
|
||||||
|
|
||||||
/// @brief Test if the column is an integer type value (meaningful only before any conversion)
|
/// @brief Test if the column is an integer type value (meaningful only before any conversion)
|
||||||
inline bool isInteger(void) const throw() // nothrow
|
inline bool isInteger(void) const throw() // nothrow
|
||||||
{
|
{
|
||||||
return (SQLITE_INTEGER == getType());
|
return (SQLITE_INTEGER == getType());
|
||||||
}
|
}
|
||||||
/// @brief Test if the column is a floating point type value (meaningful only before any conversion)
|
/// @brief Test if the column is a floating point type value (meaningful only before any conversion)
|
||||||
inline bool isFloat(void) const throw() // nothrow
|
inline bool isFloat(void) const throw() // nothrow
|
||||||
{
|
{
|
||||||
return (SQLITE_FLOAT == getType());
|
return (SQLITE_FLOAT == getType());
|
||||||
}
|
}
|
||||||
/// @brief Test if the column is a text type value (meaningful only before any conversion)
|
/// @brief Test if the column is a text type value (meaningful only before any conversion)
|
||||||
inline bool isText(void) const throw() // nothrow
|
inline bool isText(void) const throw() // nothrow
|
||||||
{
|
{
|
||||||
return (SQLITE_TEXT == getType());
|
return (SQLITE_TEXT == getType());
|
||||||
}
|
}
|
||||||
/// @brief Test if the column is a binary blob type value (meaningful only before any conversion)
|
/// @brief Test if the column is a binary blob type value (meaningful only before any conversion)
|
||||||
inline bool isBlob(void) const throw() // nothrow
|
inline bool isBlob(void) const throw() // nothrow
|
||||||
{
|
{
|
||||||
return (SQLITE_BLOB == getType());
|
return (SQLITE_BLOB == getType());
|
||||||
}
|
}
|
||||||
/// @brief Test if the column is NULL (meaningful only before any conversion)
|
/// @brief Test if the column is NULL (meaningful only before any conversion)
|
||||||
inline bool isNull(void) const throw() // nothrow
|
inline bool isNull(void) const throw() // nothrow
|
||||||
{
|
{
|
||||||
return (SQLITE_NULL == getType());
|
return (SQLITE_NULL == getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the number of bytes used by the text (or blob) value of the column
|
* @brief Return the number of bytes used by the text (or blob) value of the column
|
||||||
*
|
*
|
||||||
* Return either :
|
* Return either :
|
||||||
* - size in bytes (not in characters) of the string returned by getText() without the '\0' terminator
|
* - size in bytes (not in characters) of the string returned by getText() without the '\0' terminator
|
||||||
* - size in bytes of the string representation of the numerical value (integer or double)
|
* - size in bytes of the string representation of the numerical value (integer or double)
|
||||||
* - size in bytes of the binary blob returned by getBlob()
|
* - size in bytes of the binary blob returned by getBlob()
|
||||||
* - 0 for a NULL value
|
* - 0 for a NULL value
|
||||||
*/
|
*/
|
||||||
int getBytes(void) const throw();
|
int getBytes(void) const throw();
|
||||||
|
|
||||||
/// @brief Alias returning the number of bytes used by the text (or blob) value of the column
|
/// @brief Alias returning the number of bytes used by the text (or blob) value of the column
|
||||||
inline int size(void) const throw()
|
inline int size(void) const throw()
|
||||||
{
|
{
|
||||||
return getBytes ();
|
return getBytes ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Inline cast operator to int
|
/// @brief Inline cast operator to int
|
||||||
inline operator int() const
|
inline operator int() const
|
||||||
{
|
{
|
||||||
return getInt();
|
return getInt();
|
||||||
}
|
}
|
||||||
/// @brief Inline cast operator to 64bits integer
|
/// @brief Inline cast operator to 64bits integer
|
||||||
inline operator sqlite3_int64() const
|
inline operator sqlite3_int64() const
|
||||||
{
|
{
|
||||||
return getInt64();
|
return getInt64();
|
||||||
}
|
}
|
||||||
/// @brief Inline cast operator to double
|
/// @brief Inline cast operator to double
|
||||||
inline operator double() const
|
inline operator double() const
|
||||||
{
|
{
|
||||||
return getDouble();
|
return getDouble();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Inline cast operator to char*
|
* @brief Inline cast operator to char*
|
||||||
*
|
*
|
||||||
* @see getText
|
* @see getText
|
||||||
*/
|
*/
|
||||||
inline operator const char*() const
|
inline operator const char*() const
|
||||||
{
|
{
|
||||||
return getText();
|
return getText();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Inline cast operator to void*
|
* @brief Inline cast operator to void*
|
||||||
*
|
*
|
||||||
* @see getBlob
|
* @see getBlob
|
||||||
*/
|
*/
|
||||||
inline operator const void*() const
|
inline operator const void*() const
|
||||||
{
|
{
|
||||||
return getBlob();
|
return getBlob();
|
||||||
}
|
}
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
// NOTE : the following is required by GCC to cast a Column result in a std::string
|
// NOTE : the following is required by GCC to cast a Column result in a std::string
|
||||||
// (error: conversion from ‘SQLite::Column’ to non-scalar type ‘std::string {aka std::basic_string<char>}’ requested)
|
// (error: conversion from ‘SQLite::Column’ to non-scalar type ‘std::string {aka std::basic_string<char>}’ requested)
|
||||||
// but is not working under Microsoft Visual Studio 2010 and 2012
|
// but is not working under Microsoft Visual Studio 2010 and 2012
|
||||||
// (error C2440: 'initializing' : cannot convert from 'SQLite::Column' to 'std::basic_string<_Elem,_Traits,_Ax>'
|
// (error C2440: 'initializing' : cannot convert from 'SQLite::Column' to 'std::basic_string<_Elem,_Traits,_Ax>'
|
||||||
// [...] constructor overload resolution was ambiguous)
|
// [...] constructor overload resolution was ambiguous)
|
||||||
/// Inline cast operator to std::string
|
/// Inline cast operator to std::string
|
||||||
inline operator const std::string() const
|
inline operator const std::string() const
|
||||||
{
|
{
|
||||||
return getText();
|
return getText();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// @brief Return UTF-8 encoded English language explanation of the most recent error.
|
/// @brief Return UTF-8 encoded English language explanation of the most recent error.
|
||||||
inline const char* errmsg(void) const
|
inline const char* errmsg(void) const
|
||||||
{
|
{
|
||||||
return sqlite3_errmsg(mStmtPtr);
|
return sqlite3_errmsg(mStmtPtr);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Statement::Ptr mStmtPtr; //!< Shared Pointer to the prepared SQLite Statement Object
|
Statement::Ptr mStmtPtr; //!< Shared Pointer to the prepared SQLite Statement Object
|
||||||
int mIndex; //!< Index of the column in the row of result
|
int mIndex; //!< Index of the column in the row of result
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Standard std::ostream text inserter
|
* @brief Standard std::ostream text inserter
|
||||||
*
|
*
|
||||||
* Insert the text value of the Column object, using getText(), into the provided stream.
|
* Insert the text value of the Column object, using getText(), into the provided stream.
|
||||||
*
|
*
|
||||||
* @param[in] aStream Stream to use
|
* @param[in] aStream Stream to use
|
||||||
* @param[in] aColumn Column object to insert into the provided stream
|
* @param[in] aColumn Column object to insert into the provided stream
|
||||||
*
|
*
|
||||||
* @return Reference to the stream used
|
* @return Reference to the stream used
|
||||||
*/
|
*/
|
||||||
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn);
|
std::ostream& operator<<(std::ostream& aStream, const Column& aColumn);
|
||||||
|
|
||||||
|
|
||||||
} // namespace SQLite
|
} // namespace SQLite
|
||||||
|
Loading…
x
Reference in New Issue
Block a user