Use SQLite database under WINCE

Source: Internet
Author: User

SQLite is an open-source, cross-platform lightweight database. WINCE also has its own database SQLCE, But it occupies a large amount of resources. SQLite has been used in recent projects, so we have made a special research. Here we will introduce the specific porting methods.

1. Download SQLite source code

Go to the SQLite website http://www.sqlite.org/download.htmto download the latest source code. I downloaded sqlite-amalgamation-3071401.zip. After decompression, you will get four files (shell. c, sqlite3.c, sqlite3.h, sqlite3ext. h ).

Ii. compile and generate the DLL under WINCE

1. Create a Win32 smart device project under VS2005, select the corresponding SDK, and set the application type to DLL.

2. Copy the sqlite3.c and sqlite3.h files decompressed by sqlite-amalgamation-3071401.zip to the project directory and add them to the project directory. As shown in.

3. Added SQLITE_ENABLE_RTREE and SQLITE_ENABLE_COLUMN_METADATA macro definitions in preprocessing. :

4. when compiling a project, the system prompts "error LNK2019: the external symbol localtime_s that cannot be parsed. This symbol is referenced in the osLocaltime function, the solution to this error is to replace localtime_s with _ localtime64_s.

Decompress the plugin file, copy the sqlite3.def file in the directory to the DLL project directory, and add sqlite3.def to the project properties -- linker -- input -- module definition file, as shown in, And then compile the file.

In this way, the compilation of SQLite is complete.

Iii. SQLite test under WINCE

Create an SQLite test program. The test code is as follows:

# Include <windows. h> // sqlite3 callback function int sqlitequeryresultcallback (void * para, int n_column, char ** column_value, char ** column_name) int main (INT argc, char * argv []) {sqlite3 * DB = NULL; // declare the SQLite key structure pointer int result; // open or create a database result = sqlite3_open ("nand2 \ SQLite. DB ", & dB); If (result! = Sqlite_ OK) {// return-1;} Char * errmsg = NULL; // database operation code # If 1 // create a test table named mytable, there are two fields: ID and name. ID is an automatically added type. This field can not be specified later during insert. It will add result = sqlite3_exec (dB, "create table mytable (ID integer primary key autoincrement, name nvarchar (32)", null, null, & errmsg); If (result! = Sqlite_ OK) {printf ("Table creation failed, error code: % d, error cause: % s \ n", result, errmsg );} // insert record result = sqlite3_exec (dB, "insert into mytable (name) values ('zhang san')", 0, 0, & errmsg); If (result! = Sqlite_ OK) {printf ("insertion record failed, error code: % d, error cause: % s \ n", result, errmsg );} // insert record result = sqlite3_exec (dB, "insert into mytable (name) values ('lily')", 0, 0, & errmsg); If (result! = Sqlite_ OK) {printf ("insertion record failed, error code: % d, error cause: % s \ n", result, errmsg );} # endif // start querying the database result = sqlite3_exec (dB, "select * From mytable", sqlitequeryresultcallback, null, & errmsg); // close the database sqlite3_close (db ); return 0;} // sqlite3 callback function int sqlitequeryresultcallback (void * para, int n_column, char ** column_value, char ** column_name) {printf ("****************************** \ n "); printf ("the record contains % d fields \ n", n_column); For (INT I = 0; I <n_column; I ++) {printf ("field name: % s field value: % s \ n ", column_name [I], column_value [I]);} printf ("******************************* \ n "); return 0 ;}

Iv. SQLite visual management tools

Sqlitehas no built-in management tools, and only uses the command line management tool sqlite.exe. There is a third-party visual management tool Sqlite Expert, can also be used,: http://www.sqliteexpert.com/download.html

Related Article

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.