Browse Source

* Removed the limit of 8192 characters on stringfields + test

git-svn-id: trunk@13411 -
joost 16 years ago
parent
commit
2762ed5fba
2 changed files with 54 additions and 9 deletions
  1. 29 9
      packages/fcl-db/src/base/fields.inc
  2. 25 0
      packages/fcl-db/tests/testfieldtypes.pas

+ 29 - 9
packages/fcl-db/src/base/fields.inc

@@ -1018,7 +1018,7 @@ begin
 // A size of 0 is allowed, since for example Firebird allows
 // a query like: 'select '' as fieldname from table' which
 // results in a string with size 0.
-  If (AValue<0) or (AValue>dsMaxStringSize) Then
+  If (AValue<0) Then
     databaseErrorFmt(SInvalidFieldSize,[AValue])
 end;
 
@@ -1092,19 +1092,39 @@ end;
 function TStringField.GetValue(var AValue: string): Boolean;
 
 Var Buf, TBuf : TStringFieldBuffer;
+    DynBuf, TDynBuf : Array of char;
 
 begin
-  Result:=GetData(@Buf);
-  If Result then
+  if DataSize <= dsMaxStringSize then
     begin
-    if transliterate then
+    Result:=GetData(@Buf);
+    If Result then
       begin
-      DataSet.Translate(Buf,TBuf,False);
-      AValue:=TBuf;
+      if transliterate then
+        begin
+        DataSet.Translate(Buf,TBuf,False);
+        AValue:=TBuf;
+        end
+      else
+        AValue:=Buf
       end
-    else
-      AValue:=Buf
     end
+  else
+    begin
+    SetLength(DynBuf,DataSize);
+    Result:=GetData(@DynBuf[0]);
+    If Result then
+      begin
+      if transliterate then
+        begin
+        SetLength(TDynBuf,DataSize);
+        DataSet.Translate(@DynBuf[0],@TDynBuf[0],False);
+        AValue:=pchar(TDynBuf);
+        end
+      else
+        AValue:=pchar(DynBuf);
+      end
+    end;
 end;
 
 procedure TStringField.SetAsBoolean(AValue: Boolean);
@@ -1175,7 +1195,7 @@ begin
 // A size of 0 is allowed, since for example Firebird allows
 // a query like: 'select '' as fieldname from table' which
 // results in a string with size 0.
-  If (AValue<0) or (AValue>(dsMaxStringSize div 2)) Then
+  If (AValue<0) Then
     databaseErrorFmt(SInvalidFieldSize,[AValue]);
 end;
 

+ 25 - 0
packages/fcl-db/tests/testfieldtypes.pas

@@ -84,6 +84,8 @@ type
     procedure TestBCDParamQuery;
     procedure TestAggregates;
 
+    procedure TestStringLargerThen8192;
+
     // SchemaType tests
     procedure TestTableNames;
     procedure TestFieldNames;
@@ -927,6 +929,29 @@ begin
   TSQLDBConnector(DBConnector).Connection.ExecuteDirect('update fpdev set name=''nothing'' where (1=0)');
 end;
 
+procedure TTestFieldTypes.TestStringLargerThen8192;
+
+var
+  s             : string;
+  i             : integer;
+
+begin
+  CreateTableWithFieldType(ftString,'VARCHAR(9000)');
+  TestFieldDeclaration(ftString,9001);
+
+  setlength(s,9000);
+  for i := 1 to 9000 do
+    s[i]:=chr((i mod 10)+ord('a'));
+  TSQLDBConnector(DBConnector).Connection.ExecuteDirect('insert into FPDEV2 (FT) values (''' + s + ''')');
+
+  with TSQLDBConnector(DBConnector).Query do
+    begin
+    Open;
+    AssertEquals(s,fields[0].AsString);
+    close;
+    end;
+end;
+
 procedure TTestFieldTypes.TestTableNames;
 var TableList : TStringList;
     i         : integer;