* * *

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

HatForCat

  • Sr. Member
  • ****
  • Posts: 260
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, 256-SSD, Ubuntu 14.04-LTS, Unity Desktop, Lazarus 1.6.2, SQLite3 -- Retired: Programming for my own use for Ubuntu.

talorigomat

  • Jr. Member
  • **
  • Posts: 82
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.6.4, Windows 10

HatForCat

  • Sr. Member
  • ****
  • Posts: 260
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, 256-SSD, Ubuntu 14.04-LTS, Unity Desktop, Lazarus 1.6.2, SQLite3 -- Retired: Programming for my own use for Ubuntu.

valdir.marcos

  • Full Member
  • ***
  • Posts: 216
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: 684
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 1.6 (32b) / FPC 3.0
Windows Vista /  10

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus