SQLite3 insert time instance

Source: Internet
Author: User
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;
}

,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.