Recent

Author Topic: Firebird Insert Query.  (Read 3584 times)

cov

  • Full Member
  • ***
  • Posts: 222
Firebird Insert Query.
« on: April 29, 2013, 09:36:26 am »
I'm trying to insert values into a table.

Code: [Select]
    IBConnection1.ExecuteDirect('INSERT INTO USERNAMES(ID,OPERATOR,STATUS) VALUES(0,"dave",2);');
    SQLTransaction1.Commit;                                             

But I'm getting an error:

Quote
IBConnection1 : PrepareStatement:
- Dynamic SQL Error
- SQL error code =-206
- Column unknown
- dave
- at line 1, column 47

A similar statement works without error elsewhere
Code: [Select]


  IBConnection1.ExecuteDirect('INSERT INTO FIELDS(ID,"CLIENTNAME") VALUES(68,''ASSMANG - NEWCASTLE-'')');
  SQLTransaction1.Commit;

jujibo

  • Jr. Member
  • **
  • Posts: 81
Re: Firebird Insert Query.
« Reply #1 on: April 29, 2013, 09:50:17 am »
The solution is in your second sql sentence.

Don't use " (double quote) for field values, use  two single quotes ' '

try:

IBConnection1.ExecuteDirect('INSERT INTO USERNAMES(ID,OPERATOR,STATUS) VALUES(0,''dave'',2);');

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Firebird Insert Query.
« Reply #2 on: April 29, 2013, 10:18:11 am »
If you have these errors, copy/paste the SQL string into FlameRobin and run it there.

jujibo is right: use ' for quoting strings... or parameterised queries (see sqldbtutorial3).
Use " to quote table/object names (though not recommended as I think then you need to match exact case)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

cov

  • Full Member
  • ***
  • Posts: 222
Re: Firebird Insert Query.
« Reply #3 on: April 29, 2013, 04:47:39 pm »
Great, thanks very much, that's now working... 8)

 

TinyPortal © 2005-2018