You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
#include "sqlite3.hpp"
|
|
#include <iostream>
|
|
|
|
int main() {
|
|
try {
|
|
// Kreiraj instancu SQLite wrapper klase
|
|
marcelb::SQlite3::SQLite3 db("test.db"); // test.db je naziv baze podataka
|
|
|
|
// Izvrši SQL upit za kreiranje tabele
|
|
db.query("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT);");
|
|
|
|
// Ubaci podatke u tabelu
|
|
db.query("INSERT INTO test (name) VALUES ('John Doe');");
|
|
|
|
// Izvrši SELECT upit i pročitaj podatke
|
|
auto results = db.query("SELECT id, name FROM test;");
|
|
|
|
// Prikaži rezultate
|
|
for (const auto& row : results) {
|
|
std::string id = row.first;
|
|
std::string name = row.second[0];
|
|
std::cout << "ID: " << id << ", Name: " << name << std::endl;
|
|
}
|
|
} catch (const std::exception& e) {
|
|
std::cerr << "Error: " << e.what() << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
// cmake .. -DCMAKE_BUILD_TYPE=Release
|
|
// cmake --build . --target sqlitecpp_test
|
|
// ./test/sqlitecpp_test
|