Browse Source

* improve mapping of db type char to relative new ftfixedchar fieldtype. + tests. Mantis #20483, patch by Lacak2

git-svn-id: trunk@19489 -
marco 14 years ago
parent
commit
91f8ee8b89

+ 12 - 2
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

@@ -330,7 +330,7 @@ var esc_str : pchar;
 
 
 begin
 begin
   if (not assigned(param)) or param.IsNull then Result := 'Null'
   if (not assigned(param)) or param.IsNull then Result := 'Null'
-  else if param.DataType in [ftString,ftFixedChar,ftBlob,ftMemo] then
+  else if param.DataType in [ftString,ftFixedChar,ftBlob,ftMemo,ftBytes,ftVarBytes] then
     Result := '''' + EscapeString(Param.AsString) + ''''
     Result := '''' + EscapeString(Param.AsString) + ''''
   else Result := inherited GetAsSqlText(Param);
   else Result := inherited GetAsSqlText(Param);
 end;
 end;
@@ -615,7 +615,17 @@ begin
         end
         end
       else
       else
         begin
         begin
-        NewType := ftString;
+        if AField^.ftype = FIELD_TYPE_STRING then
+          NewType := ftFixedChar
+        else
+          NewType := ftString;
+{$IFDEF MYSQL50_UP}
+        if AField^.charsetnr = 63 then //BINARY vs. CHAR, VARBINARY vs. VARCHAR
+          if NewType = ftFixedChar then
+            NewType := ftBytes
+          else
+            NewType := ftVarBytes;
+{$ENDIF}
         NewSize := ASize;
         NewSize := ASize;
         end;
         end;
       end;
       end;

+ 1 - 1
packages/fcl-db/src/sqldb/sqlite/sqlite3conn.pp

@@ -368,7 +368,7 @@ Const
    (n:'TIME'; t: ftTime),
    (n:'TIME'; t: ftTime),
    (n:'CURRENCY'; t: ftCurrency),
    (n:'CURRENCY'; t: ftCurrency),
    (n:'VARCHAR'; t: ftString),
    (n:'VARCHAR'; t: ftString),
-   (n:'CHAR'; t: ftString),
+   (n:'CHAR'; t: ftFixedChar),
    (n:'NUMERIC'; t: ftBCD),
    (n:'NUMERIC'; t: ftBCD),
    (n:'DECIMAL'; t: ftBCD),
    (n:'DECIMAL'; t: ftBCD),
    (n:'TEXT'; t: ftmemo),
    (n:'TEXT'; t: ftmemo),

+ 11 - 2
packages/fcl-db/tests/sqldbtoolsunit.pas

@@ -94,6 +94,8 @@ var SQLDbType : TSQLDBTypes;
     
     
 implementation
 implementation
 
 
+uses StrUtils;
+
 { TSQLDBConnector }
 { TSQLDBConnector }
 
 
 procedure TSQLDBConnector.CreateFConnection;
 procedure TSQLDBConnector.CreateFConnection;
@@ -131,7 +133,6 @@ begin
     Fconnection := TSQLite3Connection.Create(nil);
     Fconnection := TSQLite3Connection.Create(nil);
     FieldtypeDefinitions[ftCurrency] := 'CURRENCY';
     FieldtypeDefinitions[ftCurrency] := 'CURRENCY';
     FieldtypeDefinitions[ftMemo] := 'CLOB'; //or TEXT SQLite supports both, but CLOB is sql standard (TEXT not)
     FieldtypeDefinitions[ftMemo] := 'CLOB'; //or TEXT SQLite supports both, but CLOB is sql standard (TEXT not)
-    FieldtypeDefinitions[ftFixedChar] := '';
     end;
     end;
   if SQLDbType = POSTGRESQL then
   if SQLDbType = POSTGRESQL then
     begin
     begin
@@ -174,9 +175,17 @@ begin
       testValues[ftTime,2]:='23:00:00.000';
       testValues[ftTime,2]:='23:00:00.000';
       end;
       end;
     end;
     end;
+
   if SQLDbType in [sqlite3] then
   if SQLDbType in [sqlite3] then
     testValues[ftCurrency]:=testValues[ftBCD]; //decimal separator for currencies must be decimal point
     testValues[ftCurrency]:=testValues[ftBCD]; //decimal separator for currencies must be decimal point
 
 
+  // SQLite does not support fixed length CHAR datatype
+  // MySQL by default trimms trailing spaces on retrieval; so set sql-mode="PAD_CHAR_TO_FULL_LENGTH" - supported from MySQL 5.1.20
+  if SQLDbType in [sqlite3] then
+    for t := 0 to testValuesCount-1 do
+      testValues[ftFixedChar,t] := PadRight(testValues[ftFixedChar,t], 10);
+
+
   if not assigned(Fconnection) then writeln('Invalid database-type, check if a valid database-type was provided in the file ''database.ini''');
   if not assigned(Fconnection) then writeln('Invalid database-type, check if a valid database-type was provided in the file ''database.ini''');
 
 
   with Fconnection do
   with Fconnection do
@@ -190,7 +199,7 @@ begin
       FieldNameQuoteChars[0] := dbQuoteChars[1];
       FieldNameQuoteChars[0] := dbQuoteChars[1];
       FieldNameQuoteChars[1] := dbQuoteChars[2];
       FieldNameQuoteChars[1] := dbQuoteChars[2];
       end;
       end;
-    open;
+    Open;
     end;
     end;
 end;
 end;
 
 

+ 1 - 1
packages/fcl-db/tests/testfieldtypes.pas

@@ -839,7 +839,7 @@ begin
         ftFloat  : Params.ParamByName('field1').AsFloat   := testFloatValues[i];
         ftFloat  : Params.ParamByName('field1').AsFloat   := testFloatValues[i];
         ftBCD    : Params.ParamByName('field1').AsCurrency:= testBCDValues[i];
         ftBCD    : Params.ParamByName('field1').AsCurrency:= testBCDValues[i];
         ftFixedChar,
         ftFixedChar,
-        ftString : Params.ParamByName('field1').AsString  := testStringValues[i];
+        ftString : Params.ParamByName('field1').AsString  := testValues[ADataType,i];
         ftTime   : Params.ParamByName('field1').AsTime  := TimeStringToDateTime(testTimeValues[i]);
         ftTime   : Params.ParamByName('field1').AsTime  := TimeStringToDateTime(testTimeValues[i]);
         ftDate   : if cross then
         ftDate   : if cross then
                      Params.ParamByName('field1').AsString:= testDateValues[i]
                      Params.ParamByName('field1').AsString:= testDateValues[i]