mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
30 lines
992 B
C++
30 lines
992 B
C++
#include <iostream>
|
|
#include "../SQLiteC++/SQLiteC++.h"
|
|
|
|
int main (void)
|
|
{
|
|
try
|
|
{
|
|
// Open a database file
|
|
SQLite::Database db("example.db3");
|
|
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
|
|
|
|
// Compile a SQL query, containing one parameter (index 1)
|
|
SQLite::Statement query(db, "SELECT * FROM test WHERE size>?");
|
|
std::cout << "SQLite statement '" << query.getQuery().c_str() << "' compiled (" << query.getColumnCount () << " collumns in the result)\n";
|
|
// Bind an integer value "6" to the first parameter of the SQL query
|
|
query.bind(1, 6);
|
|
|
|
while (query.executeStep())
|
|
{
|
|
std::cout << "row : (" << query.getColumnInt(0) << ", " << query.getColumnText(1) << ", " << query.getColumnInt(2) << ")\n";
|
|
}
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
std::cout << "SQLite exception: " << e.what() << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|