├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .gitmodules
├── CMakeLists.txt
├── LICENSE.txt
├── README.md
├── build.bat
├── build.sh
└── src
└── main.cpp
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v2
12 | - name: Submodule SQLiteCpp
13 | run: |
14 | git submodule init
15 | git submodule update
16 | - name: CMake generate & build
17 | run: |
18 | mkdir -p build
19 | cd build
20 | cmake ..
21 | cmake --build .
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | Debug
2 | Release
3 | build
4 | example1
5 | *.a
6 |
7 | /SQLiteCpp.sln
8 | *.ncb
9 | *.suo
10 | *.user
11 | *sdf
12 | *.vc*
13 | *~
14 | doc
15 | core
16 | *ipch
17 | .settings/
18 |
19 | CMakeCache.txt
20 | CMakeFiles
21 | *.cmake
22 | *.dir
23 | Testing
24 | Win32
25 |
26 | SQLiteCpp_example1
27 | SQLiteCpp_tests
28 |
29 | !FindSQLiteCpp.cmake
30 | /SQLiteCpp_Example
31 |
32 | .idea/
33 | cmake-build-debug/
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "SQLiteCpp"]
2 | path = SQLiteCpp
3 | url = https://github.com/SRombauts/SQLiteCpp.git
4 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Example CMake file for compiling & linking a project with the the SQLiteCpp wrapper
2 | #
3 | # Copyright (c) 2012-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
4 | #
5 | # Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
6 | # or copy at http://opensource.org/licenses/MIT)
7 | cmake_minimum_required(VERSION 3.1) # for "CMAKE_CXX_STANDARD" version
8 | project(SQLiteCpp_Example VERSION 2.0)
9 |
10 | # SQLiteC++ 3.x now requires C++11 compiler
11 | set(CMAKE_CXX_STANDARD 11)
12 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
13 |
14 | # Add SQLite3 C++ wrapper around sqlite3 library (and sqlite3 itself provided for ease of use)
15 | # Here you can set CMake variables to avoid building Example, as well as cpplint, cppcheck...
16 | # or set them in the cmake command line (see for instance provided build.bat/build.sh scripts)
17 | set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "" FORCE)
18 | set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "" FORCE)
19 | add_subdirectory(SQLiteCpp)
20 |
21 | # Add main.cpp example source code to the executable
22 | add_executable(SQLiteCpp_Example src/main.cpp)
23 |
24 | # Link SQLiteCpp_example1 with SQLiteCpp
25 | target_link_libraries(SQLiteCpp_Example SQLiteCpp)
26 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2012-2016 Sebastien Rombauts (sebastien.rombauts@gmail.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is furnished
10 | to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
20 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SQLiteC++
2 | ---------
3 |
4 | [](https://github.com/SRombauts/SQLiteCpp/releases)
5 | [](https://github.com/SRombauts/SQLiteCpp/blob/master/LICENSE.txt)
6 | [](https://github.com/SRombauts/SQLiteCpp_Example/actions "GitHhub Actions Build status")
7 |
8 | [SQLiteC++ (SQLiteCpp)](https://github.com/SRombauts/SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper.
9 |
10 | [See SQLiteC++ website on GitHub](http://srombauts.github.com/SQLiteCpp).
11 |
12 | Keywords: sqlite, sqlite3, C, library, wrapper C++, simple example
13 |
14 | ## About SQLiteC++:
15 |
16 | SQLiteC++ offers an encapsulation around the native C APIs of SQLite,
17 | with a few intuitive and well documented C++ classes.
18 |
19 | ### License:
20 |
21 | Copyright (c) 2012-2020 Sébastien Rombauts (sebastien.rombauts@gmail.com)
22 |
23 |
24 | Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
25 | or copy at http://opensource.org/licenses/MIT)
26 |
27 | ## Getting started
28 | ### Git:
29 |
30 | Use git to clone the repository. Then init and update submodule "SQLiteCpp".
31 |
32 | ```Shell
33 | git clone https://github.com/SRombauts/SQLiteCpp_Example.git
34 | cd SQLiteCpp_Example
35 | git submodule init
36 | git submodule update
37 | ```
38 |
39 | ### CMake and build:
40 |
41 | Use build.bat or ./build.sh script, or cmake command line (example for Linux):
42 |
43 | ```Shell
44 | mkdir -p build
45 | cd build
46 |
47 | # Generate a Makefile for GCC (or Clang, depanding on CC/CXX envvar)
48 | cmake ..
49 |
50 | # Build (ie 'make')
51 | cmake --build .
52 | ```
53 |
54 | On Windows, you can also open the Visual Studio Solution (in the build/ subdirectory).
55 |
56 | ### Run
57 |
58 | Launch build/SQLiteCpp_Example(.exe) from the command line
59 |
60 | ## How to contribute
61 | ### GitHub website
62 | The most efficient way to help and contribute to this wrapper project is to
63 | use the tools provided by GitHub:
64 | - please fill bug reports and feature requests here: https://github.com/SRombauts/SQLiteCpp/issues
65 | - fork the repository, make some small changes and submit them with pull-request
66 |
67 |
--------------------------------------------------------------------------------
/build.bat:
--------------------------------------------------------------------------------
1 | @REM Copyright (c) 2012-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
2 | @REM
3 | @REM Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
4 | @REM or copy at http://opensource.org/licenses/MIT)
5 | mkdir build
6 | cd build
7 |
8 | @REM Generate a Visual Studio solution for latest version found
9 | cmake ..
10 | @if ERRORLEVEL 1 goto onError
11 |
12 | @REM Build default configuration (ie 'Debug')
13 | cmake --build .
14 | @if ERRORLEVEL 1 goto onError
15 |
16 | goto onSuccess
17 |
18 | :onError
19 | @echo An error occured!
20 | :onSuccess
21 | cd ..
22 |
--------------------------------------------------------------------------------
/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # Copyright (c) 2012-2020 Sébastien Rombauts (sebastien.rombauts@gmail.com)
3 | #
4 | # Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
5 | # or copy at http://opensource.org/licenses/MIT)
6 |
7 | # exit on first error
8 | set -e
9 |
10 | mkdir -p build
11 | cd build
12 |
13 | # Generate a Makefile for GCC (or Clang, depanding on CC/CXX envvar)
14 | cmake -DCMAKE_BUILD_TYPE=Debug ..
15 |
16 | # Build (ie 'make')
17 | cmake --build .
18 |
19 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | * @file main.cpp
3 | * @brief A few short examples in a row.
4 | *
5 | * Demonstrates how-to use the SQLite++ wrapper
6 | *
7 | * Copyright (c) 2012-2020 Sebastien Rombauts (sebastien.rombauts@gmail.com)
8 | *
9 | * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
10 | * or copy at http://opensource.org/licenses/MIT)
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 |
17 | #include
18 |
19 |
20 | #ifdef SQLITECPP_ENABLE_ASSERT_HANDLER
21 | namespace SQLite
22 | {
23 | /// definition of the assertion handler enabled when SQLITECPP_ENABLE_ASSERT_HANDLER is defined in the project (CMakeList.txt)
24 | void assertion_failed(const char* apFile, const long apLine, const char* apFunc, const char* apExpr, const char* apMsg)
25 | {
26 | // Print a message to the standard error output stream, and abort the program.
27 | std::cerr << apFile << ":" << apLine << ":" << " error: assertion failed (" << apExpr << ") in " << apFunc << "() with message \"" << apMsg << "\"\n";
28 | std::abort();
29 | }
30 | }
31 | #endif
32 |
33 | int main ()
34 | {
35 | // Using SQLITE_VERSION would require #include which we want to avoid: use SQLite::VERSION if possible.
36 | // std::cout << "SQlite3 version " << SQLITE_VERSION << std::endl;
37 | std::cout << "SQlite3 version " << SQLite::VERSION << " (" << SQLite::getLibVersion() << ")" << std::endl;
38 | std::cout << "SQliteC++ version " << SQLITECPP_VERSION << std::endl;
39 |
40 | ////////////////////////////////////////////////////////////////////////////
41 | // Simple batch queries example :
42 | try
43 | {
44 | // Open a database file in create/write mode
45 | SQLite::Database db("test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
46 | std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
47 |
48 | // Create a new table with an explicit "id" column aliasing the underlying rowid
49 | db.exec("DROP TABLE IF EXISTS test");
50 | db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)");
51 |
52 | // first row
53 | int nb = db.exec("INSERT INTO test VALUES (NULL, \"test\")");
54 | std::cout << "INSERT INTO test VALUES (NULL, \"test\")\", returned " << nb << std::endl;
55 |
56 | // second row
57 | nb = db.exec("INSERT INTO test VALUES (NULL, \"second\")");
58 | std::cout << "INSERT INTO test VALUES (NULL, \"second\")\", returned " << nb << std::endl;
59 |
60 | // update the second row
61 | nb = db.exec("UPDATE test SET value=\"second-updated\" WHERE id='2'");
62 | std::cout << "UPDATE test SET value=\"second-updated\" WHERE id='2', returned " << nb << std::endl;
63 |
64 | // Check the results : expect two row of result
65 | SQLite::Statement query(db, "SELECT * FROM test");
66 | std::cout << "SELECT * FROM test :\n";
67 | while (query.executeStep())
68 | {
69 | std::cout << "row (" << query.getColumn(0) << ", \"" << query.getColumn(1) << "\")\n";
70 | }
71 |
72 | db.exec("DROP TABLE test");
73 | }
74 | catch (std::exception& e)
75 | {
76 | std::cout << "SQLite exception: " << e.what() << std::endl;
77 | return EXIT_FAILURE; // unexpected error : exit the example program
78 | }
79 | remove("test.db3");
80 |
81 | std::cout << "everything ok, quitting\n";
82 |
83 | return EXIT_SUCCESS;
84 | }
85 |
--------------------------------------------------------------------------------