Click here to Skip to main content
12,252,407 members (58,321 online)
Click here to Skip to main content
Add your own
alternative version

Stats

168.2K views
6.1K downloads
69 bookmarked
Posted

SQLite3 MFC Wrapper

, 29 Dec 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
A SQLite3 MFC wrapper with Unicode/Pocket PC 2003 support.

Introduction

Here is another wrapper for the famous SQLite3 database engine. While there are several other wrappers available here at Code Project, I don't believe they support MFC/Unicode or have the results tested on a Pocket PC.

The wrapper source code is based on the SQLiteWrapper source produced by rene.nyffenegger@adp-gmbh.ch. I altered the original source while packaging it for use with Microsoft MFC. My primary objective in this exercise was to make the wrapper suitable for both MCBS and Unicode because Unicode is native to the Pocket PC. There are four key differences between this wrapper and the author's original source.

  • First, all the instances of std::string were converted to Microsoft's generic string pointers using LPCTSTR. This should be familiar to developer's accustomed to working with MFC. This also means that you should rely heavily on the Microsoft TEXT or _T macros for hard-coded character strings should you wish to maintain portability between the desktop and the Pocket PC.
  • Second, I have changed the class SQLiteStatement to CSqlStatement and SQLiteWrapper to CDbSQLite. This was primarily a matter of preference since most MFC developer's recognize Microsoft's conventions for the "Cx" nomenclature.
  • Third, I removed exception handling from the wrapper. Windows CE does not support the traditional try, catch and throw paradigm so you are basically on your own with respect to error handling.
  • Finally, I have added the header SQLite3i.h with typedefs to the various sqlite3.h functions. These type definitions are "internal" accessors to the sqlite3 functions conditionally utilizing either the UTF-8 or UTF-16 variation during compilation. For your entertainment, I incorporated a pragma in the header to inform you when you are compiling Unicode or MCBS.

Care and feeding

The test programs provided here are simple MFC dialog applications incorporating two buttons, an edit box and a list control. The "Create" button is used to populate the database with three entries. The "review" button is used to populate the list control with the database records. It is acceptable to click the "Create" button more than once. You may even wish to do so to observe any errors reported. The edit box is used simply for status info.

This code was tested on a Windows desktop and on a Pocket PC. As part of my test, I moved the database created by the Pocket PC to my desktop and then reviewed it using the desktop application.

Free with your purchase

The ZIP file contains the source code for the altered wrapper as well as code for both a desktop and Pocket PC application. The projects that I have provided include:

  1. Project to create the w32SQLite3.dll.
  2. Project to create the wceSQLite3.dll.
  3. Project to create the desktop test application.
  4. Project to create the Pocket PC test application.

As you might gather from this list, you must first build the DLL files for use with the test applications that I have provided. In order to do this, you should obtain the source from the SQLite Download Page for the W32 DLL and deposit it into the sqlite3 directory. You should obtain the source for the WCE DLL from the SQLite for Windows CE site and deposit it into the wince directory.

Once you have constructed the two DLL files, move them and their corresponding .lib files to the LIB directory. The application projects will search for these files in that location.

Warnings and disclaimers

  • All of these projects assume that you are experienced with MFC development and proficient in navigating Microsoft's IDE to configure the complier.
  • All of the projects provided here are dependent upon the directory structure stored in the zip file. If you deviate from this structure, please do not submit reports that " compilation fails because the compiler cannot locate the applicable header files".
  • The desktop solutions were created using Visual Studio 2003, so please don't submit questions informing me that you cannot load the project with a prior version of VC or a different compiler.
  • The CE projects were created using eMbedded Visual C++ v4.00, so please don't submit questions informing me that you cannot load the project using a different compiler.
  • The sample code is pure MFC so please don't submit comments about any notions you may have about portability or code bloat. The whole purpose here was to use SQLite on Windows CE using MFC.
  • This code was tested on a Win2K desktop and a Symbol PDT-8100 with Microsoft Pocket PC Version 4.20.0. Your results on anything less are anybody's guess.
  • These projects were compiled with the source code from SQLite3 Version 3.2.8 and SQLite for Windows CE Version 3.2.2. Problems compiling with future versions are most likely due to missing source files that should be included in the project.

Film credits

I selected Rene's SQLite Wrapper as the starting point for this exercise because of it's sheer simplicity. In other words, any complaints about missing functionality will fall upon deaf ears since you are most certainly welcome to port CppSQLite or Darkside SQL to Pocket PC and then post your results to Code Project for everyone's benefit.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

midnightEngineer
Software Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionNeed Help UNICODE Pin
Nazim Iqbal5-Oct-12 13:31
memberNazim Iqbal5-Oct-12 13:31 
GeneralMy vote of 5 Pin
ThatsAlok3-Jun-12 2:26
memberThatsAlok3-Jun-12 2:26 
QuestionBlobs Pin
BigAlBuchanan27-Jun-11 22:05
memberBigAlBuchanan27-Jun-11 22:05 
GeneralMemory leaks in "Download demo project w/source" that you provided [modified] Pin
wcqq1232-Dec-10 21:31
memberwcqq1232-Dec-10 21:31 
GeneralAnother bug Pin
thinksrc4-Nov-10 22:19
memberthinksrc4-Nov-10 22:19 
GeneralGood Pin
loyal ginger19-Nov-09 10:41
memberloyal ginger19-Nov-09 10:41 
GeneralDeployment errors: unable to start program Pin
susanaferenc10-Jun-09 20:33
membersusanaferenc10-Jun-09 20:33 
GeneralRe: Deployment errors: unable to start program Pin
midnightEngineer11-Jun-09 2:17
membermidnightEngineer11-Jun-09 2:17 
GeneralRe: Deployment errors: unable to start program Pin
midnightEngineer11-Jun-09 2:21
membermidnightEngineer11-Jun-09 2:21 
GeneralRe: Deployment errors: unable to start program Pin
susanaferenc11-Jun-09 7:04
membersusanaferenc11-Jun-09 7:04 
GeneralSQLite to connect to MS SQL Server Pin
Jesper Rahbek1-May-09 0:16
memberJesper Rahbek1-May-09 0:16 
GeneralRe: SQLite to connect to MS SQL Server Pin
midnightEngineer1-May-09 0:46
membermidnightEngineer1-May-09 0:46 
GeneralRe: SQLite to connect to MS SQL Server Pin
Jesper Rahbek3-May-09 22:41
memberJesper Rahbek3-May-09 22:41 
GeneralRe: SQLite to connect to MS SQL Server [modified] Pin
midnightEngineer4-May-09 0:47
membermidnightEngineer4-May-09 0:47 
GeneralSQLite v3.4.0 Pin
Floppe15-Jul-07 21:26
memberFloppe15-Jul-07 21:26 
GeneralRe: SQLite v3.4.0 Pin
midnightEngineer16-Jul-07 4:31
membermidnightEngineer16-Jul-07 4:31 
QuestionSQLITE3.DLL Pin
usf_azi9-Feb-07 8:01
memberusf_azi9-Feb-07 8:01 
AnswerRe: SQLITE3.DLL Pin
midnightEngineer13-Feb-07 8:13
membermidnightEngineer13-Feb-07 8:13 
Generaltext limit Pin
charoon28-Jan-07 10:21
membercharoon28-Jan-07 10:21 
GeneralRe: text limit [modified] Pin
midnightEngineer30-Jan-07 2:41
membermidnightEngineer30-Jan-07 2:41 
GeneralRe: text limit Pin
charoon30-Jan-07 19:06
membercharoon30-Jan-07 19:06 
GeneralRe: text limit Pin
charoon5-Feb-07 19:13
membercharoon5-Feb-07 19:13 
GeneralRe: text limit Pin
midnightEngineer13-Feb-07 9:34
membermidnightEngineer13-Feb-07 9:34 
GeneralRe: text limit Pin
midnightEngineer13-Feb-07 9:25
membermidnightEngineer13-Feb-07 9:25 
Generalwindows mobile 5.0 Pin
GVR197929-Nov-06 11:11
memberGVR197929-Nov-06 11:11 
GeneralRe: windows mobile 5.0 Pin
midnightEngineer4-Dec-06 6:54
membermidnightEngineer4-Dec-06 6:54 
GeneralOther unicode wrapper Pin
Softvoile27-Nov-06 22:17
memberSoftvoile27-Nov-06 22:17 
Generalcompile problems ..... Pin
asdklasjdlaskj8-Aug-06 12:34
memberasdklasjdlaskj8-Aug-06 12:34 
GeneralRe: compile problems ..... [modified] Pin
midnightEngineer8-Aug-06 15:00
membermidnightEngineer8-Aug-06 15:00 
GeneralRe: compile problems ..... Pin
DHarman9-Aug-06 3:02
memberDHarman9-Aug-06 3:02 
GeneralRe: compile problems ..... Pin
midnightEngineer9-Aug-06 4:39
membermidnightEngineer9-Aug-06 4:39 
GeneralRe: compile problems ..... Pin
DHarman9-Aug-06 9:46
memberDHarman9-Aug-06 9:46 
GeneralCP_ACP -> CP_UTF8 Pin
Softvoile18-Jul-06 7:52
memberSoftvoile18-Jul-06 7:52 
GeneralRe: CP_ACP -> CP_UTF8 [modified] Pin
midnightEngineer18-Jul-06 10:05
membermidnightEngineer18-Jul-06 10:05 
GeneralRe: CP_ACP -> CP_UTF8 Pin
Softvoile18-Jul-06 19:19
memberSoftvoile18-Jul-06 19:19 
GeneralCSqlStatement::Bind(int pos_zero_indexed, LPCTSTR value) is not correct ! Pin
ki11er4-May-06 21:45
memberki11er4-May-06 21:45 
GeneralLast insert ID Pin
gazmac27-Feb-06 12:40
membergazmac27-Feb-06 12:40 
GeneralRe: Last insert ID Pin
midnightEngineer28-Feb-06 6:26
membermidnightEngineer28-Feb-06 6:26 
GeneralRe: Last insert ID Pin
gazmac28-Feb-06 10:46
membergazmac28-Feb-06 10:46 
NewsWrong link Pin
Massimo Colurcio29-Dec-05 14:11
memberMassimo Colurcio29-Dec-05 14:11 
GeneralRe: Wrong link Pin
midnightEngineer29-Dec-05 17:05
membermidnightEngineer29-Dec-05 17:05 
GeneralCannot build wceSQLite3.dll Pin
gerhard4527-Dec-05 11:44
membergerhard4527-Dec-05 11:44 
GeneralRe: Cannot build wceSQLite3.dll Pin
midnightEngineer28-Dec-05 3:53
membermidnightEngineer28-Dec-05 3:53 
GeneralOther memory leaks Pin
Mathieu Desrochers3-Nov-05 5:34
memberMathieu Desrochers3-Nov-05 5:34 
GeneralRe: Other memory leaks Pin
midnightEngineer28-Dec-05 4:58
membermidnightEngineer28-Dec-05 4:58 
GeneralNewest sqLite3 Pin
Floppe31-Aug-05 22:26
memberFloppe31-Aug-05 22:26 
GeneralRe: Newest sqLite3 Pin
midnightEngineer28-Dec-05 3:55
membermidnightEngineer28-Dec-05 3:55 
QuestionUpdate column from another column of an existing table in SQLite?? Pin
dungoi26-Apr-05 2:58
memberdungoi26-Apr-05 2:58 
GeneralMemory leak Pin
jschisler18-Apr-05 9:27
memberjschisler18-Apr-05 9:27 
GeneralRe: Memory leak Pin
midnightEngineer28-Dec-05 4:36
membermidnightEngineer28-Dec-05 4:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 29 Dec 2005
Article Copyright 2005 by midnightEngineer
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid