Problem with ZQuery

Forum related to MySQL

Moderators: gto, cipto_kh, EgonHugeist

alexcagliari
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 28.04.2013, 11:49

Problem with ZQuery

Postby alexcagliari » 28.04.2013, 11:59

Hi guys,
i've a problem with zquery...
This is the code:

Code: Select all

// inizia sql
                     with ZQuery1 do
                       begin
                          Active:=False;
                          SQL.Clear;
                          SQL.Add('Insert into logbook(Callsign,Name,City) values('+Callsign.Text+','+Nome.Text+','+Country.Text+');');
                      ExecSQL;
                      end;
                     // finisce sql


And the database is in the attached image...

in Callsign (edit field) i write ABABAB
in Nome (edit field) i write CDCDCD
in Country (edit field) i write EFEFEF

The content of ZQuery.Sql.Text it's (i hope) correct:

Code: Select all

insert into logbook(Callsign,Name,City) Values(ABABAB,CDCDCD,EFEFEF);


After all Delphi say me:
SQL Error: Unknown column 'ABABAB' in 'field list

How can i resolve? :(
You do not have the required permissions to view the files attached to this post.

alexcagliari
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 28.04.2013, 11:49

Postby alexcagliari » 30.04.2013, 14:54

help me..

marsupilami
Gold Boarder
Gold Boarder
Posts: 671
Joined: 17.01.2011, 14:17

Postby marsupilami » 30.04.2013, 16:20

Hello alexcagliari,

if you want to insert the data directly into the SQL then you need to encase the Strings in quotes:

Code: Select all

// inizia sql
                     with ZQuery1 do
                       begin
                          Active:=False;
                          SQL.Clear;
                          SQL.Add('Insert into logbook(Callsign,Name,City) values(' + QuotedStr(Callsign.Text) + ',' + QuotedStr(Nome.Text) + ',' + QuotedStr(Country.Text) + ');');
                          ExecSQL;
                      end;
                     // finisce sql


but in any case it would be better to use parameters for passing the contents into the database:

Code: Select all

// inizia sql
                     with ZQuery1 do
                       begin
                          Active:=False;
                          SQL.Clear;
                          SQL.Add('Insert into logbook(Callsign, Name, City) values ( :CALLSIGN, :NOME, :COUNTRY);');
                          SQL.ParamByName('CALLSIGN').AsString := Callsign.Text;
                          SQL.ParamByName('NOME').AsString := Nome.Text;
                          SQL.ParamByName('COUNTRY').AsString := Country.Text;
                          ExecSQL;
                      end;
                     // finisce sql

Best regards,

Jan


Return to “MySQL”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest