فهرست منبع

Merged revisions 9245,9250,9254 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r9245 | joost | 2007-11-13 22:24:18 +0100 (Tue, 13 Nov 2007) | 1 line

* Patch from Luiz Americo to fix TField.Size issues
........
r9250 | joost | 2007-11-14 19:33:40 +0100 (Wed, 14 Nov 2007) | 1 line

* Patch from Luiz Americo to set TStringField.Size:=dsMaxStringSize
........
r9254 | joost | 2007-11-14 23:08:01 +0100 (Wed, 14 Nov 2007) | 1 line

* Not only a comma is a seperator in the from-clause of a query. Fixes bug #10148 (+test)
........

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

joost 17 سال پیش
والد
کامیت
12f33d825b

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

@@ -1072,7 +1072,7 @@ begin
                          Move(PStatementPart^,FFromPart[1],(StrLength));
                          FFrompart := trim(FFrompart);
                        
-                         if pos(',',FFromPart) > 0 then
+                         if ExtractStrings([',',' '],[],pchar(FFromPart),nil) > 1 then
                            FUpdateable := False // select-statements from more then one table are not updateable
                          else
                            begin

+ 23 - 33
packages/fcl-db/src/sqlite/sqlite3ds.pas

@@ -103,7 +103,7 @@ procedure TSqlite3Dataset.InternalInitFieldDefs;
 var
   vm:Pointer;
   ColumnStr:String;
-  i,ColumnCount,FieldSize:Integer;
+  i,ColumnCount:Integer;
   AType:TFieldType;
 begin
   {$ifdef DEBUG}
@@ -118,71 +118,61 @@ begin
   FRowBufferSize:=(SizeOf(PPChar)*ColumnCount);
   //Prepare the array of pchar2sql functions
   SetLength(FGetSqlStr,ColumnCount);
-  for i:= 0 to ColumnCount - 1 do
+  for i := 0 to ColumnCount - 1 do
   begin
-   ColumnStr:= UpperCase(StrPas(sqlite3_column_decltype(vm,i)));
+   ColumnStr := UpperCase(StrPas(sqlite3_column_decltype(vm,i)));
    if (ColumnStr = 'INTEGER') or (ColumnStr = 'INT') then
    begin
      if AutoIncrementKey and (UpperCase(StrPas(sqlite3_column_name(vm,i))) = UpperCase(PrimaryKey)) then
      begin
-       AType:= ftAutoInc;
-       FAutoIncFieldNo:=i;
+       AType := ftAutoInc;
+       FAutoIncFieldNo := i;
      end
      else
-       AType:= ftInteger;
-     FieldSize:=SizeOf(LongInt);
+       AType := ftInteger;     
    end else if Pos('VARCHAR',ColumnStr) = 1 then
    begin
-     AType:= ftString;
-     FieldSize:=0;
+     AType := ftString;
    end else if Pos('BOOL',ColumnStr) = 1 then
    begin
-     AType:= ftBoolean;
-     FieldSize:=SizeOf(WordBool);
+     AType := ftBoolean;
    end else if Pos('AUTOINC',ColumnStr) = 1 then
    begin
-     AType:= ftAutoInc;
-     FieldSize:=SizeOf(LongInt);
+     AType := ftAutoInc;
      if FAutoIncFieldNo = -1 then
-       FAutoIncFieldNo:= i;
+       FAutoIncFieldNo := i;
    end else if (Pos('FLOAT',ColumnStr)=1) or (Pos('NUMERIC',ColumnStr)=1) then
    begin
-     AType:= ftFloat;
-     FieldSize:=SizeOf(Double);
+     AType := ftFloat;
    end else if (ColumnStr = 'DATETIME') then
    begin
-     AType:= ftDateTime;
-     FieldSize:=SizeOf(TDateTime);
+     AType := ftDateTime;
    end else if (ColumnStr = 'DATE') then
    begin
-     AType:= ftDate;
-     FieldSize:=SizeOf(TDateTime);
+     AType := ftDate;
    end else if (ColumnStr = 'LARGEINT') then
    begin
-     AType:= ftLargeInt;
-     FieldSize:=SizeOf(Int64);
+     AType := ftLargeInt;
    end else if (ColumnStr = 'TIME') then
    begin
-     AType:= ftTime;
-     FieldSize:=SizeOf(TDateTime);
+     AType := ftTime;
    end else if (ColumnStr = 'TEXT') then
    begin
-     AType:= ftMemo;
-     FieldSize:=0;
+     AType := ftMemo;
    end else if (ColumnStr = 'CURRENCY') then
    begin
-     AType:= ftCurrency;
-     FieldSize:=SizeOf(Double);
+     AType := ftCurrency;
    end else if (ColumnStr = 'WORD') then
    begin
-     AType:= ftWord;
-     FieldSize:=SizeOf(Word);
+     AType := ftWord;
    end else
    begin
-     AType:= ftString;
-     FieldSize:=0;
+     AType := ftString;
    end;
-   FieldDefs.Add(StrPas(sqlite3_column_name(vm,i)), AType, FieldSize, False);
+   if AType = ftString then
+     FieldDefs.Add(StrPas(sqlite3_column_name(vm,i)), AType, dsMaxStringSize)
+   else
+     FieldDefs.Add(StrPas(sqlite3_column_name(vm,i)), AType);  
    //Set the pchar2sql function
    if AType in [ftString,ftMemo] then
      FGetSqlStr[i]:=@Char2SqlStr

+ 24 - 35
packages/fcl-db/src/sqlite/sqliteds.pas

@@ -104,14 +104,13 @@ end;
 procedure TSqliteDataset.InternalInitFieldDefs;
 var
   ColumnCount,i:Integer;
-  FieldSize:Word;
   AType:TFieldType;
   vm:Pointer;
   ColumnNames,ColumnValues:PPChar;
   ColumnStr:String;
 begin
   FieldDefs.Clear;
-  FAutoIncFieldNo:=-1;
+  FAutoIncFieldNo := -1;
   sqlite_compile(FSqliteHandle,PChar(FSql),nil,@vm,nil);
   sqlite_step(vm,@ColumnCount,@ColumnValues,@ColumnNames);
   //Prepare the array of pchar2sql functions
@@ -123,72 +122,62 @@ begin
   // exactly what is in Create Table statement
   // here is a trick to get the datatype.
   // If the field contains another type, may have problems
-  for i:= 0 to ColumnCount - 1 do
+  for i := 0 to ColumnCount - 1 do
   begin
-    ColumnStr:= UpperCase(StrPas(ColumnNames[i + ColumnCount]));
+    ColumnStr := UpperCase(StrPas(ColumnNames[i + ColumnCount]));
     if (ColumnStr = 'INTEGER') or (ColumnStr = 'INT') then
     begin
       if AutoIncrementKey and
            (UpperCase(StrPas(ColumnNames[i])) = UpperCase(PrimaryKey)) then
       begin
-        AType:= ftAutoInc;
-        FAutoIncFieldNo:=i;
+        AType := ftAutoInc;
+        FAutoIncFieldNo := i;
       end
       else
-        AType:= ftInteger;
-      FieldSize:=SizeOf(LongInt);
+        AType := ftInteger;
     end else if Pos('VARCHAR',ColumnStr) = 1 then
     begin
-      AType:= ftString;
-      FieldSize:=0;
+      AType := ftString;
     end else if Pos('BOOL',ColumnStr) = 1 then
     begin
-      AType:= ftBoolean;
-      FieldSize:=SizeOf(WordBool);
+      AType := ftBoolean;
     end else if Pos('AUTOINC',ColumnStr) = 1 then
     begin
-      AType:= ftAutoInc;
-      FieldSize:=SizeOf(LongInt);
+      AType := ftAutoInc;
       if FAutoIncFieldNo = -1 then
-        FAutoIncFieldNo:= i;
+        FAutoIncFieldNo := i;
     end else if (Pos('FLOAT',ColumnStr)=1) or (Pos('NUMERIC',ColumnStr)=1) then
     begin
-      AType:= ftFloat;
-      FieldSize:=SizeOf(Double);
+      AType := ftFloat;
     end else if (ColumnStr = 'DATETIME') then
     begin
-      AType:= ftDateTime;
-      FieldSize:=SizeOf(TDateTime);
+      AType := ftDateTime;
     end else if (ColumnStr = 'DATE') then
     begin
-      AType:= ftDate;
-      FieldSize:=SizeOf(TDateTime);
+      AType := ftDate;
     end else if (ColumnStr = 'TIME') then
     begin
-      AType:= ftTime;
-      FieldSize:=SizeOf(TDateTime);
+      AType := ftTime;
     end else if (ColumnStr = 'LARGEINT') then
     begin
-      AType:= ftLargeInt;
-      FieldSize:=SizeOf(LargeInt);
+      AType := ftLargeInt;
     end else if (ColumnStr = 'TEXT') then
     begin
-      AType:= ftMemo;
-      FieldSize:=0;
+      AType := ftMemo;
     end else if (ColumnStr = 'CURRENCY') then
     begin
-      AType:= ftCurrency;
-      FieldSize:=SizeOf(Double);
+      AType := ftCurrency;
     end else if (ColumnStr = 'WORD') then
     begin
-      AType:= ftWord;
-      FieldSize:=SizeOf(Word);
+      AType := ftWord;
     end else
     begin
-      AType:=ftString;
-      FieldSize:=0;
-    end;
-    FieldDefs.Add(StrPas(ColumnNames[i]), AType, FieldSize, False);
+      AType := ftString;
+    end;    
+    if AType = ftString then
+      FieldDefs.Add(StrPas(ColumnNames[i]), AType, dsMaxStringSize)
+    else
+      FieldDefs.Add(StrPas(ColumnNames[i]), AType);  
     //Set the pchar2sql function
     if AType in [ftString,ftMemo] then
       FGetSqlStr[i]:=@Char2SqlStr

+ 14 - 0
packages/fcl-db/tests/testsqlfieldtypes.pas

@@ -26,6 +26,7 @@ type
     procedure TearDown; override;
     procedure RunTest; override;
   published
+    procedure TestParseJoins; // bug 10148
     procedure TestInsertLargeStrFields; // bug 9600
     procedure TestNumericNames; // Bug9661
     procedure Test11Params;
@@ -875,6 +876,19 @@ begin
     inherited RunTest;
 end;
 
+procedure TTestFieldTypes.TestParseJoins;
+begin
+  with TSQLDBConnector(DBConnector) do
+    begin
+    with query do
+      begin
+      SQL.Text:='select TT.NAME from FPDEV left join FPDEV as TT on TT.ID=FPDEV.ID';
+      Open;
+      close;
+      end;
+    end;
+end;
+
 procedure TTestFieldTypes.TestInsertLargeStrFields;
 begin
   with TSQLDBConnector(DBConnector) do