From 7e2e8a8f5a195ac0c49dcb941d065dd9bf0e0256 Mon Sep 17 00:00:00 2001 From: jaybinks Date: Tue, 18 Sep 2007 10:54:41 +0000 Subject: SQLite unit's modified and tested to be lazarus compatible. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@389 b956fd51-792f-4845-bead-9b4dfca2ff2c --- Game/Code/lib/SQLite/SQLiteTable3.pas | 4 + Game/Code/lib/SQLite/lazarustest.lpi | 142 ++++++++++++++++++++++++++++++++++ Game/Code/lib/SQLite/lazarustest.lpr | 79 +++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 Game/Code/lib/SQLite/lazarustest.lpi create mode 100644 Game/Code/lib/SQLite/lazarustest.lpr (limited to 'Game/Code') diff --git a/Game/Code/lib/SQLite/SQLiteTable3.pas b/Game/Code/lib/SQLite/SQLiteTable3.pas index 19346915..e09cc7a0 100644 --- a/Game/Code/lib/SQLite/SQLiteTable3.pas +++ b/Game/Code/lib/SQLite/SQLiteTable3.pas @@ -17,6 +17,10 @@ unit SQLiteTable3; interface +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + uses Windows, SQLite3, Classes, SysUtils; diff --git a/Game/Code/lib/SQLite/lazarustest.lpi b/Game/Code/lib/SQLite/lazarustest.lpi new file mode 100644 index 00000000..0da6fab4 --- /dev/null +++ b/Game/Code/lib/SQLite/lazarustest.lpi @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Game/Code/lib/SQLite/lazarustest.lpr b/Game/Code/lib/SQLite/lazarustest.lpr new file mode 100644 index 00000000..61b7c748 --- /dev/null +++ b/Game/Code/lib/SQLite/lazarustest.lpr @@ -0,0 +1,79 @@ +program lazarustest; + +uses + SQLiteTable3 in 'SQLiteTable3.pas', + SQLite3 in 'SQLite3.pas', + sysutils; + + +procedure DoTest(); +var + slDBpath : string; + sldb : TSQLiteDatabase; + sltb : TSQLIteTable; + sSQL : String; + Notes : String; + +begin + slDBPath := ExtractFilepath( paramstr(0) ) + '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 are 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 + writeln( sltb.FieldAsString(sltb.FieldIndex['Name']) ); + writeln( inttostr(sltb.FieldAsInteger(sltb.FieldIndex['ID'])) ); + writeln( floattostr( sltb.FieldAsDouble(sltb.FieldIndex['Number'])) ); + end; + + finally + sltb.Free; + end; + + finally + sldb.Free; + end; + +end; + +begin + try + DoTest(); + writeln( 'SqlLite3 unit IS lazarus compatible' ); + except + writeln( 'ERROR : SqlLite3 unit is NOT lazarus compatible' ); + end; +end. + -- cgit v1.2.3