Compact 2013 Ebook

18.3 SQLite
Created by djones on 7/29/2013 4:53:57 PM

SQLite

There is no longer the SQL Compact component. This technology has been taken up by the desktop API with version 4 only being available for that context. SQL Compact had its beginnings in the Windows CE context as SQLCE and did not at that stage target the desktop. SQL Compact/SQLCE required an OS catalog component to be selected in the OS design. A database is a single file and the movement of its data from one context to another was trivial. It is though a fully featured relational database.

There is a move to make SQLite that database of choice for database application development with Compact 2013. This is an Open Source relational database technology available on a variety of platforms. Like SQL Compact, a database is a single file which can be moved seamlessly between different platforms if required. There is a native version of this technology for the CE/Compact operating systems with a managed code Visual Studio plugin that P/Invokes the native version. Unlike SQL Compact, it does not require an OS catalog component. When an application project encompasses SQLite, the app build links in all of the required components. Given the binary recompilation of native code requirement for Compact 2013 because of the C++ compiler upgrade, current binary downloads won’t work with Compact 2013. That situation should be addressed soon.

http://sqlite.com/

For managed code Compact 7 SQLite development there is an excellent article “SQLite and Windows Embedded Compact” by Pavel Bansky:

http://blogs.msdn.com/b/windows-embedded/archive/2013/02/14/sqlite-and-windows-embedded-compact.aspx

 

CESQLite2013: SQLite for Windows Embedded Compact 2013

http://cesqlite2013.codeplex.com/

A project to provide SQLite.dll for x86 Windows Embedded Compact 2013

Compact 2013 requires native code components to be rebuilt in its context. This project adds a ThirdParty component to Compact 2013 Platform Builder for the SQLite DLL. The first version is not the build project for that DLL. It packages the prebuilt DLL for use with a native code application. A simple test application is included in binary form.

This is the first (trial) version of SQLite for x86 Windows Embedded Compact 2013.

 

 

(A)  Setup

1.     1.Download the zip to C:\WINCE800

2.     2.Set it property to be Unblocked.

3.     3.Unzip it to that location.

4.     4.c:\WINCE800\3rdParty\SQLite will be created

 

(B)  Usage

1.     1.In OS project (must be x86) refresh the Catalog

2.     2.In the Catalog, navigate to ThirdParty/Embedded101

3.     3.Select the SQLite component

4.     4.Build the component in Retail mode

5.     5.Run the OS and run the simple test app SQLtest.exe

 

(C)  App development

1.     Include the header file SQLite3,h in your app.

2.     Link the app with SQLite.lib

3.     These files are in c:\WINCE800\3rdParty\SQLite\AppDev

 

A sample sqlite application follows. This requires as a starting point, a blank native code C++ OS subproject.  The following listings can be inserted into the project source code (.cpp) in the order shown.

 

The following listing shows the required cod to at the top of the source code file  In particular, there is a reference to the SQLite header file which is part of the SQLIte project under the 3rdParty folder. If it is located elsewhere then modify the path. There is a function prototype for the callback function that is used by SQLite calls.

 

// SQLTest.cpp : Defines the entry point for the application.

//

#include "stdafx.h"

#include        

#include “c:\WINCE800\3rdParty\SQLite\AppDev\sqlite3.h"  

//Callback function prototype
static int callback(void *NotUsed, int argc, char **argv, char **azColName);

Listing 18.x The SQLite App Callback function

The main function for the app is shown in the following listing. Note a C style ASCII main( ) interface is used. (See required the sources change below.)  The app opens the databse (it creates a new one if it doesn’t exist), creates a table into which it inserts some records, runs a query to get them back and then closes the database.

int main(int argc, char* argv)

{

  sqlite3 *db;

  char *zErrMsg = 0;

  int rc;

 

  rc = sqlite3_open("test.db", &db);

  if( rc ){

   fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));

   sqlite3_close(db);

   return 1;

  }

 

 rc = sqlite3_exec(db, "create table stuff ( name )", callback, 0, &zErrMsg);

 rc = sqlite3_exec(db, "insert into stuff values ('hello')", callback, 0, &zErrMsg);

 rc = sqlite3_exec(db, "insert into stuff values ('david')", callback, 0, &zErrMsg);

 rc = sqlite3_exec(db, "insert into stuff values ('jones')", callback, 0, &zErrMsg);

 rc = sqlite3_exec(db, "select * from stuff", callback, 0, &zErrMsg);

 

  if( rc!=SQLITE_OK ){

   fprintf(stderr, "SQL error: %s\n", zErrMsg);

   sqlite3_free(zErrMsg);

  }

  sqlite3_close(db);

  return 0;

}

Listing 18.x The SQLite App main function

 

The sqlite3( ) function requires a callback function to be called when the requested execution is completed. A generic callback function for that purpose is shown the following code listing that prints a record’s fields.

static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{

 for(int i=0; i<>      

    printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : NULL);

 }        

 printf("\n");        

 return 0;       

}

 

Listing 18.x The SQLite App Callback function

 

AS with any native app that references a DLL, the project sources file needs to be modified to link to sqlite.lib in the SQLite project. Also because a C style ASCII main function is used, an appropriate EXEENTRY item is required in the sources file. Those changes are shown in bold the following code listing.

 

PRECOMPILED_PCH=StdAfx.pch

PRECOMPILED_CXX=1

TARGETLIBS= \

    $(SG_OUTPUT_ROOT)\sdk\lib\$(_CPUINDPATH)\coredll.lib \

   c:\WINCE800\3rdParty\SQLite\AppDev\SQLite.lib \

 

EXEENTRY=mainACRTStartup

 

PRECOMPILED_OBJ=StdAfx.obj

TARGETTYPE=PROGRAM

Listing 18.x The SQLite App sources file modifications

Build and test run the application.

PS: We are currently working on porting the SQLIte Managed Code components to Compact 2013. Because there is no upgrade path for Compact 7 to Compact 2013 paths, you have to recreate each project from scratch, although you can reuse, where compatible, source code files etc.


NEXT:  Windows Azure

print

Click here to provide feedback and input

  Comments


Turkish porno izle video site in rokettubeporno izle