1 Open the database file
sqlite3* m_db = NULL;
int ret = SQLITE3_OPEN_V2 ("Test.db", &db, Sqlite_open_readwrite, NULL);
if (ret! = SQLITE_OK)
{
Return
}
2 If the table does not exist, create a table
Char szcreateuserdatasql[1024] = "CREATE table if not exists Tb_user (id INTEGER, \
Type integer,\
Kind INTEGER) ";
3 Creating a unique primary key ID
Char szcreateuserdatasql[1024] = "CREATE table if not exists Tb_user (ID INTEGER PRIMARY KEY autoincrement,\
Type integer,\
Kind INTEGER) ";
4 queries
Char szsql[1024] = {0};
sprintf (szSQL, "SELECT DISTINCT * from Tb_test");
sqlite3_stmt* stmt = NULL;
Sqlite3_prepare (m_db, szSQL, 1, &stmt, 0);
while (Sqlite3_step (stmt) = = Sqlite_row)
{
Const unsigned char* szpoiname = sqlite3_column_text (stmt, 0);
Char szname[128] = {0};
if (szpoiname)
{
sprintf (SzName, "%s", szpoiname);
}
int kx = Sqlite3_column_int (stmt, 3);
float x = sqlite3_column_double (stmt, 5);
}
Sqlite3_finalize (stmt);
5 get error message for SQL execution failure
char* errmsg = NULL;
char* szSQL = "SELECT * From address";
Nret = Sqlite3_exec (PDB, szsql, NULL, NULL, &ERRMSG);
if (nret! = SQLITE_OK)
{
cout<<errmsg<<endl;
Sqlite3_free (errmsg);
}
Note: Release the memory that ErrMsg points to
6 Closing the database
Sqlite3_close (DB);
SQLite Fifth Lesson Application case