Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions src/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "CppSQLite3.h"
#include <iostream>
#include <cassert>

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;
}
}