diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..2271ba2 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,38 @@ +name: CppSQLite CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build-and-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + # os: [ubuntu-latest, windows-latest, macos-latest] + os: [ubuntu-latest, macos-latest] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build static library (CppSQLite3.o/CppSQLite3.obj) + run: | + c++ -std=c++11 -c src/CppSQLite3.cpp -o CppSQLite3.o + + - name: Build and run test program + if: runner.os != 'Windows' + run: | + c++ -std=c++11 src/test.cpp src/CppSQLite3.cpp -lsqlite3 -o testprog + ./testprog + shell: bash + + # Windows expects .exe and uses different shell + - name: Build and run test program + if: runner.os == 'Windows' + run: | + cl /EHsc /MD src/test.cpp src/CppSQLite3.cpp /I. /link sqlite3.lib + testprog.exe + shell: cmd diff --git a/CppSQLite3.cpp b/src/CppSQLite3.cpp similarity index 100% rename from CppSQLite3.cpp rename to src/CppSQLite3.cpp diff --git a/CppSQLite3.h b/src/CppSQLite3.h similarity index 100% rename from CppSQLite3.h rename to src/CppSQLite3.h diff --git a/src/test.cpp b/src/test.cpp new file mode 100644 index 0000000..b8df88d --- /dev/null +++ b/src/test.cpp @@ -0,0 +1,48 @@ +#include "CppSQLite3.h" +#include +#include + +int main() { + try { + CppSQLite3DB db; + + // In-memory database + db.open(":memory:"); + + db.execDML("CREATE TABLE test(id INTEGER PRIMARY KEY, name TEXT);"); + assert(db.tableExists("test")); + + db.execDML("INSERT INTO test(name) VALUES ('Alice');"); + db.execDML("INSERT INTO test(name) VALUES ('Bob');"); + + // Query it back using both Query and Table + { + auto q = db.execQuery("SELECT * FROM test ORDER BY id;"); + int cnt = 0; + while (!q.eof()) { + int id = q.getIntField("id"); + const char* name = q.getStringField("name"); + std::cout << "Row " << id << ": " << name << std::endl; + q.nextRow(); + ++cnt; + } + assert(cnt == 2); + } + + { + auto t = db.getTable("SELECT id, name FROM test;"); + assert(t.numRows() == 2); + t.setRow(0); + assert(std::string(t.getStringField(1)) == "Alice"); + t.setRow(1); + assert(std::string(t.getStringField(1)) == "Bob"); + } + + db.close(); + std::cout << "CppSQLite basic tests passed!" << std::endl; + return 0; + } catch(const CppSQLite3Exception& e) { + std::cerr << "CppSQLite3Exception: " << e.errorMessage() << std::endl; + return 1; + } +}