Browse Source

* Always reset FUpdateable when calling the SQLParser (+test)

git-svn-id: trunk@9878 -
joost 17 years ago
parent
commit
ce9b080854
2 changed files with 25 additions and 4 deletions
  1. 4 4
      packages/fcl-db/src/sqldb/sqldb.pp
  2. 21 0
      packages/fcl-db/tests/testsqlfieldtypes.pas

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

@@ -997,6 +997,7 @@ begin
   FWhereStopPos := 0;
   
   ConnOptions := TSQLConnection(DataBase).ConnOptions;
+  FUpdateable := False;
 
   repeat
     begin
@@ -1074,10 +1075,9 @@ begin
                          Setlength(FFromPart,StrLength);
                          Move(PStatementPart^,FFromPart[1],(StrLength));
                          FFrompart := trim(FFrompart);
-                       
-                         if ExtractStrings([',',' '],[],pchar(FFromPart),nil) > 1 then
-                           FUpdateable := False // select-statements from more then one table are not updateable
-                         else
+
+                         // select-statements from more then one table are not updateable
+                         if ExtractStrings([',',' '],[],pchar(FFromPart),nil) = 1 then
                            begin
                            FUpdateable := True;
                            FTableName := FFromPart;

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

@@ -26,6 +26,7 @@ type
     procedure TearDown; override;
     procedure RunTest; override;
   published
+    procedure TestClearUpdateableStatus;
     procedure TestParseJoins; // bug 10148
     procedure TestInsertLargeStrFields; // bug 9600
     procedure TestNumericNames; // Bug9661
@@ -876,6 +877,26 @@ begin
     inherited RunTest;
 end;
 
+procedure TTestFieldTypes.TestClearUpdateableStatus;
+// Test if CanModify is correctly disabled in case of a select query without
+// a from-statement.
+begin
+  if not (SQLDbType in MySQLdbTypes) then Ignore('This test does only apply to MySQL because the used SQL-statement is MySQL only.');
+  with TSQLDBConnector(DBConnector) do
+    begin
+    with (GetNDataset(false,5) as TSQLQuery) do
+      begin
+      Open;
+      AssertEquals(True,CanModify);
+      Close;
+      SQL.Text:='select last_insert_id();';
+      Open;
+      AssertEquals(False,CanModify);
+      close;
+      end;
+    end;
+end;
+
 procedure TTestFieldTypes.TestParseJoins;
 begin
   with TSQLDBConnector(DBConnector) do