mORMot and Open Source friends
Check-in [dc304caa30]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:fix unit tests when compiled on a non Win1252 charset system
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dc304caa30534c6128cc4af21b752ec0a32b3802
User & Date: ab 2011-06-09 05:19:45
Context
2011-06-10
14:27
new SynOleDB unit check-in: fac9c4ffce user: ab tags: trunk
2011-06-09
05:19
fix unit tests when compiled on a non Win1252 charset system check-in: dc304caa30 user: ab tags: trunk
2011-06-08
15:24
fixed small typo check-in: 1d07de30ab user: ab tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to SQLite3/SQLite3.pas.

5515
5516
5517
5518
5519
5520
5521





5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
....
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
....
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236

6237
6238
6239
6240
6241
6242
6243
  inherited;
end;

{$ifdef UNICODE}
{$WARNINGS OFF} // don't care about implicit string cast in tests
{$endif}






procedure TTestSQLite3Engine.DirectAccess;
procedure InsertData(n: integer);
var i: integer;
    s: WinAnsiString;
    ins: RawUTF8;
    R: TSQLRequest;
begin
  // this code is a lot faster than sqlite3 itself, even if it use Utf8 encoding:
  // -> we test the engine speed, not the test routines speed :)
 ins := 'INSERT INTO People (FirstName,LastName,Data,YearOfBirth,YearOfDeath) VALUES (''';
 for i := 1 to n do begin
   str(i,s);
   // we put some accents in order to test UTF-8 encoding
   R.Prepare(Demo.DB,ins+'Salvador'+s+''', ''Dali'', ?, 1904, 1989);');
   R.Bind(1,PAnsiChar('a'+chr(233)+chr(224)+chr(231)),4); // Bind Blob
   R.Execute;
   Demo.Execute(ins+WinAnsiToUtf8('Samuel Finley Breese'+s+''', ''Morse'', ''a'+chr(233)+chr(224)+chr(231)+''', 1791, 1872);'));
   Demo.Execute(ins+WinAnsiToUtf8('Sergei'+s+''', ''Rachmaninoff'', '''+chr(233)+'z'+chr(231)+'b'', 1873, 1943);'));
   Demo.Execute(ins+WinAnsiToUtf8('Alexandre'+s+''', ''Dumas'', '''+chr(233)+chr(231)+'b'', 1802, 1870);'));
   Demo.Execute(ins+WinAnsiToUtf8('Franz'+s+''', ''Schubert'', '''+chr(233)+chr(224)+chr(231)+'a'', 1797, 1828);'));
   Demo.Execute(ins+WinAnsiToUtf8('Leonardo'+s+''', ''da Vin'+chr(231)+'i'', ''@'+chr(231)+'b'', 1452, 1519);'));
   Demo.Execute(ins+WinAnsiToUtf8('Aldous Leonard'+s+''', ''Huxley'', '''+chr(233)+chr(224)+''', 1894, 1963);'));
   R.Prepare(Demo.DB,ins+WinAnsiToUtf8('Claud'+chr(232)+s+#10#7''', ''M'#244'net'', ?, 1840, 1926);'));
   R.Bind(1,PAnsiChar(chr(224)+chr(233)+chr(231)+'dsjdsBLOB23'),14); // Bind Blob
   R.Execute;
   Demo.Execute(ins+WinAnsiToUtf8('Albert'+s+''', ''Einstein'', '''+chr(233)+chr(231)+'p'', 1879, 1955);'));
   Demo.Execute(ins+WinAnsiToUtf8('Johannes'+s+''', ''Gutenberg'', '''#234'mls'', 1400, 1468);'));
   Demo.Execute(ins+WinAnsiToUtf8('Jane'+s+''', ''Aust'+chr(232)+'n'', '''+chr(231)+chr(224)+chr(231)+'m'', 1775, 1817);'));
 end;
end;
const
  ReqAnsi: WinAnsiString =
    'SELECT * FROM People WHERE LastName=''M'#244'net'' ORDER BY FirstName;';
  SoundexValues: array[0..5] of RawUTF8 =
    ('bonjour','bonchour','Bnjr','mohammad','mohhhammeeet','bonjourtr'+chr(232)+'slongmotquid'+chr(233)+'passe');
  LOG1: RawUTF8 = 'D:\Dev\lib\SQLite3\exe\TestSQL3.exe 1.2.3.4 (2011-04-07)'#13#10+
    'Host=MyPC User=MySelf CPU=2*0-15-1027 OS=2.3=5.1.2600 Wow64=0 Freq=3579545'#13#10+
    'TSynLog 1.13 LVCL 2011-04-07 12:04:09'#13#10#13#10+
    '20110407 12040904 debug {"TObjectList(00AF8D00)":["TObjectList(00AF8D20)",'+
    '"TObjectList(00AF8D60)","TFileVersion(00ADC0B0)","TSynMapFile(00ACC990)"]}';
................................................................................
      with Client.fServer.Model do
        for i := 0 to high(Tables) do
          if not Check(GetTableIndex(Tables[i])=i) then
            Check(GetTableIndex(Tables[i].SQLTableName)=i);
      // direct client access test
      Client.fServer.CreateMissingTables(0); // NEED Dest,Source,Dests,...
      Check(Client.SetUser('User','synopse')); // use default user
      DaVinci := WinAnsiToUtf8('da Vin'#231'i');
      Check(Client.Retrieve('LastName='''+DaVinci+'''',V));
      Check(V.FirstName='Leonardo1');
      Check(V.LastName=DaVinci);
      Check(V.YearOfBirth=1452);
      Check(V.YearOfDeath=1519);
      checks(false,Client,'Retrieve');
      Check(V.ID=6,'check RETRIEVE/GET');
................................................................................
      Check(not V2.SameValues(V),'V and V2 must differ');
      Check(Client.UpdateFromServer([V2],Refreshed));
      Check(Refreshed,'V2 value will be synchronized with V');
      Check(V2.SameValues(V));
      Check(Client.UpdateFromServer([V2],Refreshed));
      Check(not Refreshed);
      Req := StringReplace(Req,'*',TSQLRecordPeople.RecordProps.SQLTableSimpleFields[true,false],[]);
      s := WinAnsiToUtf8('LastName=''M'#244'net'' ORDER BY LastName');
      J := Client.List([TSQLRecordPeople],'*',s);
      Check(Client.UpdateFromServer([J],Refreshed));
      Check(not Refreshed);
      Check(Test(J),'incorrect TSQLTableJSON');
      Check(Client.OneFieldValues(TSQLRecordPeople,'ID','LastName=:("Dali"):',IntArray));
      Check(length(IntArray)=1001);
      for i := 0 to high(IntArray) do
        Check(Client.OneFieldValue(TSQLRecordPeople,'LastName',IntArray[i])='Dali');
      Check(Client.TransactionBegin(TSQLRecordPeople)); // for UpdateBlob() below
      for i := 0 to high(IntArray) do begin
        Check(Client.RetrieveBlob(TSQLRecordPeople,IntArray[i],'Data',Data));
        Check(Data='a'#233#224#231);

        Check(Client.RetrieveBlob(TSQLRecordPeople,IntArray[i],'Data',DataS));
        Check((DataS.Size=4) and (PCardinal(DataS.Memory)^=$E7E0E961));
        DataS.Free;
        Check(Client.UpdateBlob(TSQLRecordPeople,IntArray[i],'Data',@IntArray[i],4));
        Check(Client.RetrieveBlob(TSQLRecordPeople,IntArray[i],'Data',Data));
        Check((length(Data)=4) and (PInteger(pointer(Data))^=IntArray[i]));
        V2.ID := IntArray[i]; // debug use - do NOT set ID in your programs!






>
>
>
>
>



|









|
|

|
|
|
|
|
|
|
|

|
|
|




|







 







|







 







|











|
>







5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
....
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
....
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
  inherited;
end;

{$ifdef UNICODE}
{$WARNINGS OFF} // don't care about implicit string cast in tests
{$endif}

const // BLOBs are stored as array of byte to avoid any charset conflict
  BlobDali: array[0..3] of byte = (97,233,224,231);
  BlobMonet: array[0..13] of byte = (224,233,231,ord('d'),ord('s'),ord('j'),
        ord('d'),ord('s'),ord('B'),ord('L'),ord('O'),ord('B'),ord('2'),ord('3'));

procedure TTestSQLite3Engine.DirectAccess;
procedure InsertData(n: integer);
var i: integer;
    s: string;
    ins: RawUTF8;
    R: TSQLRequest;
begin
  // this code is a lot faster than sqlite3 itself, even if it use Utf8 encoding:
  // -> we test the engine speed, not the test routines speed :)
 ins := 'INSERT INTO People (FirstName,LastName,Data,YearOfBirth,YearOfDeath) VALUES (''';
 for i := 1 to n do begin
   str(i,s);
   // we put some accents in order to test UTF-8 encoding
   R.Prepare(Demo.DB,ins+'Salvador'+RawUTF8(s)+''', ''Dali'', ?, 1904, 1989);');
   R.Bind(1,@BlobDali,4); // Bind Blob
   R.Execute;
   Demo.Execute(ins+StringToUtf8('Samuel Finley Breese'+s+''', ''Morse'', ''a'+chr(233)+chr(224)+chr(231)+''', 1791, 1872);'));
   Demo.Execute(ins+StringToUtf8('Sergei'+s+''', ''Rachmaninoff'', '''+chr(233)+'z'+chr(231)+'b'', 1873, 1943);'));
   Demo.Execute(ins+StringToUtf8('Alexandre'+s+''', ''Dumas'', '''+chr(233)+chr(231)+'b'', 1802, 1870);'));
   Demo.Execute(ins+StringToUtf8('Franz'+s+''', ''Schubert'', '''+chr(233)+chr(224)+chr(231)+'a'', 1797, 1828);'));
   Demo.Execute(ins+StringToUtf8('Leonardo'+s+''', ''da Vin'+chr(231)+'i'', ''@'+chr(231)+'b'', 1452, 1519);'));
   Demo.Execute(ins+StringToUtf8('Aldous Leonard'+s+''', ''Huxley'', '''+chr(233)+chr(224)+''', 1894, 1963);'));
   R.Prepare(Demo.DB,ins+StringToUtf8('Claud'+chr(232)+s+#10#7''', ''M'+chr(244)+'net'', ?, 1840, 1926);'));
   R.Bind(1,@BlobMonet,sizeof(BlobMonet)); // Bind Blob
   R.Execute;
   Demo.Execute(ins+StringToUtf8('Albert'+s+''', ''Einstein'', '''+chr(233)+chr(231)+'p'', 1879, 1955);'));
   Demo.Execute(ins+StringToUtf8('Johannes'+s+''', ''Gutenberg'', '''+chr(234)+'mls'', 1400, 1468);'));
   Demo.Execute(ins+StringToUtf8('Jane'+s+''', ''Aust'+chr(232)+'n'', '''+chr(231)+chr(224)+chr(231)+'m'', 1775, 1817);'));
 end;
end;
const
  ReqAnsi: WinAnsiString =
    'SELECT * FROM People WHERE LastName=''M'+chr(244)+'net'' ORDER BY FirstName;';
  SoundexValues: array[0..5] of RawUTF8 =
    ('bonjour','bonchour','Bnjr','mohammad','mohhhammeeet','bonjourtr'+chr(232)+'slongmotquid'+chr(233)+'passe');
  LOG1: RawUTF8 = 'D:\Dev\lib\SQLite3\exe\TestSQL3.exe 1.2.3.4 (2011-04-07)'#13#10+
    'Host=MyPC User=MySelf CPU=2*0-15-1027 OS=2.3=5.1.2600 Wow64=0 Freq=3579545'#13#10+
    'TSynLog 1.13 LVCL 2011-04-07 12:04:09'#13#10#13#10+
    '20110407 12040904 debug {"TObjectList(00AF8D00)":["TObjectList(00AF8D20)",'+
    '"TObjectList(00AF8D60)","TFileVersion(00ADC0B0)","TSynMapFile(00ACC990)"]}';
................................................................................
      with Client.fServer.Model do
        for i := 0 to high(Tables) do
          if not Check(GetTableIndex(Tables[i])=i) then
            Check(GetTableIndex(Tables[i].SQLTableName)=i);
      // direct client access test
      Client.fServer.CreateMissingTables(0); // NEED Dest,Source,Dests,...
      Check(Client.SetUser('User','synopse')); // use default user
      DaVinci := WinAnsiToUtf8('da Vin'+chr(231)+'i');
      Check(Client.Retrieve('LastName='''+DaVinci+'''',V));
      Check(V.FirstName='Leonardo1');
      Check(V.LastName=DaVinci);
      Check(V.YearOfBirth=1452);
      Check(V.YearOfDeath=1519);
      checks(false,Client,'Retrieve');
      Check(V.ID=6,'check RETRIEVE/GET');
................................................................................
      Check(not V2.SameValues(V),'V and V2 must differ');
      Check(Client.UpdateFromServer([V2],Refreshed));
      Check(Refreshed,'V2 value will be synchronized with V');
      Check(V2.SameValues(V));
      Check(Client.UpdateFromServer([V2],Refreshed));
      Check(not Refreshed);
      Req := StringReplace(Req,'*',TSQLRecordPeople.RecordProps.SQLTableSimpleFields[true,false],[]);
      s := WinAnsiToUtf8('LastName=''M'+chr(244)+'net'' ORDER BY LastName');
      J := Client.List([TSQLRecordPeople],'*',s);
      Check(Client.UpdateFromServer([J],Refreshed));
      Check(not Refreshed);
      Check(Test(J),'incorrect TSQLTableJSON');
      Check(Client.OneFieldValues(TSQLRecordPeople,'ID','LastName=:("Dali"):',IntArray));
      Check(length(IntArray)=1001);
      for i := 0 to high(IntArray) do
        Check(Client.OneFieldValue(TSQLRecordPeople,'LastName',IntArray[i])='Dali');
      Check(Client.TransactionBegin(TSQLRecordPeople)); // for UpdateBlob() below
      for i := 0 to high(IntArray) do begin
        Check(Client.RetrieveBlob(TSQLRecordPeople,IntArray[i],'Data',Data));
        Check(Length(Data)=sizeof(BlobDali));
        Check(CompareMem(pointer(Data),@BlobDali,sizeof(BlobDali)));
        Check(Client.RetrieveBlob(TSQLRecordPeople,IntArray[i],'Data',DataS));
        Check((DataS.Size=4) and (PCardinal(DataS.Memory)^=$E7E0E961));
        DataS.Free;
        Check(Client.UpdateBlob(TSQLRecordPeople,IntArray[i],'Data',@IntArray[i],4));
        Check(Client.RetrieveBlob(TSQLRecordPeople,IntArray[i],'Data',Data));
        Check((length(Data)=4) and (PInteger(pointer(Data))^=IntArray[i]));
        V2.ID := IntArray[i]; // debug use - do NOT set ID in your programs!