Ver código fonte

Merged revisions 10706,10709,10713-10716,10718-10719,10723,10735-10740,10743-10744,10749,10751-10752,10755-10757,10759-10761,10763,10769,10772-10779,10782-10790,10794-10795,10798,10807,10812,10814,10817-10819,10821-10822,10824,10830-10832,10837,10839,10844 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r10706 | joost | 2008-04-18 22:14:21 +0200 (Fri, 18 Apr 2008) | 1 line

* Removed "as" keyword from query, it is not supported by Firebird
........
r10740 | joost | 2008-04-20 21:19:44 +0200 (Sun, 20 Apr 2008) | 1 line

* Add sqQuoteFieldnames to postgresql connectionparameters
........
r10743 | joost | 2008-04-20 22:34:04 +0200 (Sun, 20 Apr 2008) | 1 line

* Handle String-Parameters as text parameters
........
r10744 | joost | 2008-04-20 23:28:32 +0200 (Sun, 20 Apr 2008) | 1 line

* Added support for stColumns to GetSchemaInfoSQL
........
r10752 | joost | 2008-04-21 21:40:05 +0200 (Mon, 21 Apr 2008) | 1 line

* Refactored test
........
r10763 | joost | 2008-04-22 22:38:48 +0200 (Tue, 22 Apr 2008) | 1 line

* Base indexes on AnsiCompareStr/AnsiCompareText and modified tests
........
r10779 | joost | 2008-04-23 23:26:31 +0200 (Wed, 23 Apr 2008) | 1 line

* Mysql servers before version 5.0.3 removes trailing spaces on varchar fields, adapted testvalues to take this into account
........
r10786 | joost | 2008-04-24 22:33:44 +0200 (Thu, 24 Apr 2008) | 1 line

* Refactored test-values, removed duplicate and re-enabled a string-testvalue containing quotes
........
r10807 | joost | 2008-04-26 22:43:44 +0200 (Sat, 26 Apr 2008) | 3 lines

* Fixed warning
* Use consistent test data between 32-bit and 64-bit
* Fix range-overflow problem in building indexes
........
r10812 | joost | 2008-04-27 10:37:15 +0200 (Sun, 27 Apr 2008) | 1 line

* Patch from Luk Vandelaer to use username, password and pagesize on creation of a database
........
r10814 | joost | 2008-04-27 13:56:05 +0200 (Sun, 27 Apr 2008) | 1 line

* Clean up TestScript-test properly
........
r10817 | joost | 2008-04-27 17:46:55 +0200 (Sun, 27 Apr 2008) | 1 line

* Map string-fields with a size above dsMaxStringSize to ftMemo-fields
........
r10818 | joost | 2008-04-27 18:13:11 +0200 (Sun, 27 Apr 2008) | 1 line

* Improved r10817
........
r10819 | joost | 2008-04-27 18:14:04 +0200 (Sun, 27 Apr 2008) | 1 line

* Allow a size (amount of decimals) of 0 for TBCDFields
........
r10821 | joost | 2008-04-27 22:13:49 +0200 (Sun, 27 Apr 2008) | 1 line

* Correct a test for mysql version 5 (server)
........
r10822 | joost | 2008-04-27 22:15:46 +0200 (Sun, 27 Apr 2008) | 1 line

* Fixes for ftCurrency fields
........
r10824 | joost | 2008-04-27 22:24:29 +0200 (Sun, 27 Apr 2008) | 1 line

* Reverted accidental commit in r10821
........
r10839 | joost | 2008-04-29 23:54:45 +0200 (Tue, 29 Apr 2008) | 1 line

* Commit the DDL-transaction in the TestScript test. (interbase only)
........
r10844 | joost | 2008-04-30 19:32:12 +0200 (Wed, 30 Apr 2008) | 1 line

* Avoid second exception while handling the first
........

git-svn-id: branches/fixes_2_2@10935 -

joost 17 anos atrás
pai
commit
5b562a9537

+ 33 - 37
packages/fcl-db/src/base/bufdataset.pas

@@ -276,35 +276,13 @@ implementation
 
 uses variants, dbconst;
 
-function DBCompareTextLen(substr, astr: pchar; len : integer; options: TLocateOptions): int64;
-
-var
-  i : integer; Chr1, Chr2: byte;
-begin
-  result := 0;
-  i := 0;
-  chr1 := 1;
-  while (result=0) and (i<=len) and (chr1 <> 0) do
-    begin
-    Chr1 := byte(substr[i]);
-    Chr2 := byte(astr[i]);
-    inc(i);
-    if loCaseInsensitive in options then
-      begin
-      if Chr1 in [97..122] then
-        dec(Chr1,32);
-      if Chr2 in [97..122] then
-        dec(Chr2,32);
-      end;
-    result := Chr1 - Chr2;
-    end;
-  if (result <> 0) and (chr1 = 0) and (loPartialKey in options) then result := 0;
-end;
-
 function DBCompareText(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
 
 begin
-  Result := DBCompareTextLen(subValue,aValue,Length(pchar(subValue)),options);
+  if loCaseInsensitive in options then
+    Result := AnsiCompareText(pchar(subValue),pchar(aValue))
+  else
+    Result := AnsiCompareStr(pchar(subValue),pchar(aValue));
 end;
 
 function DBCompareByte(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
@@ -328,7 +306,14 @@ end;
 function DBCompareLargeInt(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
 
 begin
-  Result := PInt64(subValue)^-PInt64(aValue)^;
+  // A simple subtraction doesn't work, since it could be that the result
+  // doesn't fit into a LargeInt
+  if PLargeInt(subValue)^ < PLargeInt(aValue)^ then
+    result := -1
+  else if PLargeInt(subValue)^  > PLargeInt(aValue)^ then
+    result := 1
+  else
+    result := 0;
 end;
 
 function DBCompareWord(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
@@ -340,16 +325,27 @@ end;
 function DBCompareQWord(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
 
 begin
-  Result := PQWord(subValue)^-PQWord(aValue)^;
+  // A simple subtraction doesn't work, since it could be that the result
+  // doesn't fit into a LargeInt
+  if PQWord(subValue)^ < PQWord(aValue)^ then
+    result := -1
+  else if PQWord(subValue)^  > PQWord(aValue)^ then
+    result := 1
+  else
+    result := 0;
 end;
 
 function DBCompareDouble(subValue, aValue: pointer; options: TLocateOptions): LargeInt;
 var Dbl : Double;
 begin
-  Dbl := PDouble(subValue)^-PDouble(aValue)^;
-  if dbl < 0 then result := -1
-  else if dbl > 0 then result := 1
-  else result := 0;
+  // A simple subtraction doesn't work, since it could be that the result
+  // doesn't fit into a LargeInt
+  if PDouble(subValue)^ < PDouble(aValue)^ then
+    result := -1
+  else if PDouble(subValue)^  > PDouble(aValue)^ then
+    result := 1
+  else
+    result := 0;
 end;
 
 function IndexCompareRecords(Rec1,Rec2 : pointer; ADBCompareRecs : TDBCompareStruct) : LargeInt;
@@ -963,11 +959,11 @@ begin
   case AField.DataType of
     ftString : ACompareRec.Comparefunc := @DBCompareText;
     ftSmallint : ACompareRec.Comparefunc := @DBCompareSmallInt;
-    ftInteger, ftCurrency, ftBCD : ACompareRec.Comparefunc :=
+    ftInteger, ftBCD : ACompareRec.Comparefunc :=
       @DBCompareInt;
     ftWord : ACompareRec.Comparefunc := @DBCompareWord;
     ftBoolean : ACompareRec.Comparefunc := @DBCompareByte;
-    ftFloat : ACompareRec.Comparefunc := @DBCompareDouble;
+    ftFloat, ftCurrency : ACompareRec.Comparefunc := @DBCompareDouble;
     ftDateTime, ftDate, ftTime : ACompareRec.Comparefunc :=
       @DBCompareDouble;
     ftLargeint : ACompareRec.Comparefunc := @DBCompareLargeInt;
@@ -1125,8 +1121,7 @@ function TBufDataset.getnextpacket : integer;
 
 var i : integer;
     pb : pchar;
-    IndexNr : integer;
-    
+
 begin
   if FAllPacketsFetched then
     begin
@@ -1183,7 +1178,8 @@ begin
       ftword     : result := sizeof(longint);
     ftBoolean    : result := sizeof(wordbool);
     ftBCD        : result := sizeof(currency);
-    ftFloat      : result := sizeof(double);
+    ftFloat,
+      ftCurrency : result := sizeof(double);
     ftLargeInt   : result := sizeof(largeint);
     ftTime,
       ftDate,

+ 10 - 3
packages/fcl-db/src/sqldb/interbase/ibconnection.pp

@@ -280,8 +280,8 @@ procedure TIBConnection.CreateDB;
 
 var ASQLDatabaseHandle,
     ASQLTransactionHandle : pointer;
-    CreateSQL             : String;
-
+    CreateSQL : String;
+    pagesize : String;
 begin
   CheckDisConnected;
 {$IfDef LinkDynamically}
@@ -289,10 +289,17 @@ begin
 {$EndIf}
   ASQLDatabaseHandle := nil;
   ASQLTransactionHandle := nil;
-  
+
   CreateSQL := 'CREATE DATABASE ';
   if HostName <> '' then CreateSQL := CreateSQL + ''''+ HostName+':'+DatabaseName + ''''
     else CreateSQL := CreateSQL + '''' + DatabaseName + '''';
+  if UserName <> '' then
+    CreateSQL := CreateSQL + ' USER ''' + Username + '''';
+  if Password <> '' then
+    CreateSQL := CreateSQL + ' PASSWORD ''' + Password + '''';
+  pagesize := params.Values['PAGE_SIZE'];
+  if pagesize <> '' then
+    CreateSQL := CreateSQL + ' PAGE_SIZE '+pagesize;
 
   if isc_dsql_execute_immediate(@FStatus[0],@ASQLDatabaseHandle,@ASQLTransactionHandle,length(CreateSQL),@CreateSQL[1],Dialect,nil) <> 0 then
     CheckError('CreateDB', FStatus);

+ 18 - 3
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

@@ -493,8 +493,18 @@ begin
       end;
     FIELD_TYPE_VAR_STRING, FIELD_TYPE_STRING, FIELD_TYPE_ENUM, FIELD_TYPE_SET:
       begin
-      NewType := ftString;
-      NewSize := ASize;
+      // Since mysql server version 5.0.3 string-fields with a length of more
+      // then 256 characters are suported
+      if ASize>dsMaxStringSize then
+        begin
+        NewType := ftMemo;
+        NewSize := 0;
+        end
+      else
+        begin
+        NewType := ftString;
+        NewSize := ASize;
+        end;
       end;
     FIELD_TYPE_BLOB:
       begin
@@ -816,7 +826,12 @@ begin
           inc(p);
           end;
       Writeln;
-}      if Src<> '' then
+}
+      // String-fields which can contain more then dsMaxStringSize characters
+      // are mapped to ftBlob fields, while their mysql-datatype is FIELD_TYPE_BLOB
+      if AFieldType in [ftBlob,ftMemo] then
+        CreateBlob := True
+      else if Src<> '' then
         Move(Source^, Dest^, ASize)
       else
         Dest^ := #0;

+ 23 - 2
packages/fcl-db/src/sqldb/postgres/pqconnection.pp

@@ -124,7 +124,7 @@ constructor TPQConnection.Create(AOwner : TComponent);
 
 begin
   inherited;
-  FConnOptions := FConnOptions + [sqSupportParams] + [sqEscapeRepeat] + [sqEscapeSlash];
+  FConnOptions := FConnOptions + [sqSupportParams] + [sqEscapeRepeat] + [sqEscapeSlash] + [sqQuoteFieldnames];
 end;
 
 procedure TPQConnection.CreateDB;
@@ -458,7 +458,7 @@ const TypeStrings : array[TFieldType] of string =
       'Unknown',
       'Unknown',
       'Unknown',
-      'Unknown',
+      'text',
       'Unknown',
       'Unknown',
       'Unknown',
@@ -851,6 +851,27 @@ begin
                         'where '+
                           'relkind=''r''' +
                         'order by relname';
+    stColumns    : s := 'select '+
+                          'a.attnum                 as recno, '+
+                          '''''                     as catalog_name, '+
+                          '''''                     as schema_name, '+
+                          'c.relname                as table_name, '+
+                          'a.attname                as column_name, '+
+                          '0                        as column_position, '+
+                          '0                        as column_type, '+
+                          '0                        as column_datatype, '+
+                          '''''                     as column_typename, '+
+                          '0                        as column_subtype, '+
+                          '0                        as column_precision, '+
+                          '0                        as column_scale, '+
+                          'a.atttypmod              as column_length, '+
+                          'not a.attnotnull         as column_nullable '+
+                        'from '+
+                          ' pg_class c, pg_attribute a '+
+                        'WHERE '+
+                        // This can lead to problems when case-sensitive tablenames are used.
+                          '(c.oid=a.attrelid) and (a.attnum>0) and (not a.attisdropped) and (upper(c.relname)=''' + Uppercase(SchemaObjectName) + ''') ' +
+                        'order by a.attname';
   else
     DatabaseError(SMetadataUnavailable)
   end; {case}

+ 42 - 25
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -94,6 +94,7 @@ implementation
 
 procedure TSQLDBConnector.CreateFConnection;
 var i : TSQLDBTypes;
+    t : integer;
 begin
   for i := low(DBTypesNames) to high(DBTypesNames) do
     if UpperCase(dbconnectorparams) = DBTypesNames[i] then sqldbtype := i;
@@ -102,6 +103,13 @@ begin
     
   if SQLDbType = MYSQL40 then Fconnection := tMySQL40Connection.Create(nil);
   if SQLDbType = MYSQL41 then Fconnection := tMySQL41Connection.Create(nil);
+  if SQLDbType in [mysql40,mysql41] then
+    begin
+    // Mysql versions prior to 5.0.3 removes the trailing spaces on varchar
+    // fields on insertion. So to test properly, we have to do the same
+    for t := 0 to testValuesCount-1 do
+      testStringValues[t] := TrimRight(testStringValues[t]);
+    end;
   if SQLDbType = MYSQL50 then Fconnection := tMySQL50Connection.Create(nil);
   if SQLDbType in MySQLdbTypes then
     FieldtypeDefinitions[ftLargeint] := 'BIGINT';
@@ -209,7 +217,7 @@ begin
           begin
           sql := sql + ',F' + Fieldtypenames[FType];
           if testValues[FType,CountID] <> '' then
-            sql1 := sql1 + ',''' + testValues[FType,CountID] + ''''
+            sql1 := sql1 + ',''' + StringReplace(testValues[FType,CountID],'''','''''',[rfReplaceAll]) + ''''
           else
             sql1 := sql1 + ',NULL';
           end;
@@ -227,26 +235,32 @@ end;
 
 procedure TSQLDBConnector.DropNDatasets;
 begin
-  try
-    if Ftransaction.Active then Ftransaction.Rollback;
-    Ftransaction.StartTransaction;
-    Fconnection.ExecuteDirect('DROP TABLE FPDEV');
-    Ftransaction.Commit;
-  Except
-    if Ftransaction.Active then Ftransaction.Rollback
-  end;
+  if assigned(FTransaction) then
+    begin
+    try
+      if Ftransaction.Active then Ftransaction.Rollback;
+      Ftransaction.StartTransaction;
+      Fconnection.ExecuteDirect('DROP TABLE FPDEV');
+      Ftransaction.Commit;
+    Except
+      if Ftransaction.Active then Ftransaction.Rollback
+    end;
+    end;
 end;
 
 procedure TSQLDBConnector.DropFieldDataset;
 begin
-  try
-    if Ftransaction.Active then Ftransaction.Rollback;
-    Ftransaction.StartTransaction;
-    Fconnection.ExecuteDirect('DROP TABLE FPDEV_FIELD');
-    Ftransaction.Commit;
-  Except
-    if Ftransaction.Active then Ftransaction.Rollback
-  end;
+  if assigned(FTransaction) then
+    begin
+    try
+      if Ftransaction.Active then Ftransaction.Rollback;
+      Ftransaction.StartTransaction;
+      Fconnection.ExecuteDirect('DROP TABLE FPDEV_FIELD');
+      Ftransaction.Commit;
+    Except
+      if Ftransaction.Active then Ftransaction.Rollback
+    end;
+    end;
 end;
 
 function TSQLDBConnector.InternalGetNDataset(n: integer): TDataset;
@@ -271,14 +285,17 @@ end;
 
 destructor TSQLDBConnector.Destroy;
 begin
-  try
-    if Ftransaction.Active then Ftransaction.Rollback;
-    Ftransaction.StartTransaction;
-    Fconnection.ExecuteDirect('DROP TABLE FPDEV2');
-    Ftransaction.Commit;
-  Except
-    if Ftransaction.Active then Ftransaction.Rollback
-  end;
+  if assigned(FTransaction) then
+    begin
+    try
+      if Ftransaction.Active then Ftransaction.Rollback;
+      Ftransaction.StartTransaction;
+      Fconnection.ExecuteDirect('DROP TABLE FPDEV2');
+      Ftransaction.Commit;
+    Except
+      if Ftransaction.Active then Ftransaction.Rollback
+    end; // try
+    end;
   inherited Destroy;
 
   FreeAndNil(FQuery);

+ 37 - 33
packages/fcl-db/tests/testdbbasics.pas

@@ -905,6 +905,7 @@ procedure TTestDBBasics.TestAddIndexFieldType(AFieldType: TFieldType; ActiveDS :
 var ds : TBufDataset;
     FList : TStringList;
     LastValue : Variant;
+    StrValue : String;
 begin
   ds := DBConnector.GetFieldDataset as TBufDataset;
   with ds do
@@ -939,14 +940,20 @@ begin
     LastValue:=null;
     while not eof do
       begin
-      AssertTrue(LastValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
+      if AFieldType=ftString then
+        AssertTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))<=0)
+      else
+        AssertTrue(LastValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
       LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
       Next;
       end;
 
     while not bof do
       begin
-      AssertTrue(LastValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
+      if AFieldType=ftString then
+        AssertTrue(AnsiCompareStr(VarToStr(LastValue),VarToStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString))>=0)
+      else
+        AssertTrue(LastValue>=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant);
       LastValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsVariant;
       Prior;
       end;
@@ -1187,7 +1194,7 @@ begin
     LastValue:=FieldByName('name').AsString;
     while not eof do
       begin
-      AssertTrue(LastValue<=FieldByName('name').AsString);
+      AssertTrue(AnsiCompareStr(LastValue,FieldByName('name').AsString)<=0);
       Next;
       end;
     end;
@@ -1314,48 +1321,45 @@ end;
 
 procedure TTestDBBasics.TestAddDblIndex;
 var ds : TBufDataset;
-    FList : TStringList;
-    i : integer;
+    LastInteger : Integer;
+    LastString : string;
 begin
   ds := DBConnector.GetFieldDataset as TBufDataset;
   with ds do
     begin
 
     AddIndex('testindex','F'+FieldTypeNames[ftString]+';F'+FieldTypeNames[ftInteger],[]);
-    FList := TStringList.Create;
-    FList.Sorted:=true;
-    FList.CaseSensitive:=True;
-    FList.Duplicates:=dupAccept;
     open;
 
-    while not eof do
-      begin
-      // If the first field of the index is null then the compound string in
-      // FList isn't sorted right...
-      if FieldByName('F'+FieldTypeNames[ftString]).IsNull then
-        flist.Add('         -'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]))
-      else
-        flist.Add(FieldByName('F'+FieldTypeNames[ftString]).AsString+'-'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]));
-      Next;
-      end;
-
     IndexName:='testindex';
     first;
-    i:=0;
 
+    LastString:='';
     while not eof do
       begin
-      if (not FieldByName('F'+FieldTypeNames[ftString]).IsNull) then
-        AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[ftString]).AsString+'-'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]));
-      inc(i);
-      Next;
+      AssertTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[ftString]).AsString,LastString)>=0);
+      LastString:= FieldByName('F'+FieldTypeNames[ftString]).AsString;
+
+      LastInteger:=-MaxInt;
+      while (FieldByName('F'+FieldTypeNames[ftString]).AsString=LastString) and not eof do
+        begin
+        AssertTrue(FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger>=LastInteger);
+        LastInteger:=FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger;
+        next;
+        end;
       end;
     while not bof do
       begin
-      dec(i);
-      if not FieldByName('F'+FieldTypeNames[ftString]).IsNull then
-        AssertEquals(flist[i],FieldByName('F'+FieldTypeNames[ftString]).AsString+'-'+ Format('%.12d',[FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger]));
-      Prior;
+      AssertTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[ftString]).AsString,LastString)<=0);
+      LastString:= FieldByName('F'+FieldTypeNames[ftString]).AsString;
+
+      LastInteger:=+MaxInt;
+      while (FieldByName('F'+FieldTypeNames[ftString]).AsString=LastString) and not bof do
+        begin
+        AssertTrue(FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger<=LastInteger);
+        LastInteger:=FieldByName('F'+FieldTypeNames[ftInteger]).AsInteger;
+        prior;
+        end;
       end;
     end;
 end;
@@ -1379,17 +1383,17 @@ begin
     AssertTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
     OldStringValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
     next;
-    AssertTrue(OldStringValue<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
+    AssertTrue(AnsiCompareStr(OldStringValue,FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0);
     prior;
     
     edit;
     FieldByName('F'+FieldTypeNames[AfieldType]).AsString := 'ZZZ';
     post;
     prior;
-    AssertTrue('ZZZ'>=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
+    AssertTrue(AnsiCompareStr('ZZZ',FieldByName('F'+FieldTypeNames[AfieldType]).AsString)>=0);
     next;
     next;
-    AssertTrue('ZZZ'<=FieldByName('F'+FieldTypeNames[AfieldType]).AsString);
+    AssertTrue(AnsiCompareStr('ZZZ',FieldByName('F'+FieldTypeNames[AfieldType]).AsString)<=0);
     close;
     end;
 end;
@@ -1410,7 +1414,7 @@ begin
     PrevValue:='';
     while not eof do
       begin
-      AssertTrue(FieldByName('F'+FieldTypeNames[AfieldType]).AsString>=PrevValue);
+      AssertTrue(AnsiCompareStr(FieldByName('F'+FieldTypeNames[AfieldType]).AsString,PrevValue)>=0);
       PrevValue:=FieldByName('F'+FieldTypeNames[AfieldType]).AsString;
       Next;
       end;

+ 24 - 38
packages/fcl-db/tests/testfieldtypes.pas

@@ -88,30 +88,6 @@ const
   testIntValuesCount = 17;
   testIntValues : Array[0..testIntValuesCount-1] of integer = (-maxInt,-maxSmallint-1,-maxSmallint,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint+1,MaxInt);
 
-  testStringValuesCount = 20;
-  testStringValues : Array[0..testStringValuesCount-1] of string = (
-    '',
-    'a',
-    'ab',
-    'abc',
-    'abcd',
-    'abcde',
-    'abcdef',
-    'abcdefg',
-    'abcdefgh',
-    'abcdefghi',
-    'abcdefghij',
-    'lMnOpQrStU',
-    '1234567890',
-    '_!@#$%^&*(',
-    ' ''quotes'' ',
-    ')-;:/?.<>',
-    '~`|{}- =',    // note that there's no \  (backslash) since some db's uses that as escape-character
-    '  WRaP  ',
-    'wRaP  ',
-    ' wRAP'
-  );
-
   testDateValuesCount = 18;
   testDateValues : Array[0..testDateValuesCount-1] of string = (
     '2000-01-01',
@@ -179,15 +155,25 @@ var Ascript : TSQLScript;
 
 begin
   Ascript := tsqlscript.create(nil);
-  with Ascript do
-    begin
-    DataBase := TSQLDBConnector(DBConnector).Connection;
-    transaction := TSQLDBConnector(DBConnector).Transaction;
-    script.clear;
-    script.append('create table a (id int);');
-    script.append('create table b (id int);');
-    ExecuteScript;
-    end;
+  try
+    with Ascript do
+      begin
+      DataBase := TSQLDBConnector(DBConnector).Connection;
+      transaction := TSQLDBConnector(DBConnector).Transaction;
+      script.clear;
+      script.append('create table a (id int);');
+      script.append('create table b (id int);');
+      ExecuteScript;
+      // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
+      if SQLDbType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining;
+
+      end;
+  finally
+    TSQLDBConnector(DBConnector).Connection.ExecuteDirect('drop table a');
+    TSQLDBConnector(DBConnector).Connection.ExecuteDirect('drop table b');
+    // Firebird/Interbase need a commit after a DDL statement. Not necessary for the other connections
+    if SQLDbType=interbase then TSQLDBConnector(DBConnector).Transaction.CommitRetaining;
+  end;
 end;
 
 procedure TTestFieldTypes.TestInt;
@@ -311,8 +297,8 @@ begin
     Open;
     for i := 0 to testValuesCount-1 do
       begin
-      if (SQLDbType in MySQLdbTypes) then
-        AssertEquals(TrimRight(testValues[i]),fields[0].AsString) // MySQL automatically trims strings
+      if (SQLDbType in [mysql40,mysql41]) then
+        AssertEquals(TrimRight(testValues[i]),fields[0].AsString) // MySQL < 5.0.3 automatically trims strings
       else
         AssertEquals(testValues[i],fields[0].AsString);
       Next;
@@ -708,7 +694,7 @@ end;
 procedure TTestFieldTypes.TestStringParamQuery;
 
 begin
-  TestXXParamQuery(ftString,'VARCHAR(10)',testStringValuesCount);
+  TestXXParamQuery(ftString,'VARCHAR(10)',testValuesCount);
 end;
 
 procedure TTestFieldTypes.TestDateParamQuery;
@@ -913,7 +899,7 @@ begin
     begin
     with query do
       begin
-      SQL.Text:='select TT.NAME from FPDEV left join FPDEV as TT on TT.ID=FPDEV.ID';
+      SQL.Text:='select TT.NAME from FPDEV left join FPDEV TT on TT.ID=FPDEV.ID';
       Open;
       close;
       end;
@@ -946,7 +932,7 @@ procedure TTestFieldTypes.TestNumericNames;
 begin
   with TSQLDBConnector(DBConnector) do
     begin
-    if sqQuoteFieldnames in Connection.ConnOptions then
+    if not (SQLDbType in MySQLdbTypes) then
       Connection.ExecuteDirect('create table FPDEV2 (         ' +
                                 '  "2ID" INT NOT NULL            , ' +
                                 '  "3TEST" VARCHAR(10),     ' +

+ 4 - 4
packages/fcl-db/tests/toolsunit.pas

@@ -86,7 +86,7 @@ const
   testCurrencyValues : Array[0..testValuesCount-1] of currency = (-100,-65.5,-54.34,-43.34,-2.50,-0.2,45.40,0.3,45.4,127,128,255,256,45,0.3,45.4,127,128,255,256,45,1234.56,43.23,43.43,99.88);
   testIntValues : Array[0..testValuesCount-1] of integer = (-maxInt,-maxInt+1,-maxSmallint-1,-maxSmallint,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint+1,MaxInt-1,MaxInt,100,130,150,-150,-132,234);
   testSmallIntValues : Array[0..testValuesCount-1] of smallint = (-maxSmallint,-maxSmallint+1,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint-1,100,110,120,130,150,-150,-132,234,231,42);
-  testLargeIntValues : Array[0..testValuesCount-1] of LargeInt = (-MaxSIntValue,-MaxSIntValue+1,-maxInt-1,-maxInt+1,-maxSmallint,-maxSmallint+1,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint-1,maxSmallint+1,MaxInt-1,MaxInt,MaxSIntValue-1,MaxSIntValue,235253244);
+  testLargeIntValues : Array[0..testValuesCount-1] of LargeInt = ( -$7fffffffffffffff,-$7ffffffffffffffe,-maxInt-1,-maxInt+1,-maxSmallint,-maxSmallint+1,-256,-255,-128,-127,-1,0,1,127,128,255,256,maxSmallint,maxSmallint-1,maxSmallint+1,MaxInt-1,MaxInt,$7fffffffffffffff-1,$7fffffffffffffff,235253244);
   testBooleanValues : Array[0..testValuesCount-1] of boolean = (true,false,false,true,true,false,false,true,false,true,true,true,false,false,false,false,true,true,true,true,false,true,true,false,false);
   testStringValues : Array[0..testValuesCount-1] of string = (
     '',
@@ -104,14 +104,14 @@ const
     '1234567890',
     '_!@#$%^&*(',
     '_!@#$%^&*(',
-//    ' ''quotes'' ',
+    ' ''quotes'' ',
     ')-;:/?.<>',
     '~`|{}- =',    // note that there's no \  (backslash) since some db's uses that as escape-character
     '  WRaP  ',
     'wRaP  ',
     ' wRAP',
     'this',
-    'is',
+//    'is',
     'fun',
     'VB7^',
     'vdfbst'
@@ -176,7 +176,7 @@ end;
 
 destructor TDBConnector.destroy;
 begin
-  FUsedDatasets.Destroy;
+  if assigned(FUsedDatasets) then FUsedDatasets.Destroy;
   DropNDatasets;
   DropFieldDataset;
 end;