File tree Expand file tree Collapse file tree 4 files changed +86
-0
lines changed Expand file tree Collapse file tree 4 files changed +86
-0
lines changed Original file line number Diff line number Diff line change 1+ name : CppSQLite CI
2+
3+ on :
4+ push :
5+ branches : [ master ]
6+ pull_request :
7+ branches : [ master ]
8+
9+ jobs :
10+ build-and-test :
11+ runs-on : ${{ matrix.os }}
12+ strategy :
13+ matrix :
14+ # os: [ubuntu-latest, windows-latest, macos-latest]
15+ os : [ubuntu-latest, macos-latest]
16+
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v4
20+
21+ - name : Build static library (CppSQLite3.o/CppSQLite3.obj)
22+ run : |
23+ c++ -std=c++11 -c src/CppSQLite3.cpp -o CppSQLite3.o
24+
25+ - name : Build and run test program
26+ if : runner.os != 'Windows'
27+ run : |
28+ c++ -std=c++11 src/test.cpp src/CppSQLite3.cpp -lsqlite3 -o testprog
29+ ./testprog
30+ shell : bash
31+
32+ # Windows expects .exe and uses different shell
33+ - name : Build and run test program
34+ if : runner.os == 'Windows'
35+ run : |
36+ cl /EHsc /MD src/test.cpp src/CppSQLite3.cpp /I. /link sqlite3.lib
37+ testprog.exe
38+ shell : cmd
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1+ #include " CppSQLite3.h"
2+ #include < iostream>
3+ #include < cassert>
4+
5+ int main () {
6+ try {
7+ CppSQLite3DB db;
8+
9+ // In-memory database
10+ db.open (" :memory:" );
11+
12+ db.execDML (" CREATE TABLE test(id INTEGER PRIMARY KEY, name TEXT);" );
13+ assert (db.tableExists (" test" ));
14+
15+ db.execDML (" INSERT INTO test(name) VALUES ('Alice');" );
16+ db.execDML (" INSERT INTO test(name) VALUES ('Bob');" );
17+
18+ // Query it back using both Query and Table
19+ {
20+ auto q = db.execQuery (" SELECT * FROM test ORDER BY id;" );
21+ int cnt = 0 ;
22+ while (!q.eof ()) {
23+ int id = q.getIntField (" id" );
24+ const char * name = q.getStringField (" name" );
25+ std::cout << " Row " << id << " : " << name << std::endl;
26+ q.nextRow ();
27+ ++cnt;
28+ }
29+ assert (cnt == 2 );
30+ }
31+
32+ {
33+ auto t = db.getTable (" SELECT id, name FROM test;" );
34+ assert (t.numRows () == 2 );
35+ t.setRow (0 );
36+ assert (std::string (t.getStringField (1 )) == " Alice" );
37+ t.setRow (1 );
38+ assert (std::string (t.getStringField (1 )) == " Bob" );
39+ }
40+
41+ db.close ();
42+ std::cout << " CppSQLite basic tests passed!" << std::endl;
43+ return 0 ;
44+ } catch (const CppSQLite3Exception& e) {
45+ std::cerr << " CppSQLite3Exception: " << e.errorMessage () << std::endl;
46+ return 1 ;
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments