sqlite3_prepare, sqlite3_step sqlite_finalize, , sqlite3_exec ( ): https://www.sqlite.org/c3ref/exec.html?
sqlite_exec :
sqlite3* pDB;
if (sqlite3_open("Database", &pDB) != SQLITE_OK)
{
}
char* error = nullptr;
if (sqlite3_exec(pDB, "SELECT * FROM SomeTable WHERE Something='Hi'", _func, &object, &error) != SQLITE_OK)
{
cout << error << endl;
sqlite3_free(error);
}
sqlite3_exec _func object , .
,
create_table (id int, , , )
:
int getCustomers(void* pObject, int columns, char** columnValues, char** columnNames)
{
if (columns != columns_in_desired_table)
{
return 1;
}
if (std::vector<std::string>* name = reinterpret_cast<std::vector<std::string>*>(pObject))
name->push_back(columnValues[1]);
return 0;
}
int main()
{
sqlite3* db;
sqlite3_open(&db, "customers.db");
std::vector<std::string> customers;
char* error = nullptr;
sqlite3_exec(db, "select * from Customers where postcode='1234'", &getCustomers, static_cast<void*>(&customers), error);
}
getCustomers - ,
int (*callback)(void*,int,char**,char**)
getCustomers . , SQL:
select * from Customers where postcode='1234'
customers . , , vector . , error , sqlite3_free ( nullptr, sqlite3 ).