View Issue Details

IDProjectCategoryView StatusLast Update
0032486FPCFCLpublic2017-09-29 10:11
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0032486: [patch] TSQLScript doesn't execute last statement not terminated by ';' (FTerminator)
Descriptionif I run this script with TSQLScript:

INSERT INTO A (ID) VALUES (1);
INSERT INTO A (ID) VALUES (2)

Only the first insert is executed. Not the second one - it's ignored because it lacks the terminating ';'. Furthermore, no exception is raised - so I even don't know about the last statement being ignored.
Steps To Reproduceprogram SQLScriptTest;

{$mode delphi}

uses
  SysUtils, sqldb, pqconnection;

var
  Conn: TPQConnection;
  Trans: TSQLTransaction;
  Script: TSQLScript;

begin
  Conn := TPQConnection.Create(nil);
  Conn.HostName := 'localhost';
  Conn.DatabaseName := 'fpctest';
  Conn.UserName := 'postgres';
  Conn.Password := '';
  Conn.Connected := True;
  Trans := TSQLTransaction.Create(Conn);
  Trans.DataBase := Conn;

  Script := TSQLScript.Create(Conn);
  Script.Script.Text :=
    'CREATE TABLE test (ID INTEGER)';

  Script.DataBase := Conn;
  Script.Transaction := Trans;

  Script.Execute;
  Trans.Commit;
  Conn.Free;
end.
Additional InformationI ran the test suite - no additional tests were broken:
test/cg/tcalext6
test/opt/tdfa11
test/opt/tdfa8
test/packages/zlib/tzlib1
test/tcpstr2a
test/timplements4a
test/timplements4b
test/tset6
test/tweaklib2
test/units/sharemem/test1
webtbs/tw11039a
webtbs/tw11039b
webtbs/tw22744
webtbs/tw22744b
webtbs/tw24863
webtbs/tw29353
webtbs/tw3930
webtbs/tw4809
webtbf/tw18225b
webtbf/tw3930a

Patch attached
TagsNo tags attached.
Fixed in Revision37355
FPCOldBugId
FPCTarget
Attached Files
  • sqlscript-terminator-01.patch (966 bytes)
    Index: packages/fcl-db/src/base/sqlscript.pp
    ===================================================================
    --- packages/fcl-db/src/base/sqlscript.pp	(revision 37292)
    +++ packages/fcl-db/src/base/sqlscript.pp	(working copy)
    @@ -519,10 +519,9 @@
     
     var
       pnt: AnsiString;
    -  b,isExtra,terminator_found: Boolean;
    +  b,isExtra: Boolean;
     
     begin
    -  terminator_found:=False;
       ClearStatement;
       while FLine <= FSQL.Count do
         begin
    @@ -530,7 +529,6 @@
         if (pnt=FTerminator) then
           begin
           FCol:=FCol + length(pnt);
    -      terminator_found:=True;
           break;
           end
         else if pnt = '/*' then
    @@ -583,8 +581,6 @@
             FCol:=FCol + length(pnt);
           end;
         end;
    -  if not terminator_found then
    -    ClearStatement;
       while (FCurrentStatement.Count > 0) and (trim(FCurrentStatement.Strings[0]) = '') do
         FCurrentStatement.Delete(0);
       while (FCurrentStripped.Count > 0) and (trim(FCurrentStripped.Strings[0]) = '') do
    

Activities

Ondrej Pokorny

2017-09-29 08:29

developer  

sqlscript-terminator-01.patch (966 bytes)
Index: packages/fcl-db/src/base/sqlscript.pp
===================================================================
--- packages/fcl-db/src/base/sqlscript.pp	(revision 37292)
+++ packages/fcl-db/src/base/sqlscript.pp	(working copy)
@@ -519,10 +519,9 @@
 
 var
   pnt: AnsiString;
-  b,isExtra,terminator_found: Boolean;
+  b,isExtra: Boolean;
 
 begin
-  terminator_found:=False;
   ClearStatement;
   while FLine <= FSQL.Count do
     begin
@@ -530,7 +529,6 @@
     if (pnt=FTerminator) then
       begin
       FCol:=FCol + length(pnt);
-      terminator_found:=True;
       break;
       end
     else if pnt = '/*' then
@@ -583,8 +581,6 @@
         FCol:=FCol + length(pnt);
       end;
     end;
-  if not terminator_found then
-    ClearStatement;
   while (FCurrentStatement.Count > 0) and (trim(FCurrentStatement.Strings[0]) = '') do
     FCurrentStatement.Delete(0);
   while (FCurrentStripped.Count > 0) and (trim(FCurrentStripped.Strings[0]) = '') do

Michael Van Canneyt

2017-09-29 09:49

administrator   ~0103112

Applied, and added a test to the testsuite, testsuite for DB related things is in fcl-db/tests.

Thanks for the patch

Ondrej Pokorny

2017-09-29 10:11

developer   ~0103113

Thank you!

Issue History

Date Modified Username Field Change
2017-09-29 08:29 Ondrej Pokorny New Issue
2017-09-29 08:29 Ondrej Pokorny File Added: sqlscript-terminator-01.patch
2017-09-29 09:13 Michael Van Canneyt Assigned To => Michael Van Canneyt
2017-09-29 09:13 Michael Van Canneyt Status new => assigned
2017-09-29 09:49 Michael Van Canneyt Fixed in Revision => 37355
2017-09-29 09:49 Michael Van Canneyt Note Added: 0103112
2017-09-29 09:49 Michael Van Canneyt Status assigned => resolved
2017-09-29 09:49 Michael Van Canneyt Fixed in Version => 3.1.1
2017-09-29 09:49 Michael Van Canneyt Resolution open => fixed
2017-09-29 09:49 Michael Van Canneyt Target Version => 3.2.0
2017-09-29 10:11 Ondrej Pokorny Note Added: 0103113
2017-09-29 10:11 Ondrej Pokorny Status resolved => closed