Connect SQLite without controls in Delphi7

Source: Internet
Author: User
Tags sqlite

DELPHI 7 There is no way to use Lib file, this is a bit of trouble, but we do not need a query, that is too painful. I was so miserable. We can use the third party packaging class, some are charged, but there are some free, specific information please check the address below Http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers

I am using the SQLite simple Delphi This is a completely free packaging class, you can go to its official website to download, http://www.itwriting.com/sqlitesimple.php

Down after is a compressed package inside is a demo. We need two files inside. Sqlite3.pas and Sqlitetable3.pas, copy them to the project directory, and then uses SQLITETABLE3 in the cell file that needs to be manipulated, then see the official case code:


Procedure Tform1.btntestclick (Sender:tobject);

Var

sldbpath:string;
Sldb:tsqlitedatabase;
Sltb:tsqlitetable;
Ssql:string;
Notes:string;
Begin
Sldbpath: = Extractfilepath (application.exename) + ' test.db ';
SLDB: = Tsqlitedatabase.create (Sldbpath);
Try
if sldb. Tableexists (' testtable ') then 
Begin
sSQL: = ' DROP TABLE testtable ';
Sldb.execsql (sSQL);
End;
sSQL: = ' CREATE TABLE testtable ([ID] integer PRIMARY key,[otherid] integer NULL, ';
sSQL: = sSQL + ' [Name] VARCHAR (255), [number] FLOAT, [notes] blob, [picture] blob COLLATE nocase);
Sldb.execsql (sSQL);
Sldb.execsql (' CREATE INDEX testtablename on [TestTable] ([Name]);

Begin a transaction

Sldb. BeginTransaction;

sSQL: = ' INSERT into testtable (name,otherid,number,notes) VALUES ("Some Name", 4,587.6594, "Here is Some Notes");

Do the Insert

Sldb. Execsql (sSQL);

sSQL: = ' INSERT into testtable (name,otherid,number,notes) VALUES ("Another Name", 12,4758.3265, "more Notes");

Do the Insert

Sldb. Execsql (sSQL);


End the transaction

Sldb.commit;


Query the data

SLTB: = sldb.gettable (' SELECT * from TestTable ');

Try


If SLTB. Count > 0 Then

Begin

Display First row


Ebname.text: = SLTB. Fieldasstring (SLTB. fieldindex[' Name ']);

Ebid.text: = IntToStr (SLTB. Fieldasinteger (SLTB. fieldindex[' ID '));

Ebnumber.text: = Floattostr (SLTB. Fieldasdouble (SLTB. fieldindex[' number '));

Notes: = SLTB. Fieldasblobtext (SLTB. fieldindex[' Notes ');

Memnotes.text: = notes;


End


Finally

SLTB. Free;

End


Finally

Sldb. Free;


End


End


It's not easy to do this, ^_^


<4> PHP Call SQLite3, this does not need me a lot of nonsense, please see my written "through Apache + PHP5 + PDO connection SQLite3 database" article.


<5>visual Basic, because I did not study carefully, I have no say, please refer to the official SQLite information


Http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers


COM wrappers/visual Basic DLLs Section


<6>java please refer to http://www.loveunix.net/bbs/index.php?showtopic=35051 post for more details.

The second part uses the transaction write library

The specific theoretical concept of business I do not want to say more, if you do not understand, please go to google search keyword "database transaction", can find more than n article information. We use VC + + to do the case. There are two functions used in the above

void Writesqlite ()

{

Try

{

Opensqlite ();

Execsql ("BEGIN Transaction;"); \ \ Start a transaction, record the operation

Char Strsql[max_path];

sprintf (strSQL, "INSERT into table_name (NAction1, NAction2, NAction3) VALUES (%d,%d,%d)", Szvar1,szvar2, SzVar3,);

Execsql (strSQL);

Execsql ("Commit transaction;"); \ \ The database automatically saves the user's sequence of operations to the database before executing the commit.

Return

}

catch (...)

{

Execsql ("ROLLBACK transaction;");

}

ADD Custom Code


}


This article is complete, the above code is in Windows2000 Pro + vc++6 English Enterprise version + Delphi7 English Enterprise Edition compiled through


Connect SQLite without controls in Delphi7

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.