Use sqlite3 in tcx

Source: Internet
Author: User
Tags dbx

I have long argued that SQLite is the best local file-type database.

In Windows, it can be driven by a DLL of several hundred K, and the management tool is just a few hundred K exe program. In contrast, access is huge and annoying, even a OLE-DB driver also has at least 10 m size, not to mention FoxPro, paradox ...... That's a bunch of table files. Of course, the performance of SQLite cannot be compared with that of the BT berkeleydb-bdb cannot be regarded as a complete database, and it is not supported by SQL.

However, because the BDE, ADO, DBX and other development methods provided by VCL do not provide support for SQLite-PostgreSQL can at least be connected through the OLD-DB driver using ADO. Therefore, using Delphi or BCB to access SQLite is still troublesome. I used SQLite in Python applications.

Fortunately, the open-source community soon provided support for this, that is, the excellent open-source database control package: zeosdbo. It is implemented based on the VCL standard database interface and can use this group of controls like BDE, ADO, and DBX. It supports the following database and development tools:

Supported databases: Sybase/ASA, Oracle, ms SQL, MySQL, Interbase/Firebird, PostgreSQL, and SQLite/3.
Supported VCL development tools: Delphi 5-10, BCB 5/6, kylix 2/3, And Lazarus.

However, due to copyright reasons, I only use codegear's free development tool: Turbo C ++ Explorer (tcx ). Due to the license restrictions in the free version, no third-party controls can be installed in tcx, so I cannot directly use zeosdbo. However, since I have already claimed to be a Delphi expert for many years, if I can't even do this, it would be too shameful. Dig Kaka.

After some experiments, the problem was finally solved. In fact, there is no technical content, and it is nothing more than a bit of trouble:

Start tcx, create a VCL application, and add all the PAS files in the following folders to the project:

Zeosdbo/src/Core
Zeosdbo/src/DBC
Zeosdbo/src/parsesql
Zeosdbo/src/plain

Add the necessary files in the zeosdbo/src/component folder to the project -- add the files of the control to the controls used, such as the commonly used zconnection. PAS and zdataset. you do not need to add other unnecessary files. In particular, the file name contains "Editor" attribute editing function units, because they use some of the control design, which are not available in the free version of tcx, adding these units will cause compilation failure.

After adding the file, do not reference it in the program for the time being. Instead, compile the file to generate necessary related files, such as. HPP. Under normal circumstances, except for several hint or warning, the compilation can be successful.

Then you can reference zeosdbo in the program to access SQLite.

Unit1.h has the following content (the auto_ptr in STL is used to manage the lifecycle of the zeosdbo control object ):

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ZConnection.hpp>
#include <ZDataset.hpp>

#include <memory>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:// IDE-managed Components
private:// User declarations
std::auto_ptr<TZConnection> zConn;
std::auto_ptr<TZTable> tblPerson;
public:// User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

In unit1.cpp, you can access SQLite using the following code:

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner),
zConn( new TZConnection(this) ),
tblPerson( new TZTable( this) )
{
zConn->Protocol = "sqlite-3";
zConn->HostName = "localhost";
zConn->Database = ChangeFileExt( Application->ExeName, ".sqlite3" );
zConn->User = "";
zConn->Password = "";
zConn->Connect();
tblPerson->Connection = zConn.get();
tblPerson->TableName = "person";
tblPerson->Open( );
//...
}

Finally, let's talk nonsense: SQLite is a free open-source cross-platform.

 

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.