Embedded Database sqlce and SQLite usage (sqlce)

Source: Internet
Author: User

 

Recently, due to project requirements, the query of large data volumes on wince4.2, wince5.0, and mobile models is estimated to be between 50-records.
In the past, because the database project of mobile5 was mainly written in C #, and the data volume was tens of thousands of records, in order to ensure that the project would not take a detour in the future, I specifically tested the performance of mobile databases. The following is the work record for this week. For your reference.
1. Since wince4.2 does not support. net when packaging the OS, you can only use C ++ for the convenience of porting to various platforms.
We initially consider using one of sqlce and SQLite. sqlce is MS, which is relatively stable. SQLite is open-source, easy to use, and fast to query. Therefore, I did a test on both of them.
1. sqlce development environment:
Evc4 + SP4. Vs2005. SQL 3.0
1) I first wrote a small program with vs2005 to generate 0.5 million pieces of simulation data. (Install a sqlce package to operate the SDF file in vs2005)
2). If you use sqlce on WinCE, copy the following files to the Windows directory (My wince does not have its own sqlce package ):
Sqlcese30.dll, sqlceqp30.dll, sqlceoledb30.dll, sqlceme30.dll, sqlceer30cn. dll, and register sqlceoledb30.dll to operate the database normally. (Or directly install the SQL cab package)
3). Compile the program under wince to operate the sqlce database.
: Coinitializeex (null, coinit_multithreaded );
// Register sqlce DLL
Lresult (callback * lpdllentrypoint) (); // declare it before the CPP File
// Register
Hinstance hlib = loadlibrary (L "// windows // sqlceoledb30.dll ");
If (hlib = NULL)
Return;
(Farproc &) lpdllentrypoint = getprocaddress (hlib, _ T ("dllregisterserver "));
(* Lpdllentrypoint )();

// The sqlce operations in oledb are related to some com
Hresult hr;
// Todo: add your control notification handler code here
Idbinitialize * pidbinitialize;
Idbcreatesession * pidbcreatesession;
Idbcreatecommand * pidbcreatecommand;
Icommandtext * picommandtext;
Idbproperties * pidbproperties;
Iunknown * piunknown;
Dbprop [1];
Dbpropset [1];

 

HR = cocreateinstance (clsid_sqlserverce_3_0, 0, clsctx_inproc_server,
Iid_idbinitialize, (void **) & pidbinitialize );

If (failed (HR ))
{
Return;
}

Dbprop [0]. dwpropertyid = dbprop_init_datasource;
Dbprop [0]. dwoptions = dbpropoptions_required;
Dbprop [0]. vvalue. Vt = vt_bstr;
Dbprop [0]. vvalue. bstrval = sysallocstring (L "// dB. SDF"); // need oleaut32.lib

If (dbprop [0]. vvalue. bstrval = NULL)
{
Return;
}

Dbpropset [0]. guidpropertyset = dbpropset_dbinit; // # define dbinitconstants
Dbpropset [0]. cproperties = sizeof (dbprop)/sizeof (dbprop [0]);
Dbpropset [0]. rgproperties = dbprop;

HR = pidbinitialize-> QueryInterface (iid_idbproperties, (void **) & pidbproperties );

If (failed (HR ))
{
Return;
}

HR = pidbproperties-> setproperties (sizeof (dbpropset)/sizeof (dbpropset [0]), dbpropset );

If (failed (HR ))
{
Return;
}

HR = pidbinitialize-> initialize ();

If (failed (HR ))
{
Return;
}

HR = pidbproperties-> QueryInterface (iid_idbcreatesession, (void **) & pidbcreatesession );

If (failed (HR ))
{
Return;
}
HR = pidbcreatesession-> createsession (null, iid_iunknown, & piunknown); // need UUID. Lib
If (failed (HR ))
{
Return;
}
HR = piunknown-> QueryInterface (iid_idbcreatecommand, (void **) & pidbcreatecommand );
If (failed (HR ))
{
Return;
}
HR = pidbcreatecommand-> createcommand (null, iid_icommandtext, (iunknown **) & picommandtext );
If (failed (HR ))
{
Return;
}
HR = picommandtext-> setcommandtext (dbguid_ SQL, l "select * From sninfo"); // execute the query
If (failed (HR ))
{
Return;
}
HR = picommandtext-> execute (null, iid_null, null, null );
If (failed (HR ))
{
Return;
}

I remember using ADO to operate sqlce on the Internet, but I heard that Ms is no longer updated, but oledb is a little more troublesome. This will also help us understand some interfaces of sqlce.
Sqlce writes so much and is not fully written. If you have any questions, please comment on them below.

Address: http://blog.csdn.net/xiangding/article/details/2982267

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.