Recent

Author Topic: Near 'set':Syntax Error - not that I can see!  (Read 6320 times)

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Near 'set':Syntax Error - not that I can see!
« on: April 15, 2017, 12:38:29 am »
This is driving me crazy, a short trip I know, but...
The Table name is correct, it is not locked by anything else. Where is the syntax error?
Where am I going wrong?

Code: Pascal  [Select][+][-]
  1.   tStr:='UPDATE People SET zActive = 0, zEmailAddr = "help@amazon.com"  WHERE zID = 6;' ;
  2.   sqlPeople.SQL.Text:=tStr;
  3.   sqlPeople.ExecSQL;
  4.  

Thanks
« Last Edit: April 15, 2017, 02:05:33 pm by HatForCat »
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

talorigomat

  • Jr. Member
  • **
  • Posts: 96
Re: Near 'set':Syntax Error - not that I can see!
« Reply #1 on: April 15, 2017, 04:16:58 am »
To assign a value to a variable use ":="

line 1 should read:

tStr := 'UPDATE People SET zActive = 0, zEmailAddr = "help@amazon.com"  WHERE zID = 6;' ;

Also notice the semicolon that is outside the final single quote.  Without this the program would fail to compile.

I am assuming the database you are using accepts a pair of double quotes to delimit strings as the one I work with uses single quotes.
Lazarus 1.8.0Rc4, Windows 10

HatForCat

  • Sr. Member
  • ****
  • Posts: 293
Re: Near 'set':Syntax Error - not that I can see!
« Reply #2 on: April 15, 2017, 02:04:58 pm »
To assign a value to a variable use ":="

Thanks, my mistake. I copied that from the Debugging Window. I used that so it was displaying exactly what the running program was seeing.

In the program it is constructed correctly and compiles and runs. Just keeps declaring an error on a line that looks OK to me.

I will correct the OP Code. The pertinent Code/SQL etc details are in my Signature.
Acer-i5, 2.6GHz, 6GB, 500GB-SSD, Mint-19.3, Cinnamon Desktop, Lazarus 2.0.6, SQLite3

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: Near 'set':Syntax Error - not that I can see!
« Reply #3 on: April 17, 2017, 03:36:56 pm »
Code: Pascal  [Select][+][-]
  1.   tStr:='UPDATE People SET zActive = 0, zEmailAddr = "help@amazon.com"  WHERE zID = 6;' ;
  2.   sqlPeople.SQL.Text:=tStr;
  3.   sqlPeople.ExecSQL;
  4.  


Try chance double quote to single quote on string inside SQL.Text:
Code: Pascal  [Select][+][-]
  1.   tStr:='UPDATE People SET zActive = 0, zEmailAddr = ''help@amazon.com'' WHERE zID = 6;' ;

or

Code: Pascal  [Select][+][-]
  1.   tStr:='UPDATE People SET zActive = 0, zEmailAddr = ' + QuotedStr('help@amazon.com') + ' WHERE zID = 6;' ;

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Near 'set':Syntax Error - not that I can see!
« Reply #4 on: April 18, 2017, 09:36:12 am »
create less errors to use parameters
Code: Pascal  [Select][+][-]
  1. with sqlPeople do
  2. begin
  3.   SQL.text  := 'UPDATE People SET zActive = :zActive, zEmailAddr = :zEmailAddr  WHERE zID = :zID;' ;
  4.   parambyname('zActive').AsInteger := 0;
  5.   parambyname('zEmailAddr').AsString := 'help@amazon.com';
  6.   parambyname('zID').AsInteger := 6;
  7.   sqlPeople.ExecSQL;
  8.  
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

 

TinyPortal © 2005-2018