Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created November 9, 2018 09:23
Show Gist options
  • Save fearofcode/3e608488248c1262371555a1a0f68bc8 to your computer and use it in GitHub Desktop.
Save fearofcode/3e608488248c1262371555a1a0f68bc8 to your computer and use it in GitHub Desktop.
simple SQLiteCPP example - https://github.com/qmick/SQLiteCPP
#include <iostream>
#include <chrono>
#include <SQLiteCpp/SQLiteCpp.h>
int main() {
auto start = std::chrono::high_resolution_clock::now();
SQLite::Database db("example.db3", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
db.exec("create table if not exists test(id integer primary key autoincrement, name text, size integer)");
SQLite::Statement insert_query(db, "insert into test(name, size) values(?, ?)");
insert_query.bind(1, "Warren");
insert_query.bind(2, 5);
insert_query.exec();
SQLite::Statement query(db, "SELECT id, name, size FROM test WHERE size > ?");
query.bind(1, 4);
while (query.executeStep())
{
int id = query.getColumn(0);
const char* value = query.getColumn(1);
int size = query.getColumn(2);
std::cout << "row: " << id << ", " << value << ", " << size << std::endl;
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::milliseconds elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
std::cout << elapsed_ms.count() << "ms\n";
std::cin.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment