mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 23:29:32 +02:00
* Fix compilation and improve sqlite examples, patch from Luiz Americo
git-svn-id: trunk@6791 -
This commit is contained in:
parent
2dc4a8d1b6
commit
9054139d26
@ -1,60 +1,90 @@
|
|||||||
program browseds;
|
program browseds;
|
||||||
|
|
||||||
{$Mode ObjFpc}
|
{$Mode ObjFpc}
|
||||||
|
{$H+}
|
||||||
{$define DEBUGHEAP}
|
{$define DEBUGHEAP}
|
||||||
uses
|
|
||||||
|
//To test the sqlite3 version replace sqliteds by sqlite3ds
|
||||||
|
// and TSqliteDataset by TSqlite3Dataset
|
||||||
|
|
||||||
|
uses
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
Heaptrc,
|
Heaptrc,
|
||||||
{$endif}
|
{$endif}
|
||||||
{$ifdef Linux}
|
{$ifdef Linux}
|
||||||
cmem,
|
cmem,
|
||||||
{$endif}
|
{$endif}
|
||||||
crt,sysutils,sqliteds,db;
|
crt,
|
||||||
|
sqliteds,
|
||||||
|
sysutils,db,inifiles;
|
||||||
|
|
||||||
var
|
const
|
||||||
dsTest:TSQliteDataset;
|
SQLITEDS_TESTS_INI_FILE = 'sqlitedstests.ini';
|
||||||
I:Integer;
|
DEFAULT_TABLENAME = 'tabletest';
|
||||||
|
DEFAULT_FILENAME = 'test.db';
|
||||||
|
|
||||||
|
|
||||||
|
var
|
||||||
|
dsTest:TSqliteDataset;
|
||||||
|
ini: TIniFile;
|
||||||
|
i:Integer;
|
||||||
|
|
||||||
procedure DumpFieldData (F : TField);
|
procedure DumpFieldData (F : TField);
|
||||||
begin
|
begin
|
||||||
With F Do
|
with F do
|
||||||
begin
|
begin
|
||||||
Writeln ('Field : ',FieldName);
|
Write (FieldName:10,FieldTypeNames[DataType]:12);
|
||||||
Writeln ('Data type : ',FieldTypeNames[DataType]);
|
if DataType <> ftMemo then
|
||||||
Writeln ('As String : ',AsString);
|
Write(AsString:30)
|
||||||
Case Datatype of
|
else
|
||||||
ftSmallint, ftInteger, ftWord : Writeln ('As Longint : ',AsLongint);
|
Write('(memo)':30);
|
||||||
ftBoolean : Writeln ('As Boolean : ',AsBoolean);
|
case Datatype of
|
||||||
ftFloat : Writeln ('As Float : ',AsFloat);
|
ftSmallint, ftInteger, ftWord, ftAutoInc : Writeln (AsLongint:28);
|
||||||
ftDate, ftTime, ftDateTime : Writeln ('As DateTime : ',AsDateTime);
|
ftBoolean : Writeln (AsBoolean:28);
|
||||||
|
ftFloat : Writeln (AsFloat:28);
|
||||||
|
ftDate, ftTime, ftDateTime : Writeln (AsDateTime:28);
|
||||||
|
ftLargeInt: WriteLn(AsLargeInt:28);
|
||||||
|
ftMemo: WriteLn('(memo)':28);
|
||||||
|
ftString: WriteLn(AsString:28);
|
||||||
|
ftCurrency: WriteLn(AsCurrency:28);
|
||||||
|
else
|
||||||
|
WriteLn;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
writeln('------------------');
|
|
||||||
//Readkey;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
SetHeapTraceOutput('heaplog.txt');
|
SetHeapTraceOutput(ExtractFileName(ParamStr(0))+'.heap.log');
|
||||||
{$endif}
|
{$endif}
|
||||||
dsTest:=TsqliteDataset.Create(nil);
|
dsTest:=TSqliteDataset.Create(nil);
|
||||||
with dsTest do
|
with dsTest do
|
||||||
Begin
|
begin
|
||||||
FileName:='New.db';
|
//Load Database properties from a inifile
|
||||||
TableName:='NewTable';
|
ini:=TIniFile.Create(SQLITEDS_TESTS_INI_FILE);
|
||||||
Sql:= 'SELECT _ROWID_,* FROM NewTable';
|
FileName:=ini.ReadString('testinfo','filename',DEFAULT_FILENAME);
|
||||||
|
TableName:=ini.ReadString('testinfo','tablename',DEFAULT_TABLENAME);
|
||||||
|
ini.Destroy;
|
||||||
|
//Calling Open with an empty SQL, is the same of setting SQL to 'SELECT * from [TableName]';
|
||||||
Open;
|
Open;
|
||||||
WriteLn('RecordCount: ',RecordCount);
|
//Browse all records
|
||||||
First;
|
|
||||||
while not Eof do
|
while not Eof do
|
||||||
begin
|
begin
|
||||||
writeln(':::: Press a key to see data from record ',RecNo,' ::::');
|
ClrScr;
|
||||||
Readkey;
|
Writeln('Record ',RecNo,'/',RecordCount);
|
||||||
For I:=0 to FieldCount-1 do
|
Writeln('--------------------------------------------------------------------------------');
|
||||||
|
Writeln ('Field Name':10,'Data Type':12,'As String':30, 'As Native Type':28);
|
||||||
|
Writeln('--------------------------------------------------------------------------------');
|
||||||
|
for i:=0 to FieldCount - 1 do
|
||||||
DumpFieldData(Fields[I]);
|
DumpFieldData(Fields[I]);
|
||||||
Next;
|
Next;
|
||||||
|
WriteLn;
|
||||||
|
if not Eof then
|
||||||
|
WriteLn(':::: Press a key to see the next record ::::')
|
||||||
|
else
|
||||||
|
WriteLn(':::: Press a key to finish the program ::::');
|
||||||
|
Readkey;
|
||||||
end;
|
end;
|
||||||
Close;
|
|
||||||
Destroy;
|
Destroy;
|
||||||
end;
|
end;
|
||||||
Exit;
|
|
||||||
end.
|
end.
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
program concurrencyds;
|
program concurrencyds;
|
||||||
|
|
||||||
{$Mode ObjFpc}
|
{$Mode ObjFpc}
|
||||||
|
{$H+}
|
||||||
{$define DEBUGHEAP}
|
{$define DEBUGHEAP}
|
||||||
|
|
||||||
|
//To test the sqlite3 version replace sqliteds by sqlite3ds
|
||||||
|
// and TSqliteDataset by TSqlite3Dataset
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
Heaptrc,
|
Heaptrc,
|
||||||
@ -8,38 +14,52 @@ uses
|
|||||||
{$ifdef Linux}
|
{$ifdef Linux}
|
||||||
cmem,
|
cmem,
|
||||||
{$endif}
|
{$endif}
|
||||||
crt,sysutils,SqliteDS;
|
sysutils,sqliteds, inifiles;
|
||||||
|
|
||||||
|
const
|
||||||
|
SQLITEDS_TESTS_INI_FILE = 'sqlitedstests.ini';
|
||||||
|
DEFAULT_TABLENAME = 'tabletest';
|
||||||
|
DEFAULT_FILENAME = 'test.db';
|
||||||
|
|
||||||
|
FieldNames: array [0..10] of String =
|
||||||
|
(
|
||||||
|
'Integer',
|
||||||
|
'String',
|
||||||
|
'Boolean',
|
||||||
|
'Float',
|
||||||
|
'Word',
|
||||||
|
'Date',
|
||||||
|
'DateTime',
|
||||||
|
'Time',
|
||||||
|
'LargeInt',
|
||||||
|
'AutoInc',
|
||||||
|
'Currency'
|
||||||
|
);
|
||||||
|
|
||||||
var
|
var
|
||||||
dsOne,dsTwo:TSQliteDataset;
|
dsArray: array [0..10] of TSqliteDataset;
|
||||||
|
ini:TIniFile;
|
||||||
|
i: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
SetHeapTraceOutput('heaplog.txt');
|
SetHeapTraceOutput(ExtractFileName(ParamStr(0))+'.heap.log');
|
||||||
{$endif}
|
{$endif}
|
||||||
dsOne:=TsqliteDataset.Create(nil);
|
ini:=TIniFile.Create(SQLITEDS_TESTS_INI_FILE);
|
||||||
dsTwo:=TsqliteDataset.Create(nil);
|
for i:= 0 to 10 do
|
||||||
dsOne.FileName:='New.db';
|
begin
|
||||||
dsTwo.FileName:='New.db';
|
dsArray[i] := TSqliteDataset.Create(nil);
|
||||||
dsOne.TableName:='NewTable';
|
with dsArray[i] do
|
||||||
dsTwo.TableName:='NewTable';
|
begin
|
||||||
dsOne.Sql:= 'SELECT Code FROM NewTable';
|
FileName:=ini.ReadString('testinfo','filename',DEFAULT_FILENAME);
|
||||||
dsTwo.Sql:= 'SELECT Name FROM NewTable';
|
TableName:=ini.ReadString('testinfo','tablename',DEFAULT_TABLENAME);
|
||||||
dsOne.Open;
|
//Each dataset will retrieve only one field of the same table
|
||||||
dsTwo.Open;
|
Sql:='Select '+FieldNames[i]+ ' from '+ TableName;
|
||||||
writeln('Sqlite Return after opening dsTwo: ',dsTwo.SqliteReturnString);
|
Open;
|
||||||
dsOne.First;
|
WriteLn('Value of Field ',FieldNames[i],' : ',FieldByName(FieldNames[i]).AsString);
|
||||||
dsTwo.First;
|
end;
|
||||||
WriteLn('Code: ',dsOne.FieldByName('Code').AsInteger);
|
end;
|
||||||
WriteLn('Name: ',dsTwo.FieldByName('Name').AsString);
|
ini.Destroy;
|
||||||
dsOne.Next;
|
for i:= 0 to 10 do
|
||||||
dsTwo.Next;
|
dsArray[i].Destroy;
|
||||||
WriteLn('Code: ',dsOne.FieldByName('Code').AsInteger);
|
|
||||||
WriteLn('Name: ',dsTwo.FieldByName('Name').AsString);
|
|
||||||
dsOne.Close;
|
|
||||||
dsTwo.Close;
|
|
||||||
dsOne.Destroy;
|
|
||||||
dsTwo.Destroy;
|
|
||||||
Readkey;
|
|
||||||
exit;
|
|
||||||
end.
|
end.
|
||||||
|
@ -1,44 +1,65 @@
|
|||||||
program createds;
|
program createds;
|
||||||
|
|
||||||
{$Mode ObjFpc}
|
{$Mode ObjFpc}
|
||||||
|
{$H+}
|
||||||
{$define DEBUGHEAP}
|
{$define DEBUGHEAP}
|
||||||
uses
|
|
||||||
|
//To test the sqlite3 version replace sqliteds by sqlite3ds
|
||||||
|
// and TSqliteDataset by TSqlite3Dataset
|
||||||
|
|
||||||
|
uses
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
Heaptrc,
|
Heaptrc,
|
||||||
{$endif}
|
{$endif}
|
||||||
{$ifdef Linux}
|
{$ifdef Linux}
|
||||||
cmem,
|
cmem,
|
||||||
{$endif}
|
{$endif}
|
||||||
crt,sysutils,db,SqliteDS;
|
sqliteds,
|
||||||
|
sysutils,db,inifiles;
|
||||||
|
|
||||||
var
|
const
|
||||||
dsTest:TSQliteDataset;
|
SQLITEDS_TESTS_INI_FILE = 'sqlitedstests.ini';
|
||||||
|
DEFAULT_TABLENAME = 'tabletest';
|
||||||
|
DEFAULT_FILENAME = 'test.db';
|
||||||
|
|
||||||
|
var
|
||||||
|
dsTest:TSqliteDataset;
|
||||||
|
ini: TIniFile;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
SetHeapTraceOutput('heaplog.txt');
|
SetHeapTraceOutput(ExtractFileName(ParamStr(0))+'.heap.log');
|
||||||
{$endif}
|
{$endif}
|
||||||
dsTest:=TsqliteDataset.Create(nil);
|
dsTest:=TSqliteDataset.Create(nil);
|
||||||
with dsTest do
|
with dsTest do
|
||||||
Begin
|
begin
|
||||||
FileName:='New.db';
|
//Load Database properties from a inifile
|
||||||
|
ini:=TIniFile.Create(SQLITEDS_TESTS_INI_FILE);
|
||||||
|
FileName:=ini.ReadString('testinfo','filename',DEFAULT_FILENAME);
|
||||||
|
TableName:=ini.ReadString('testinfo','tablename',DEFAULT_TABLENAME);
|
||||||
|
ini.Destroy;
|
||||||
|
//Ensure the file does not exist yet
|
||||||
if FileExists(FileName) then
|
if FileExists(FileName) then
|
||||||
DeleteFile(FileName);
|
DeleteFile(FileName);
|
||||||
TableName:='NewTable';
|
//Create a table with all available field types
|
||||||
with FieldDefs do
|
with FieldDefs do
|
||||||
begin
|
begin
|
||||||
Clear;
|
Clear;
|
||||||
Add('Code',ftInteger,0,False);
|
Add('Integer',ftInteger);
|
||||||
Add('Name',ftString,0,False);
|
Add('String',ftString);
|
||||||
Add('Bool',ftBoolean,0,False);
|
Add('Boolean',ftBoolean);
|
||||||
Add('Float',ftFloat,0,False);
|
Add('Float',ftFloat);
|
||||||
Add('Word',ftWord,0,False);
|
Add('Word',ftWord);
|
||||||
Add('DateTime',ftDateTime,0,False);
|
Add('DateTime',ftDateTime);
|
||||||
Add('Date',ftDate,0,False);
|
Add('Date',ftDate);
|
||||||
Add('Time',ftTime,0,False);
|
Add('Time',ftTime);
|
||||||
end;
|
Add('AutoInc',ftAutoInc);
|
||||||
|
Add('Memo',ftMemo);
|
||||||
|
Add('LargeInt',ftLargeint);
|
||||||
|
Add('Currency',ftCurrency);
|
||||||
|
end;
|
||||||
CreateTable;
|
CreateTable;
|
||||||
writeln('SqliteReturnString after CreateTable: ',SqliteReturnString);
|
writeln('ReturnString after CreateTable: ',ReturnString);
|
||||||
Destroy;
|
Destroy;
|
||||||
end;
|
end;
|
||||||
exit;
|
|
||||||
end.
|
end.
|
||||||
|
@ -1,69 +1,98 @@
|
|||||||
program fillds;
|
program fillds;
|
||||||
|
|
||||||
{$Mode ObjFpc}
|
{$Mode ObjFpc}
|
||||||
|
{$H+}
|
||||||
{$define DEBUGHEAP}
|
{$define DEBUGHEAP}
|
||||||
uses
|
|
||||||
|
//To test the sqlite3 version replace sqliteds by sqlite3ds
|
||||||
|
// and TSqliteDataset by TSqlite3Dataset
|
||||||
|
|
||||||
|
uses
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
Heaptrc,
|
Heaptrc,
|
||||||
{$endif}
|
{$endif}
|
||||||
{$ifdef Linux}
|
{$ifdef Linux}
|
||||||
cmem,
|
cmem,
|
||||||
{$endif}
|
{$endif}
|
||||||
crt,sysutils,SqliteDS;
|
sqliteds,
|
||||||
|
sysutils,db,IniFiles;
|
||||||
|
|
||||||
var
|
const
|
||||||
dsTest:TSQliteDataset;
|
SQLITEDS_TESTS_INI_FILE = 'sqlitedstests.ini';
|
||||||
|
DEFAULT_TABLENAME = 'tabletest';
|
||||||
|
DEFAULT_FILENAME = 'test.db';
|
||||||
|
MEMOTEST_FILENAME = 'createds.pas';
|
||||||
|
|
||||||
begin
|
var
|
||||||
|
dsTest:TSqliteDataset;
|
||||||
|
ini: TIniFile;
|
||||||
|
|
||||||
|
begin
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
SetHeapTraceOutput('heaplog.txt');
|
SetHeapTraceOutput(ExtractFileName(ParamStr(0))+'.heap.log');
|
||||||
{$endif}
|
{$endif}
|
||||||
dsTest:=TsqliteDataset.Create(nil);
|
dsTest:=TSqliteDataset.Create(nil);
|
||||||
with dsTest do
|
with dsTest do
|
||||||
Begin
|
begin
|
||||||
FileName:='New.db';
|
//Load Database properties from a inifile
|
||||||
TableName:='NewTable';
|
ini:=TIniFile.Create(SQLITEDS_TESTS_INI_FILE);
|
||||||
Sql:= 'SELECT _ROWID_,* FROM NewTable';
|
FileName:=ini.ReadString('testinfo','filename',DEFAULT_FILENAME);
|
||||||
|
TableName:=ini.ReadString('testinfo','tablename',DEFAULT_TABLENAME);
|
||||||
|
ini.Destroy;
|
||||||
|
//Calling Open with an empty SQL, is the same of setting SQL to 'SELECT * from [TableName]';
|
||||||
Open;
|
Open;
|
||||||
|
//Add some dummy values
|
||||||
Append;
|
Append;
|
||||||
FieldByName('Code').AsInteger:=100;
|
FieldByName('Integer').AsInteger:=100;
|
||||||
FieldByName('Name').AsString:='Luiz';
|
FieldByName('String').AsString:='Luiz';
|
||||||
FieldByName('Bool').AsBoolean:= True;
|
FieldByName('Boolean').AsBoolean:= False;
|
||||||
FieldByName('Float').AsFloat:=2;
|
FieldByName('Float').AsFloat:=2;
|
||||||
|
FieldByName('Word').AsInteger:=2763;
|
||||||
FieldByName('DateTime').AsDateTime:=Now;
|
FieldByName('DateTime').AsDateTime:=Now;
|
||||||
FieldByName('Time').AsDateTime:=Time;
|
FieldByName('Time').AsDateTime:=Time;
|
||||||
FieldByName('Date').AsDateTime:=Date;
|
FieldByName('Date').AsDateTime:=Date;
|
||||||
|
FieldByName('Memo').AsString:='Here is a long text (Not so long in fact :-))';
|
||||||
|
FieldByName('Currency').AsFloat:=1.23;
|
||||||
|
FieldByName('LargeInt').AsLargeInt:=2163871263187263;
|
||||||
Post;
|
Post;
|
||||||
Append;
|
Append;
|
||||||
FieldByName('Code').AsInteger:=101;
|
FieldByName('Integer').AsInteger:=101;
|
||||||
FieldByName('Name').AsString:='Américo';
|
FieldByName('String').AsString:='Américo';
|
||||||
FieldByName('Bool').AsBoolean:= True;
|
FieldByName('Boolean').AsBoolean:= False;
|
||||||
FieldByName('Float').AsFloat:=1.1;
|
FieldByName('Float').AsFloat:=1.1;
|
||||||
FieldByName('DateTime').AsDateTime:=Now;
|
FieldByName('DateTime').AsDateTime:=Now;
|
||||||
FieldByName('Time').AsDateTime:=Time;
|
FieldByName('Time').AsDateTime:=Time;
|
||||||
FieldByName('Date').AsDateTime:=Date;
|
FieldByName('Date').AsDateTime:=Date;
|
||||||
|
FieldByName('LargeInt').AsLargeInt:=-9223372036854775808;
|
||||||
|
//a real long text :-).
|
||||||
|
if FileExists(MEMOTEST_FILENAME) then
|
||||||
|
TMemoField(FieldByName('Memo')).LoadFromFile(MEMOTEST_FILENAME);
|
||||||
Post;
|
Post;
|
||||||
Append;
|
Append;
|
||||||
FieldByName('Code').AsInteger:=102;
|
FieldByName('Integer').AsInteger:=102;
|
||||||
FieldByName('Name').AsString:='Ana';
|
FieldByName('String').AsString:='Ana';
|
||||||
FieldByName('Bool').AsBoolean:= False;
|
FieldByName('Boolean').AsBoolean:= False;
|
||||||
FieldByName('Float').AsFloat:=5.0E-324;
|
FieldByName('Float').AsFloat:=5.0E-324;
|
||||||
FieldByName('DateTime').AsDateTime:=Now;
|
FieldByName('DateTime').AsDateTime:=Now;
|
||||||
FieldByName('Time').AsDateTime:=Time;
|
FieldByName('Time').AsDateTime:=Time;
|
||||||
FieldByName('Date').AsDateTime:=Date;
|
FieldByName('Date').AsDateTime:=Date;
|
||||||
|
FieldByName('LargeInt').AsLargeInt:=9223372036854775807;
|
||||||
Post;
|
Post;
|
||||||
Append;
|
Append;
|
||||||
FieldByName('Code').AsInteger:=103;
|
FieldByName('Integer').AsInteger:=103;
|
||||||
FieldByName('Name').AsString:='Luiza';
|
FieldByName('String').AsString:='Luiza';
|
||||||
FieldByName('Bool').AsBoolean:= False;
|
FieldByName('Boolean').AsBoolean:= True;
|
||||||
FieldByName('Float').AsFloat:=1.7E308;
|
FieldByName('Float').AsFloat:=1.7E308;
|
||||||
FieldByName('DateTime').AsDateTime:=Now;
|
FieldByName('DateTime').AsDateTime:=Now;
|
||||||
FieldByName('Time').AsDateTime:=Time;
|
FieldByName('Time').AsDateTime:=Time;
|
||||||
FieldByName('Date').AsDateTime:=Date;
|
FieldByName('Date').AsDateTime:=Date;
|
||||||
|
FieldByName('Currency').AsFloat:=20.08;
|
||||||
Post;
|
Post;
|
||||||
|
//Save the added data to database
|
||||||
ApplyUpdates;
|
ApplyUpdates;
|
||||||
writeln('Last sqlite return: ',SqliteReturnString);
|
writeln('ReturnString after ApplyUpdates: ',ReturnString);
|
||||||
Close;
|
//Is not necessary to call Close. Destroy will call it.
|
||||||
|
//Close;
|
||||||
Destroy;
|
Destroy;
|
||||||
end;
|
end;
|
||||||
exit;
|
|
||||||
end.
|
end.
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
program testds;
|
program testds;
|
||||||
|
|
||||||
{$Mode ObjFpc}
|
{$Mode ObjFpc}
|
||||||
|
{$H+}
|
||||||
{$define DEBUGHEAP}
|
{$define DEBUGHEAP}
|
||||||
|
|
||||||
|
//To test the sqlite3 version replace sqliteds by sqlite3ds
|
||||||
|
// and TSqliteDataset by TSqlite3Dataset
|
||||||
|
|
||||||
uses
|
uses
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
Heaptrc,
|
Heaptrc,
|
||||||
@ -8,103 +14,91 @@ uses
|
|||||||
{$ifdef Linux}
|
{$ifdef Linux}
|
||||||
cmem,
|
cmem,
|
||||||
{$endif}
|
{$endif}
|
||||||
crt,sysutils,db,SqliteDS;
|
crt,sysutils,db,sqliteds,IniFiles;
|
||||||
|
|
||||||
|
const
|
||||||
|
SQLITEDS_TESTS_INI_FILE = 'sqlitedstests.ini';
|
||||||
|
DEFAULT_TABLENAME = 'tabletest';
|
||||||
|
DEFAULT_FILENAME = 'test.db';
|
||||||
|
|
||||||
var
|
var
|
||||||
dsTest:TSQliteDataset;
|
dsTest:TSqliteDataset;
|
||||||
I:Integer;
|
ini: TIniFile;
|
||||||
|
|
||||||
Procedure DumpField(F : Tfield);
|
|
||||||
|
|
||||||
begin
|
|
||||||
With F do
|
|
||||||
begin
|
|
||||||
Writeln ('FieldName : ',FieldName);
|
|
||||||
Writeln ('FieldNo : ',FieldNo);
|
|
||||||
Writeln ('Index : ',Index);
|
|
||||||
Writeln ('DataSize : ',DataSize);
|
|
||||||
Writeln ('Size : ',Size);
|
|
||||||
Writeln ('DataType : ',FieldTypeNames[DataType]);
|
|
||||||
Writeln ('Class : ',ClassName);
|
|
||||||
Writeln ('Required : ',required);
|
|
||||||
Writeln ('ReadOnly : ',ReadOnly);
|
|
||||||
Writeln ('Visible : ',Visible);
|
|
||||||
end;
|
|
||||||
writeln('-------- Press a key to continue ----------');
|
|
||||||
readkey;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$ifdef DEBUGHEAP}
|
{$ifdef DEBUGHEAP}
|
||||||
SetHeapTraceOutput('heaplog.txt');
|
SetHeapTraceOutput(ExtractFileName(ParamStr(0))+'.heap.log');
|
||||||
{$endif}
|
{$endif}
|
||||||
dsTest:=TsqliteDataset.Create(nil);
|
dsTest:=TSqliteDataset.Create(nil);
|
||||||
with dsTest do
|
with dsTest do
|
||||||
Begin
|
begin
|
||||||
FileName:='New.db';
|
//Load Database properties from a inifile
|
||||||
TableName:='NewTable';
|
ini:=TIniFile.Create(SQLITEDS_TESTS_INI_FILE);
|
||||||
SQL:='SELECT _ROWID_,* from NewTable';
|
FileName:=ini.ReadString('testinfo','filename',DEFAULT_FILENAME);
|
||||||
|
TableName:=ini.ReadString('testinfo','tablename',DEFAULT_TABLENAME);
|
||||||
|
ini.Destroy;
|
||||||
|
//Calling Open with an empty SQL, is the same of setting SQL to 'SELECT * from [TableName]';
|
||||||
Open;
|
Open;
|
||||||
//writeln('SqliteReturnString after Open: ',SqliteReturnString);
|
|
||||||
//readkey;
|
|
||||||
Writeln ('Fields count : ',FieldCount);
|
|
||||||
WriteLn('============DumpFields ============');
|
|
||||||
For I:=0 to FieldCount-1 do
|
|
||||||
DumpField(Fields[i]);
|
|
||||||
writeln('Push a key to test -Edit-');
|
writeln('Push a key to test -Edit-');
|
||||||
readkey;
|
Readkey;
|
||||||
clrscr;
|
ClrScr;
|
||||||
WriteLn('Old Code:',FieldbyName('Code').AsInteger);
|
WriteLn('Old Integer:',FieldbyName('Integer').AsInteger);
|
||||||
WriteLn('Old Name:',FieldbyName('Name').AsString);
|
WriteLn('Old String:',FieldbyName('String').AsString);
|
||||||
FieldbyName('Code').AsInteger:=12345;
|
Edit;
|
||||||
FieldbyName('Name').AsString:='Record Edited in TestDs.pas';
|
FieldbyName('Integer').AsInteger:=12345;
|
||||||
WriteLn('New Code:',FieldbyName('Code').AsInteger);
|
FieldbyName('String').AsString:='Record Edited in TestDs.pas';
|
||||||
WriteLn('New Name:',FieldbyName('Name').AsString);
|
|
||||||
writeln('Push a key to test -Append-');
|
|
||||||
readkey;
|
|
||||||
clrscr;
|
|
||||||
Append;
|
|
||||||
FieldbyName('Code').AsInteger:=22222;
|
|
||||||
FieldbyName('Name').AsString:='This will be deleted';
|
|
||||||
Post;
|
Post;
|
||||||
WriteLn('First Record Appended - Code:',FieldbyName('Code').AsInteger);
|
WriteLn('New Integer:',FieldbyName('Integer').AsInteger);
|
||||||
WriteLn('First Record Appended - Name:',FieldbyName('Name').AsString);
|
WriteLn('New String:',FieldbyName('String').AsString);
|
||||||
|
|
||||||
|
WriteLn('Push a key to test -Append-');
|
||||||
|
ReadKey;
|
||||||
|
ClrScr;
|
||||||
Append;
|
Append;
|
||||||
FieldbyName('Code').AsInteger:=3333;
|
FieldbyName('Integer').AsInteger:=22222;
|
||||||
FieldbyName('Name').AsString:='This will stay';
|
FieldbyName('String').AsString:='This will be deleted';
|
||||||
Post;
|
Post;
|
||||||
WriteLn('Second Record Appended - Code:',FieldbyName('Code').AsInteger);
|
WriteLn('First Record Appended - Integer:',FieldbyName('Integer').AsInteger);
|
||||||
WriteLn('Second Record Appended - Name:',FieldbyName('Name').AsString);
|
WriteLn('First Record Appended - String:',FieldbyName('String').AsString);
|
||||||
writeln('Push a key to test -Delete-');
|
Append;
|
||||||
readkey;
|
FieldbyName('Integer').AsInteger:=3333;
|
||||||
clrscr;
|
FieldbyName('String').AsString:='This will stay';
|
||||||
|
Post;
|
||||||
|
WriteLn('Second Record Appended - Integer:',FieldbyName('Integer').AsInteger);
|
||||||
|
WriteLn('Second Record Appended - String:',FieldbyName('String').AsString);
|
||||||
|
|
||||||
|
WriteLn('Push a key to test -Delete-');
|
||||||
|
ReadKey;
|
||||||
|
ClrScr;
|
||||||
Prior;
|
Prior;
|
||||||
WriteLn('Current record:');
|
WriteLn('Current record:');
|
||||||
Writeln('RowId:',Fields[0].AsInteger);
|
WriteLn('Integer: ',FieldbyName('Integer').AsInteger);
|
||||||
WriteLn('Code: ',FieldbyName('Code').AsInteger);
|
WriteLn('String: ',FieldbyName('String').AsString);
|
||||||
WriteLn('Name: ',FieldbyName('Name').AsString);
|
if FieldbyName('Integer').AsInteger = 22222 then
|
||||||
if FieldbyName('Code').AsInteger = 22222 then
|
begin
|
||||||
Writeln('This record should be deleted');
|
Writeln('This record should be deleted');
|
||||||
Delete;
|
Delete;
|
||||||
|
end;
|
||||||
WriteLn('After Delete:');
|
WriteLn('After Delete:');
|
||||||
Writeln('RowId:',Fields[0].AsInteger);
|
WriteLn('Integer: ',FieldbyName('Integer').AsInteger);
|
||||||
WriteLn('Code: ',FieldbyName('Code').AsInteger);
|
WriteLn('String: ',FieldbyName('String').AsString);
|
||||||
WriteLn('Name: ',FieldbyName('Name').AsString);
|
|
||||||
|
|
||||||
WriteLn('Try to find record with code = 22222');
|
WriteLn('Try to find record with code = 22222');
|
||||||
First;
|
First;
|
||||||
While Not Eof do
|
while not Eof do
|
||||||
begin
|
begin
|
||||||
if FieldbyName('Code').AsInteger = 22222 then
|
if FieldByName('Integer').AsInteger = 22222 then
|
||||||
Writeln('Record Found: It Should Not Occur')
|
Writeln('Record Found Manually: It''s a bug')
|
||||||
else
|
else
|
||||||
Writeln('Record NOT Found: It''s OK');
|
Writeln('Record NOT Found Manually: It''s OK');
|
||||||
Next;
|
Next;
|
||||||
end;
|
end;
|
||||||
readkey;
|
if Locate('Integer',22222,[]) then
|
||||||
|
WriteLn('Record Found Using Locate: It''s a bug')
|
||||||
|
else
|
||||||
|
WriteLn('Record Not Found Using Locate: It''s OK');
|
||||||
ApplyUpdates;
|
ApplyUpdates;
|
||||||
writeln('SqliteReturnString after ApplyUpdates: ',SqliteReturnString);
|
writeln('ReturnString after ApplyUpdates: ',ReturnString);
|
||||||
Close;
|
|
||||||
Destroy;
|
Destroy;
|
||||||
end;
|
end;
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user