Forum > Databases

[SOLVED] SQLScript syntax error when executed for second time

(1/2) > >>

jamestien:
I use script to create a default database file, script ran without error for the 1st time, but not the succeeding call.

Can someone please point out why the error occurred when SQLScript.Execute is called on the 2nd time.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  s: string;begin  SaveDialog1.FileName := '';  if SaveDialog1.Execute then    begin      s := SaveDialog1.FileName;      if FileExists(s) then        DeleteFile(s);       SQLite3Connection1.DatabaseName := s;      SQLite3Connection1.Open;      SQLTransaction1.Active := TRUE;       SQLScript1.Execute;             //<========= Caused "Syntax error at ..." when executed for the 2nd time       SQLTransaction1.Commit;       SQLTransaction1.Active := FALSE ;      SQLite3Connection1.Close;       Application.MessageBox('Database has been created successfully.','Done',0);    end;end; 

bytebites:
Reassign seems to help?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      SQLScript1.Script.Text:=SQLScript1.Script.Text;

wp:
I am aware that this post is about SQLScript, but maybe I should note that direct execution of the query by the Sqlite3Connection does not have this issue:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      SQLite3Connection1.ExecuteDirect(        'CREATE TABLE IF NOT EXISTS "Company" ('+        '"Name"     VARCHAR(20) NOT NULL, '+        '"Address"  VARCHAR(200), '+        '"Phone"    VARCHAR(20), ' +        '"Email"    VARCHAR(30), ' +        '"Website"  VARCHAR(50)'+      ');');

jamestien:
Thanks for all the replies and suggestions.

The script included in the sample project is just an example, in real program I have more lines to execute in order to create a complete database.
If this is a SQLScript issue, then hope it will be addressed in the future release.

I will take ExecuteDirect method as suggested by wp as a workaround for now.


--- Quote from: wp on November 14, 2021, 01:41:59 pm ---I am aware that this post is about SQLScript, but maybe I should note that direct execution of the query by the Sqlite3Connection does not have this issue:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      SQLite3Connection1.ExecuteDirect(        'CREATE TABLE IF NOT EXISTS "Company" ('+        '"Name"     VARCHAR(20) NOT NULL, '+        '"Address"  VARCHAR(200), '+        '"Phone"    VARCHAR(20), ' +        '"Email"    VARCHAR(30), ' +        '"Website"  VARCHAR(50)'+      ');');
--- End quote ---

af0815:

--- Quote from: jamestien on November 15, 2021, 05:40:39 am ---If this is a SQLScript issue, then hope it will be addressed in the future release.
--- End quote ---
But only if a Bug is filed. If nobody knows it wont fixed.

Navigation

[0] Message Index

[#] Next page

Go to full version