Development and use of SQLite wince project by Lazarus

Source: Internet
Author: User
SQLite is an open-source small database that can work normally on WinCE. This article describes how to use it in wince development.
First, we need related development tools. SQLite does not have a visual management tool. It provides a command line tool for creating databases. After you download sqlite3, you will find sqlite3.exe and sqlite3.dll. EXE is the command line tool.

Run the following command to create a database for testing:
Sqlite3 mytest. DB
Create Table demo (UID integer, uname varchar (50 ));
Insert into demo values (1, 'A ');
Insert into demo values (2, 'B ');
Insert into demo values (3, 'C ');
. Quit

Now we can see that the mytest. DB file is generated under the same directory of sqlite3.exe. Of course, it contains a table named demo. to query the table content, use the following statement.
Sqlite3 mytest. DB
Select * from demo;
. Quit

The preceding command is executed on the PC. It uses sqlite3.dll to complete the corresponding functions. However, Windows Mobile obviously cannot use the DLL on the PC, we need to use the source code to compile the relevant DLL.

Download To SQLite-Ce-source from SourceForge
3.3.3. decompress the package and create a library project in vc6. add all the files except tclsqlite. c In the source file to the project.
. After compilation, sqlite3.dll is generated. This dll can be used in Windows Mobile.

I use vc6 to compile sqlite3.dll. You can also use C ++ builder, Dev C ++, or VC ++ in Visual Studio 2008. net to compile this DLL, the compilation effect is the same.

After the database is created, we need to develop the program. Here I select Lazarus for development. Of course, if you like to use C ++, Java or C # for development, the same is true. net or Java language development, you need to download a corresponding wrapper, with native language development, do not need to download more.

To make the program smaller, we need to use kolce. For the usage of kolce, please go to the following post: Click to enter

Assuming that you have used Lazarus and kolce, you can start the development below. We will encounter a small problem, that is, the DB connection provided by Lazarus does not support SQLite. At this time, we need to use a set of third-party controls, that is, zeos DBO.
Zeosdbo is a powerful data operation control developed by Delphi. It also has Lazarus-related versions. You can obtain it from SourceForge, which is free and open-source.

Based on zeos
As described in DBO documentation, to install zcomponents. LPK on Lazarus, you only need to compile and install zcomponents. LPK. The remaining four packages, zeos
DBO has been installed for quite a long time. It takes nearly five minutes to complete the 4-Core + 4 GB memory configuration on my computer. During the installation, Lazarus will not respond, the system response is similar.
Slow, please do not care, and wait patiently.

Another problem may occur when installing zeos DBO. If you have installed kolce before, a kol. O and Kol. PPU will be reported.
Duplicate errors. Delete the lib directory under the mck directory and re-compile kolce.

After the zeos DBO is successfully installed, an additional group of controls will be displayed on the control panel ,:

Now we can perform real development. Create a project and set the window size to 240x320. The resolution is the size of my mobile phone screen, you can set a large value based on the actual resolution of your mobile phone.
Small. Drag a tkollistbox, tzconnection, and tzquery to the form. Set the connection attribute of zquery
Zconnection.

Write some simple code to query and display data.

As you can see, these codes are very similar to operations in Delphi. Pay attention to the following points:
1. In kollistbox, the items attribute is a string, so it cannot be items. Clear or items. Add (). Only ListBox. Clear and ListBox. Add can be used.
2. SQLite databases must use the complete path, rather than the relative path.
3. the SQL statements of SQLite must end with a semicolon to show that the statement ends.

Now you can compile the program. After the compilation is successful, we need to run the program to test whether the program works normally. In this case, another problem occurs: Windows
The mobile simulator cannot deploy the database or related DLL. There are two solutions at this time, one is to use Microsoft
ActiveSync, copy the related files directly into the simulator, and the other is to have a real Windows Mobile. The last method is used.

What is needed for deployment is very simple. The developed programs, sqlite3.dll and mytest. DB, are all copied to the mobile phone. Then execute the EXE file.

So far, a simple demo program has been completed. For developers using Delphi, it is very easy to get started with Lazarus, in addition, zeos DBO operates almost the same way as dbgo, which allows Delphi developers to seamlessly transition to Lazarus.
For SQLite, it is small and easy to operate, and the data access speed is very fast. More and more PPC applications use it as a local database. In addition, the open source of SQLite allows developers to better understand its nature and improve it to meet the different needs of different users.

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.