Sqlite3 for wince or mobile (EVC)

Source: Internet
Author: User

On wince and mobile, SQLite development is still encapsulated in. NET Compact framework.

In http://www.sqlite.org/cvstrac/wiki? P = sqlitewrappers can be used to find the SQLite encapsulation in various languages.

The following describes how to use SQLite in EVC.

1> development tools: evc4.0 + SP2

2> compile the required SQLite DLL.

A> download the DLL source code of SQLite for Windows CE in http://sqlite-wince.sourceforge.net.

B) Open EVC and create a "wce dynamic-Link Library" project named sqlite3.

C) In the following dialog box, select "an empty Windows ce dll Project", click Finish, and then click OK.

D) Copy all *. C *. H *. Def in the source code to the project folder.

E). Add all the SQLite source file files *. C except the files shell. C and tclsqlite. C to source files.

F). Add all *. h SQLite source file files to header files.

G). Add the sqlite3.def file in the SQLite source file to the source file of the project.

H). Select the platform you want to compile in EVC, for example, "Win32 (wce armv4i) release"

I). All right, start compiling, build (F7)

3> after compiling the DLL, you need to use C ++ to encapsulate the functions in the DLL. For the following resources, refer:

A> http://www.codeproject.com/KB/database/CppSQLite.aspx

B> http://www.adp-gmbh.ch/sqlite/wrapper.html

Although the above a and B resources have encapsulated the functions of SQLite DLL, but wince and mobile use Unicode encoding, while a and B do not support Unicode. so what we really need to use is the Unicode version in resource A, as shown below:

Http://softvoile.com/development/CppSQLite3U/


4> with SQLite DLL and cppsqlite3u, you can easily use SQLite: (in step 3, there is a demo on the link page)

The main code is as follows:

# Define file_db_name text ("Unitech. DB ")

// Obtain the current path of the program
Void getcurrentdirectory (cstring & szpath)
{
Wchar_t pbuf [256];
Getmodulefilename (null, pbuf, sizeof (pbuf)/sizeof (wchar_t ));
Szpath = pbuf;
Szpath = szpath. Left (szpath. reversefind ('\') + 1 );
}

Void cdemo2dlg: onbutton1 ()
{
Cstring strdbpath;
Getcurrentdirectory (strdbpath );
Strdbpath + = file_db_name;

Cppsqlitedb;
Try
{
// Open or create a database
DB. Open (strdbpath );

// Determine whether the table name exists
If (db. tableexists (L "tbltest "))
{
Afxmessagebox (L "table: tbltest is existed! ");
}
Else // does not exist
{
Afxmessagebox (L "table: tbltest not existed! ");
// Create a table
Db.exe cdml (L "create table tbltest (empno varchar (20), empname varchar (20 ))");
}

// Insert a record
Db.exe cdml (L "insert into tbltest values ('number', 'name ')");
// Insert a record
Db.exe cdml (L "insert into tbltest values ('jingrui ', 'answer ')");

// Delete a record
Db.exe cdml (L "delete from tbltest where empno = 'number '");

// Insert 10 records (using transactions)
Tchar Buf [256];
Db.exe cdml (L "begin transaction ;");
For (INT I = 0; I <10; I ++)
{
Memset (BUF, 0, sizeof (BUF ));
Wsprintf (BUF, l "insert into tbltest values ('no % d', 'name % D');", I, I );
Db.exe cdml (BUF );
}
Db.exe cdml (L "Commit transaction ;");

// Update a record
Db.exe cdml (L "Update tbltest set empname = 'answer' where empno = 'no1 '");

// Obtain the total number of records
Int COUNT = db.exe cscalar (L "select count (*) from tbltest ;");
Tchar szcount [50];
Memset (szcount, 0, sizeof (szcount ));
Wsprintf (szcount, l "count: % d", count );
Afxmessagebox (szcount );

// Obtain each
Cppsqlite3query q = db.exe cquery (L "select * From tbltest ");
While (! Q. EOF ())
{
Afxmessagebox (Q. fieldvalue (0 ));
Q. nextrow ();
}
Q. Finalize ();

DB. Close ();
Afxmessagebox (L "OK ");
}
Catch (cppsqlite3exception ex)
{
Afxmessagebox (ex. errormessage ());
}
}

5> completed successfully. Enjoy it ~~~

6> download:

A> sqlite3 for wince Source

B> cppsqlite3u for wince Source

C> demo Source

D> demo exe

7> we recommend a SQLite visualization tool:

Sqlitespy: http://www.yunqa.de/delphi/doku.php/products/sqlitespy/index

Download

 

 

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.