Merge pull request #1 from SRombauts/master

Update SQLiteCpp
This commit is contained in:
Mattes D 2015-04-19 14:53:26 +02:00
commit b17195b8d0
21 changed files with 154964 additions and 137258 deletions

View File

@ -1,5 +1,8 @@
# Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
language: cpp
# compilers to add to build matrix
compiler:
- gcc
- clang
@ -8,12 +11,13 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq cppcheck
# using a symbolic link to get the "make test" to work as if launched from the root directorys
# scripts to run before build
before_script:
- mkdir build
- cd build
- cmake ..
- ln -s ../examples examples
script: make && ctest --output-on-failure
- cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON -DSQLITECPP_RUN_DOXYGEN=OFF ..
# build examples, and run tests (ie make & make test)
script:
- cmake --build .
- ctest --output-on-failure

View File

@ -1,10 +1,25 @@
if (BIICODE)
# biicode doesn't process files bigger than 5Mb
list(APPEND BII_LIB_SRC sqlite3/sqlite3.c)
# Include base block dir
ADD_BIICODE_TARGETS()
# Link target with dl for linux
if (UNIX)
TARGET_LINK_LIBRARIES(${BII_BLOCK_TARGET} INTERFACE pthread)
if(NOT APPLE)
TARGET_LINK_LIBRARIES(${BII_BLOCK_TARGET} INTERFACE dl)
endif()
endif()
else (BIICODE)
# Main CMake file for compiling the library itself, examples and tests.
#
# Copyright (c) 2012-2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
# Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
#
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
# or copy at http://opensource.org/licenses/MIT)
cmake_minimum_required(VERSION 2.6)
project(SQLiteCpp)
@ -96,21 +111,34 @@ source_group(example1 FILES ${SQLITECPP_EXAMPLES})
# list of doc files of the library
set(SQLITECPP_DOC
README.md
WRAPPERS.md
LICENSE.txt
CHANGELOG.txt
TODO.txt
)
source_group(doc FILES ${SQLITECPP_DOC})
# list of script files of the library
set(SQLITECPP_SCRIPT
.travis.yml
appveyor.yml
biicode.conf
build.bat
build.sh
cpplint.py
Doxyfile
FindSQLiteCpp.cmake
)
source_group(scripts FILES ${SQLITECPP_SCRIPT})
# All includes are relative to the "include" directory
include_directories("${PROJECT_SOURCE_DIR}/include")
# add sources of the wrapper as a "SQLiteCpp" static library
add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC})
add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT})
if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC")
endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
# SQLite3 library (Windows only)
@ -129,22 +157,30 @@ endif (WIN32)
option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON)
if (SQLITECPP_RUN_CPPLINT)
find_package(PythonLibs)
if (PYTHONLIBS_FOUND)
# add a cpplint target to the "all" target
add_custom_target(SQLiteCpp_cpplint
ALL
COMMAND python ${PROJECT_SOURCE_DIR}/cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${SQLITECPP_SRC} ${SQLITECPP_INC}
)
endif (PYTHONLIBS_FOUND)
else (SQLITECPP_RUN_CPPLINT)
message(STATUS "SQLITECPP_RUN_CPPLINT OFF")
endif (SQLITECPP_RUN_CPPLINT)
option(SQLITECPP_RUN_CPPCHECK "Run cppcheck C++ static analysis tool." ON)
if (SQLITECPP_RUN_CPPCHECK)
find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
if (CPPCHECK_EXECUTABLE)
# add a cppcheck target to the "all" target
add_custom_target(SQLiteCpp_cppcheck
ALL
COMMAND cppcheck -j 4 cppcheck --enable=style --quiet ${CPPCHECK_ARG_TEMPLATE} ${PROJECT_SOURCE_DIR}/src
)
else (CPPCHECK_EXECUTABLE)
message(STATUS "Could NOT find cppcheck")
endif (CPPCHECK_EXECUTABLE)
else (SQLITECPP_RUN_CPPCHECK)
message(STATUS "SQLITECPP_RUN_CPPCHECK OFF")
endif (SQLITECPP_RUN_CPPCHECK)
@ -159,14 +195,12 @@ if (SQLITECPP_RUN_DOXYGEN)
COMMAND doxygen Doxyfile > ${DEV_NULL}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
else (DOXYGEN_FOUND)
message(STATUS "Doxygen not found")
endif (DOXYGEN_FOUND)
else (SQLITECPP_RUN_DOXYGEN)
message(STATUS "SQLITECPP_RUN_DOXYGEN OFF")
endif (SQLITECPP_RUN_DOXYGEN)
option(SQLITECPP_BUILD_EXAMPLES "Build examples." ON)
option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF)
if (SQLITECPP_BUILD_EXAMPLES)
# add the basic example executable
add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES})
@ -175,7 +209,7 @@ else(SQLITECPP_BUILD_EXAMPLES)
message(STATUS "SQLITECPP_BUILD_EXAMPLES OFF")
endif(SQLITECPP_BUILD_EXAMPLES)
option(SQLITECPP_BUILD_TESTS "Build and run tests." ON)
option(SQLITECPP_BUILD_TESTS "Build and run tests." OFF)
if (SQLITECPP_BUILD_TESTS)
# add the subdirectory containing the CMakeLists.txt for the gtest library
if (NOT MSVC)
@ -202,3 +236,5 @@ if (SQLITECPP_BUILD_TESTS)
else (SQLITECPP_BUILD_TESTS)
message(STATUS "SQLITECPP_BUILD_TESTS OFF")
endif (SQLITECPP_BUILD_TESTS)
endif (BIICODE)

View File

@ -1801,18 +1801,6 @@ GENERATE_XML = NO
XML_OUTPUT = xml
# The XML_SCHEMA tag can be used to specify a XML schema, which can be used by a
# validating XML parser to check the syntax of the XML files.
# This tag requires that the tag GENERATE_XML is set to YES.
XML_SCHEMA =
# The XML_DTD tag can be used to specify a XML DTD, which can be used by a
# validating XML parser to check the syntax of the XML files.
# This tag requires that the tag GENERATE_XML is set to YES.
XML_DTD =
# If the XML_PROGRAMLISTING tag is set to YES doxygen will dump the program
# listings (including syntax highlighting and cross-referencing information) to
# the XML output. Note that enabling this will significantly increase the size

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2012-2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,7 +1,10 @@
SQLiteC++
---------
![SQLiteCpp build status](https://api.travis-ci.org/SRombauts/SQLiteCpp.png "SQLiteCpp build status")
[![Travis CI Linux Build Status](https://travis-ci.org/SRombauts/SQLiteCpp.svg)](https://travis-ci.org/SRombauts/SQLiteCpp "Travis CI Linux Build Status")
[![AppVeyor Windows Build status](https://ci.appveyor.com/api/projects/status/github/SRombauts/SQLiteCpp?svg=true)](https://ci.appveyor.com/project/SbastienRombauts/SQLiteCpp "AppVeyor Windows Build status")
[![Build Status](https://webapi.biicode.com/v1/badges/sqlite/sqlite/sqlite/master)](https://www.biicode.com/sqlite/sqlite)
SQLiteC++ (SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper.
@ -76,11 +79,8 @@ Under Debian/Ubuntu/Mint Linux, install the libsqlite3-dev package.
### Building the examples:
A basic Makefile is provided, tested under Linux/Ubuntu 12.10, requiring the sqlite3 static library (sqlite3-dev Debian/Ubuntu package)
Solutions for Visual Studio 2008 and 2010 are provided in the "msvc/" directory, directly using the sqlite3.c source code for ease of use.
#### CMake and test
A CMake configuration file is also provided for better multiplatform support and testing.
A CMake configuration file is also provided for multiplatform support and testing.
Typical generic build (see also "build.bat" or "./build.sh"):
@ -121,8 +121,12 @@ You can either recompile it yourself (seek help online) or you can comment out t
This project is continuously tested under Ubuntu Linux with the gcc and clang compilers
using the Travis CI community service with the above CMake building and testing procedure.
It is also tested in the same way under Windows Server 2012 R2 with Visual Studio 2013 compiler
using the AppVeyor countinuous integration service.
Detailed results can be seen online: https://travis-ci.org/SRombauts/SQLiteCpp
Detailed results can be seen online:
- https://travis-ci.org/SRombauts/SQLiteCpp
- https://ci.appveyor.com/project/SbastienRombauts/SQLiteCpp
### Thread-safety
@ -142,7 +146,7 @@ in a custom shared pointer (See the inner class "Statement::Ptr").
### License
Copyright (c) 2012-2014 Sébastien Rombauts (sebastien.rombauts@gmail.com)
Copyright (c) 2012-2015 Sébastien Rombauts (sebastien.rombauts@gmail.com)
Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
or copy at http://opensource.org/licenses/MIT)
@ -246,10 +250,10 @@ See also http://www.appinf.com/download/CppCodingStyleGuide.pdf for good guideli
## See also - Some other simple C++ SQLite wrappers:
See also the file WRAPPERS.md offering a more complete comparison of other wrappers.
- [sqdbcpp](http://code.google.com/p/sqdbcpp/): RAII design, simple, no depandencies, UTF-8/UTF-16, new BSD license
See bellow a short comparison of other wrappers done at the time of the writting:
- [sqdbcpp](http://code.google.com/p/sqdbcpp/): RAII design, simple, no dependencies, UTF-8/UTF-16, new BSD license
- [sqlite3cc](http://ed.am/dev/sqlite3cc): uses boost, modern design, LPGPL
- [sqlite3pp](http://code.google.com/p/sqlite3pp/): uses boost, but never updated since initial publication in may 2012, MIT License
- [sqlite3pp](https://github.com/iwongu/sqlite3pp): modern design inspired by boost, MIT License
- [SQLite++](http://sqlitepp.berlios.de/): uses boost build system, Boost License 1.0
- [CppSQLite](http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper-for-SQLite/): famous Code Project but old design, BSD License
- [easySQLite](http://code.google.com/p/easysqlite/): manages table as structured objects, complex

View File

@ -1,83 +0,0 @@
http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers
http://stackoverflow.com/questions/120295/what-is-a-good-oo-c-wrapper-for-sqlite
http://stackoverflow.com/questions/818155/sqlite-alternatives-for-c
http://www.reddit.com/search?q=sqlite
**sqlite3cc**: http://ed.am/dev/sqlite3cc/
- Nov 2009, Jan 2012 (v0.1)
- (++) modern design, use RAII => can be a source of inspiration for me
- (++) very well documented, in code and with a very good informal presentation
- (+) is maintained (recent), initial release is 0.1.0, January 2012 (started in 2010)
- (+/-) uses boost (some more dependancies...)
- (-) uses boost coding style (I tend to prefer CamelCaps or Java coding style)
- (-) a bit complex: offer many way to do the same thing where I would prefer a clean choice
- (-) thus it does not impose RAII, as it is still possible to open or close a database outside constructor/destructor
- (---) LPGPL: for me, this is a stopper as I would like to be able to use it in commercial products
- bazaar: http://bzr.ed.am/sqlite3cc
- bugtracker: personal: trac is still to be installed to http://dev.ed.am/sqlite3cc
- test suite: a simple main with boost filesystem (build librairy) depandancy
**sqdbcpp**: http://code.google.com/p/sqdbcpp/
- Dec 2009 (no more activity)
- (++) new BSD license
- (++) RAII design, with some good ideas, like the "Convertor" class
- (++) modern design, use RAII
- (+) CamelCaps naming convention
- (+) STL is the only depandancy
- (+) very small code
- (-) not RAII transactions
- (-) some unnecessary complexity to manage copyable objects (RefCount)
- (-) UTF-8/UTF-16: the second is not portable
- (--) Not documented (only a short example
- (---) Not maintained/not finished: contact author !?
- SVN: http://sqdbcpp.googlecode.com/svn/trunk/
- bugtracker: GoogleCode: http://code.google.com/p/sqdbcpp/issues/list
- test suite: with gtest
**sqlite3pp**: http://code.google.com/p/sqlite3pp/
- Sep 2007 to Mar 2009
- (++) MIT License
- (++) modern design, use RAII => can be a source of inspiration for me
- (+/-) uses boost (some more dependancies...)
- (-) complex: offer many way to do the same thing, and advance functionalities
- (--) Not documented in code
- (---) Not maintained, many open issues
- SVN: http://sqlite3pp.googlecode.com/svn/trunk/
- bugtracker: GoogleCode: http://code.google.com/p/sqlite3pp/issues/list
**SQLite++**: http://sqlitepp.berlios.de/
- Jan 2006 until now (Apr 2012)
- (++) still maintained
- (++) Boost License 1.0
- (+) good online introduction
- (+/-) uses boost (some more dependancies...)
- (-) uses boost build system
- (-) come with yet another unicode string library
- (-) too complex and big to dive easily into
- (--) Not documented in code
- SVN: https://svn.berlios.de/svnroot/repos/sqlitepp/trunk/
- bugtracker: no!
- test suite: yes, with bjam
**CppSQLite**: http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper-for-SQLite/
- Mar 2004, Jun 2011
- (++??) BSD License? CodeProject License?
- (+) famous CodeProject, good introductory article
- (--) Not documented in code
- (--) old design, no RAII
- (--) unnecessary complex memory allocation for exception
- VCS: no! but cloned twice on GitHub
- bugtracker: no!
- test suite: no, only some demo code.
**easySQLite**: http://code.google.com/p/easysqlite/
- Sep 2010
- (++) new BSD license
- (+/-) Manage table as objects, requiring to define their structure
- (-) not RAII
- (--) complex
- (---) Not maintained, some open issues
- SVN: http://easysqlite.googlecode.com/svn/trunk/
- bugtracker: http://code.google.com/p/easysqlite/source/list
- test suite: yes, a big one, with UnitTest++

26
appveyor.yml Normal file
View File

@ -0,0 +1,26 @@
# Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
# build format
version: "{build}"
# scripts that run after cloning repository
# NOTE : not updating submodule as cloning googletest does not work on AppVeyor
install:
# - git submodule update --init googletest
# configurations to add to build matrix
configuration:
- Debug
- Release
# scripts to run before build
# NOTE : no unit tests as cloning googletest does not work on AppVeyor
before_build:
- mkdir build
- cd build
- cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=OFF -DSQLITECPP_RUN_CPPCHECK=OFF -DSQLITECPP_RUN_DOXYGEN=OFF ..
# build examples, and run tests (ie make & make test)
build_script:
- cmake --build .
# - ctest --output-on-failure

43
biicode.conf Normal file
View File

@ -0,0 +1,43 @@
# Biicode configuration file
[requirements]
# Blocks and versions this block depends on e.g.
google/gtest : 9
[parent]
# The parent version of this block. Must match folder name. E.g.
# user/block # No version number means not published yet
# You can change it to publish to a different track, and change version, e.g.
sqlite/sqlite: 7
[paths]
# Local directories to look for headers (within block)
include
/
sqlite3
[dependencies]
# Manual adjust file implicit dependencies, add (+), remove (-), or overwrite (=)
include/SQLiteCpp/Assertion.h - tests/Database_test.cpp
include/SQLiteCpp/Assertion.h - examples/example1/main.cpp
[mains]
# Manual adjust of files that define an executable
# !main.cpp # Do not build executable from this file
# main2.cpp # Build it (it doesnt have a main() function, but maybe it includes it)
[hooks]
# These are defined equal to [dependencies],files names matching bii*stage*hook.py
# will be launched as python scripts at stage = {post_process, clean}
# CMakeLists.txt + bii/my_post_process1_hook.py bii_clean_hook.py
[includes]
# Mapping of include patterns to external blocks
gtest/gtest.h: google/gtest/include
[data]
# Manually define data files dependencies, that will be copied to bin for execution
# By default they are copied to bin/user/block/... which should be taken into account
# when loading from disk such data
examples/example1/main.cpp + example.db3 logo.png

View File

@ -1,18 +1,17 @@
@REM Copyright (c) 2013 Sébastien Rombauts (sebastien.rombauts@gmail.com)
@REM Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
@REM
@REM Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
@REM or copy at http://opensource.org/licenses/MIT)
mkdir build
cd build
@REM generate solution for Visual Studio 2010, and build it
cmake .. -G "Visual Studio 10"
@REM Generate a Visual Studio solution for latest version found
cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
@REM Build default configuration (ie 'Debug')
cmake --build .
@REM prepare and launch tests
mkdir examples
mkdir examples\example1
copy ..\examples\example1\example.db3 examples\example1
copy ..\examples\example1\logo.png examples\example1
@REM Build and run tests
ctest --output-on-failure
cd ..

View File

@ -1,16 +1,15 @@
# Copyright (c) 2013 Sébastien Rombauts (sebastien.rombauts@gmail.com)
# Copyright (c) 2012-2015 Sébastien Rombauts (sebastien.rombauts@gmail.com)
#
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
# or copy at http://opensource.org/licenses/MIT)
mkdir -p build
cd build
# generate solution for GCC
cmake ..
# Generate a Makefile for GCC (or Clang, depanding on CC/CXX envvar)
cmake -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
# Build (ie 'make')
cmake --build .
# prepare and launch tests
mkdir -p examples/example1
cp ../examples/example1/example.db3 examples/example1
cp ../examples/example1/logo.png examples/example1
# Build and run unit-tests (ie 'make test')
ctest --output-on-failure

View File

@ -13,8 +13,7 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#include <string>
#include <SQLiteCpp/SQLiteCpp.h>
@ -31,10 +30,17 @@ void assertion_failed(const char* apFile, const long apLine, const char* apFunc,
}
#endif
/// Get example path
static inline std::string getExamplePath()
{
std::string filePath(__FILE__);
return filePath.substr( 0, filePath.length() - std::string("main.cpp").length());
}
/// Example Database
static const char* filename_example_db3 = "examples/example1/example.db3";
static const std::string filename_example_db3 = getExamplePath() + "/example.db3";
/// Image
static const char* filename_logo_png = "examples/example1/logo.png";
static const std::string filename_logo_png = getExamplePath() + "/logo.png";
/// Object Oriented Basic example
@ -307,7 +313,7 @@ int main ()
db.exec("DROP TABLE IF EXISTS test");
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value BLOB)");
FILE* fp = fopen(filename_logo_png, "rb");
FILE* fp = fopen(filename_logo_png.c_str(), "rb");
if (NULL != fp)
{
char buffer[16*1024];

@ -1 +1 @@
Subproject commit be1b3b66822cc3929f3da700973cef88bf45849a
Subproject commit 4650552ff637bb44ecf7784060091cbed3252211

View File

@ -37,8 +37,6 @@ namespace SQLite
* 2) the SQLite "Serialized" mode is not supported by SQLiteC++,
* because of the way it shares the underling SQLite precompiled statement
* in a custom shared pointer (See the inner class "Statement::Ptr").
*
* @todo inline all simple getters
*/
class Column
{

View File

@ -3,7 +3,7 @@
* @ingroup SQLiteCpp
* @brief Management of a SQLite Database Connection.
*
* Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
@ -239,17 +239,25 @@ public:
return sqlite3_total_changes(mpSQLite);
}
/**
* @brief Return the filename used to open the database
*/
/// @brief Return the filename used to open the database.
inline const std::string& getFilename() const noexcept // nothrow
{
return mFilename;
}
/**
* @brief Return UTF-8 encoded English language explanation of the most recent error.
*/
/// @brief Return the numeric result code for the most recent failed API call (if any).
inline int getErrorCode() const noexcept // nothrow
{
return sqlite3_errcode(mpSQLite);
}
/// @brief Return the extended numeric result code for the most recent failed API call (if any).
inline int getExtendedErrorCode() const noexcept // nothrow
{
return sqlite3_extended_errcode(mpSQLite);
}
/// Return UTF-8 encoded English language explanation of the most recent failed API call (if any).
inline const char* errmsg() const noexcept // nothrow
{
return sqlite3_errmsg(mpSQLite);

View File

@ -3,7 +3,7 @@
* @ingroup SQLiteCpp
* @brief A prepared SQLite Statement is a compiled SQL query ready to be executed, pointing to a row of result.
*
* Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
@ -269,7 +269,7 @@ public:
////////////////////////////////////////////////////////////////////////////
/**
* @brief Return a copie of the column data specified by its index
* @brief Return a copy of the column data specified by its index
*
* Can be used to access the data of the current row of result when applicable,
* while the executeStep() method returns true.
@ -326,8 +326,18 @@ public:
{
return mbDone;
}
/// @brief Return UTF-8 encoded English language explanation of the most recent error.
inline const char* errmsg() const
/// @brief Return the numeric result code for the most recent failed API call (if any).
inline int getErrorCode() const noexcept // nothrow
{
return sqlite3_errcode(mStmtPtr);
}
/// @brief Return the extended numeric result code for the most recent failed API call (if any).
inline int getExtendedErrorCode() const noexcept // nothrow
{
return sqlite3_extended_errcode(mStmtPtr);
}
/// Return UTF-8 encoded English language explanation of the most recent failed API call (if any).
inline const char* errmsg() const noexcept // nothrow
{
return sqlite3_errmsg(mStmtPtr);
}
@ -385,7 +395,7 @@ private:
*
* @param[in] SQLite return code to test against the SQLITE_OK expected value
*/
void check(const int aRet) const;
void check(const int aRet);
private:
std::string mQuery; //!< UTF-8 SQL Query

View File

@ -1,4 +1,4 @@
"sqlite3.c" and "sqlite3.h" files from sqlite-amalgamation-3071401.zip (SQLite 3.7.14.1)
"sqlite3.c" and "sqlite3.h" files from sqlite-amalgamation-3080803.zip (SQLite 3.8.8.3)
Those files are provided for easy setup under Windows ; they are used by the Visual Studio example solution.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
* @ingroup SQLiteCpp
* @brief A prepared SQLite Statement is a compiled SQL query ready to be executed, pointing to a row of result.
*
* Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
@ -200,7 +200,7 @@ bool Statement::executeStep()
}
else
{
throw SQLite::Exception("Statement need to be reseted");
throw SQLite::Exception("Statement needs to be reset");
}
return mbOk; // true only if one row is accessible by getColumn(N)
@ -272,7 +272,7 @@ bool Statement::isColumnNull(const int aIndex) const
}
// Check if aRet equal SQLITE_OK, else throw a SQLite::Exception with the SQLite error message
void Statement::check(const int aRet) const
void Statement::check(const int aRet)
{
if (SQLITE_OK != aRet)
{
@ -337,11 +337,9 @@ Statement::Ptr::~Ptr() noexcept // nothrow
--(*mpRefCount);
if (0 == *mpRefCount)
{
// If count reaches zero, finalize the sqlite3_stmt,
// as no Statement not Column objet use it anymore
int ret = sqlite3_finalize(mpStmt);
// Never throw an exception in a destructor
SQLITECPP_ASSERT(SQLITE_OK == ret, sqlite3_errmsg(mpSQLite)); // See SQLITECPP_ENABLE_ASSERT_HANDLER
// If count reaches zero, finalize the sqlite3_stmt, as no Statement nor Column objet use it anymore.
// No need to check the return code, as it is the same as the last statement evaluation.
sqlite3_finalize(mpStmt);
// and delete the reference counter
delete mpRefCount;

View File

@ -3,7 +3,7 @@
* @ingroup tests
* @brief Test of a SQLiteCpp Database.
*
* Copyright (c) 2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
@ -146,15 +146,23 @@ TEST(Database, execException) {
{
// Create a new database
SQLite::Database db("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
EXPECT_EQ(SQLITE_OK, db.getErrorCode());
EXPECT_EQ(SQLITE_OK, db.getExtendedErrorCode());
// exception with SQL error: "no such table"
EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"), SQLite::Exception);
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
// Create a new table
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)");
EXPECT_EQ(SQLITE_OK, db.getErrorCode());
EXPECT_EQ(SQLITE_OK, db.getExtendedErrorCode());
// exception with SQL error: "table test has 3 columns but 2 values were supplied"
EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, 3)"), SQLite::Exception);
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
// exception with SQL error: "No row to get a column from"
EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"first\""), SQLite::Exception);
@ -162,7 +170,6 @@ TEST(Database, execException) {
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"));
// exception with SQL error: "No row to get a column from"
EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"second\""), SQLite::Exception);
} // Close DB test.db3
remove("test.db3");
}

View File

@ -3,7 +3,7 @@
* @ingroup tests
* @brief Test of a SQLiteCpp Statement.
*
* Copyright (c) 2014 Sebastien Rombauts (sebastien.rombauts@gmail.com)
* Copyright (c) 2012-2015 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
@ -22,11 +22,17 @@ TEST(Statement, invalid) {
{
// Create a new database
SQLite::Database db("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
EXPECT_EQ(SQLITE_OK, db.getErrorCode());
EXPECT_EQ(SQLITE_OK, db.getExtendedErrorCode());
// Compile a SQL query, but without any table in the database
EXPECT_THROW(SQLite::Statement query(db, "SELECT * FROM test"), SQLite::Exception);
EXPECT_EQ(SQLITE_ERROR, db.getErrorCode());
EXPECT_EQ(SQLITE_ERROR, db.getExtendedErrorCode());
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
EXPECT_EQ(SQLITE_OK, db.getErrorCode());
EXPECT_EQ(SQLITE_OK, db.getExtendedErrorCode());
// Compile a SQL query with no parameter
SQLite::Statement query(db, "SELECT * FROM test");
@ -61,6 +67,8 @@ TEST(Statement, invalid) {
EXPECT_THROW(query.bind(2, 123), SQLite::Exception);
EXPECT_THROW(query.bind(0, "abc"), SQLite::Exception);
EXPECT_THROW(query.bind(0), SQLite::Exception);
EXPECT_EQ(SQLITE_RANGE, db.getErrorCode());
EXPECT_EQ(SQLITE_RANGE, db.getExtendedErrorCode());
query.exec();
EXPECT_THROW(query.isColumnNull(0), SQLite::Exception);