2

I keep getting an syntax error during runtime when this query is called.

adoquery1.Active := false;
adoquery1.SQL.Clear;
SQLQuery := 'INSERT INTO Comics ';
SQLQuery := SQLQuery + '(Name,Issue,Series,Volume,Poster,';
SQLQuery := SQLQuery + 'Desc,Writer,Artist,Read,Link,Extra) ';
SQLQuery := SQLQuery + 'VALUE('+ quotedstr(SeriesName+' '+IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(SeriesName);
SQLQuery := SQLQuery + ','+ quotedstr(VolumeNumber);
SQLQuery := SQLQuery + ','+ quotedstr(Poster);
SQLQuery := SQLQuery + ','+ quotedstr(Desc);
SQLQuery := SQLQuery + ','+ quotedstr(Writer);
SQLQuery := SQLQuery + ','+ quotedstr(Artist);
SQLQuery := SQLQuery + ','+ quotedstr(haveRead);
SQLQuery := SQLQuery + ','+ quotedstr(filelink);
SQLQuery := SQLQuery + ','+ quotedstr(Extra);
SQLQuery := SQLQuery + ')';
memo1.Text := SQLQuery;
adoquery1.SQL.Add(SQLQuery);
adoquery1.Active := true;

When i do the memo1.text = sqlquery, it looks to be ok, any suggestions? this is what i get in the memo1.text..

INSERT INTO Comics (Name,Issue,Series,Volume,Poster,Desc,Writer,Artist,Read,Link,Extra VALUE('xmen 8','8','xmen','1','na','Some Description','BOBwriter','BOBArtist','Yes','C:\Comics\xmen8.cbr','Some Extra info')
1
  • This is just so wrong. Please do some searching on parameterized queries instead of doing all of the string concatenation. You'll save yourself literally tons of trouble and make your code much cleaner, clearer, and safer. Commented May 24, 2012 at 12:29

3 Answers 3

5

Desc is a reserved word, so you should use [Desc] or enclose it in backticks (I don't know which database you're using).
More: I think it should be VALUES( and not VALUE(.

INSERT INTO Comics 
    (Name, Issue, Series, Volume, Poster, [Desc],
     Writer, Artist, [Read], Link, Extra) 
VALUES
    ('xmen 8', '8', 'xmen', '1', 'na', 'Some Description',
     'BOBwriter', 'BOBArtist', 'Yes', 'C:\Comics\xmen8.cbr','Some Extra info')
Sign up to request clarification or add additional context in comments.

3 Comments

I tired using values and value, Also changed the var DESC to Descrip, Same errors..
@GlenMorse: did you try the query I wrote? I used brackets also for Read
@GlenMorse: you shouldn't change your var name, but your query!! Reserved word is inside your query...
3

Enclose the Reserved Word DESC with brackets

adoquery1.Active := false;
adoquery1.SQL.Clear;
SQLQuery := 'INSERT INTO Comics ';
SQLQuery := SQLQuery + '(Name,Issue,Series,Volume,Poster,';
SQLQuery := SQLQuery + '[Desc],Writer,Artist,[Read],Link,Extra) ';
SQLQuery := SQLQuery + 'VALUES ('+ quotedstr(SeriesName+' '+IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(IssueNumber);
SQLQuery := SQLQuery + ','+ quotedstr(SeriesName);
SQLQuery := SQLQuery + ','+ quotedstr(VolumeNumber);
SQLQuery := SQLQuery + ','+ quotedstr(Poster);
SQLQuery := SQLQuery + ','+ quotedstr(Desc);
SQLQuery := SQLQuery + ','+ quotedstr(Writer);
SQLQuery := SQLQuery + ','+ quotedstr(Artist);
SQLQuery := SQLQuery + ','+ quotedstr(haveRead);
SQLQuery := SQLQuery + ','+ quotedstr(filelink);
SQLQuery := SQLQuery + ','+ quotedstr(Extra);
SQLQuery := SQLQuery + ')';
memo1.Text := SQLQuery;
adoquery1.SQL.Add(SQLQuery);
adoquery1.Active := true;

Comments

2

use Values instead of value.
Desc and Read are reserved keywords, so enclose then in square brackets.
You forgot to keep closing parenthesis before Values keyword.

INSERT INTO Comics 
            (Name, 
             Issue, 
             Series, 
             Volume, 
             Poster, 
             [Desc], 
             Writer, 
             Artist, 
             [Read], 
             Link, 
             Extra) 
VALUES     ('xmen 8', 
            '8', 
            'xmen', 
            '1', 
            'na', 
            'Some Description', 
            'BOBwriter', 
            'BOBArtist', 
            'Yes', 
            'C:\Comics\xmen8.cbr', 
            'Some Extra info') 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.