emsApplication/applications/examples/sqlite_demo/sqlitewrapper_test.cpp

30 lines
1.0 KiB
C++
Raw Normal View History

2024-05-24 12:19:45 +08:00
#include <string>
#include <iostream>
#include <iomanip>
#include <sqlitewrapper.hpp>
int main(int argc, char* argv[])
{
try {
//Creates a SQLite connection object
Sqlite::SqliteConnection connection("myProfile.db");
// sqliteExecute(connectionOb, "query"); executes a SQLite query, in this case creates a table
sqliteExecute(connection, "create table myResume (skills text, proficiency int DEFAULT 5)");
sqliteExecute(connection, "insert into myResume(skills, proficiency ) values (?, ?)", "C++", 7);
sqliteExecute(connection, "insert into myResume(skills, proficiency ) values (?, ?)", "C", 6);
sqliteExecute(connection, "insert into myResume(skills) values (?)", "libCurl");
for (auto row : Sqlite::SqliteStatement(connection, "select skills, proficiency from myResume")) {
std::cout << std::left << std::setw(8) << row.getString() << " : " << row.getInt(1) << std::endl;
}
}
catch (const Sqlite::exception &e) {
std::cout << e.errorMessage_ << '(' << e.errorCode_ << ')';
}
return 0;
}