Insert time into sqlite3 and search by time range. Voidmy_first_sqlite3_func () {inti; sqlite3 * db; sqlite3_stmt
Insert time into sqlite3 and search by time range. Void my_first_sqlite3_func () {int I; sqlite3 * db; sqlite3_stmt
Insert time into sqlite3 and search by time range.
Void my_first_sqlite3_func ()
{
Int I;
Sqlite3 * db;
Sqlite3_stmt * stmt;
Char name [16], occ [16];
Char * SQL _drop = "drop table if exists people ;";
Char * SQL _create = "create table people (id, time, blob );";
Char * SQL _insert = "insert into people values (?, ?, ?); ";
// Char * SQL _select = "select * from people ;";
Char * SQL _select = "select * from people where time between datetime ('2017-04-12 20:35:10. 30') and datetime ('2017-04-12 20:35:30. 30 ');";
Int len = strlen (SQL _select );
Sqlite3_open ("mydb. db", & db );
Sqlite3_exec (db, "PRAGMA synchronous = OFF;", 0, 0 );
Sqlite3_prepare (db, SQL _drop, strlen (SQL _drop), & stmt, NULL );
Sqlite3_step (stmt );
Sqlite3_prepare (db, SQL _create, strlen (SQL _create), & stmt, NULL );
Sqlite3_step (stmt );
Char * data = "bytes ";
Sqlite3_prepare (db, SQL _insert, strlen (SQL _insert), & stmt, NULL );
Printf ("begin write! \ N ");
Char myTime [30];
For (I = 10; I <50; I ++)
{
Sprintf (myTime, "2012-04-12 20: 35: % d.30", I );
Int len = strlen (data );
Sqlite3_bind_int (stmt, 1, I );
Sqlite3_bind_text (stmt, 2, myTime, strlen (myTime), NULL );
Sqlite3_bind_blob (stmt, 3, data, len, NULL );
Sqlite3_step (stmt );
Sqlite3_reset (stmt );
}
Printf ("finish write! \ N ");
Printf ("begin search! \ N ");
Sqlite3_prepare (db, SQL _select, strlen (SQL _select), & stmt, NULL );
I = 0;
While (SQLITE_DONE! = Sqlite3_step (stmt ))
{
Int id = sqlite3_column_int (stmt, 0 );
Char * time = (char *) sqlite3_column_text (stmt, 1 );
Int bytes = sqlite3_column_bytes (stmt, 2 );
Char * out_data = (char *) sqlite3_column_blob (stmt, 2 );
I ++;
Printf ("% d % s \ n", I, time );
}
Printf ("finish search! \ N ");
Sqlite3_finalize (stmt );
Sqlite3_close (db );
}
Int main ()
{
My_first_sqlite3_func ();
Getchar ();
Return 0;
}
,