Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-08

Problem working with Params in TSQLQuery

22 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Eduardo Lopez

The scenario:

Lazarus 0.9.25 svn: 16095M
fpc 2.2.2
Ubuntu 8.04 GTK2
SQLDb components
TIBConnection

The following query works well:

    qry02.SQL.Clear;
    qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' +
chr(39) + trim(pUsuario) + chr(39);
    trn02.Active:=true;
    qry02.Open;
    ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString;         // <--
ContrasenaDB get the value from the query

But this one don't get the value of 'PASSWOR':

    qry02.SQL.Clear;
    qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU';
    qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario);
    trn02.Active:=true;
    qry02.Open;
    ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString;        // <---
ContrasenaDB is empty

(The second code was working with fpc 2.2.0 and the UIB components, with some changes. When upgrade to fpc 2.2.2 i began to replace de UIB with the default SQLDb componentes).

TIA.

Eduardo.

Reply by email

Michael Van Canneyt
to Eduardo Lopez
Eduardo Lopez wrote 32 lines
The scenario: Lazarus 0.9.25 svn: 16095M fpc 2.2.2 Ubuntu 8.04 GTK2 SQLDb components TIBConnection The following query works well: qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' + chr(39) + trim(pUsuario) + chr(39); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <-- ContrasenaDB get the value from the query But this one don't get the value of 'PASSWOR': qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU'; qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <--- ContrasenaDB is empty (The second code was working with fpc 2.2.0 and the UIB components, with some changes. When upgrade to fpc 2.2.2 i began to replace de UIB with the default SQLDb componentes).

I have parameters working. Is the ParseSQL property set to 'True' ?

Michael.

Reply by email

Joost van der Sluis
to Michael Van Canneyt

Op maandag 18-08-2008 om 09:14 uur [tijdzone +0200], schreef Michael Van Canneyt:

Show quoted text 37 lines
On Mon, 18 Aug 2008, Eduardo Lopez wrote: > The scenario: > > Lazarus 0.9.25 svn: 16095M > fpc 2.2.2 > Ubuntu 8.04 GTK2 > SQLDb components > TIBConnection > > The following query works well: > > qry02.SQL.Clear; > qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' + > chr(39) + trim(pUsuario) + chr(39); > trn02.Active:=true; > qry02.Open; > ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <-- > ContrasenaDB get the value from the query > > > But this one don't get the value of 'PASSWOR': > > qry02.SQL.Clear; > qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU'; > qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario); > trn02.Active:=true; > qry02.Open; > ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <--- > ContrasenaDB is empty > > (The second code was working with fpc 2.2.0 and the UIB components, with > some changes. When upgrade to fpc 2.2.2 i began to replace de UIB with > the default SQLDb componentes). I have parameters working. Is the ParseSQL property set to 'True' ?
That shoudn't make any difference. What if you use
params[0].asstring := ... ?

Joost

Reply by email

Rodney Pont
to Eduardo Lopez: The scenario: Lazarus 0.9.25 svn: 16095M fpc 2.2.2 Ubuntu 8.04 GTK2 SQLDb components…
Eduardo Lopez wrote 20 lines
The following query works well: qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' + chr(39) + trim(pUsuario) + chr(39); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <-- ContrasenaDB get the value from the query But this one don't get the value of 'PASSWOR': qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU'; qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <--- ContrasenaDB is empty

The first one has quotes around the data string you are comparing against, has the second one got the quotes too when it's passed to the database?

Regards - Rodney Pont E-mail by PMMail - really weird out of context words courtesy of PMMail's spellchecker

Reply by email

Michael Van Canneyt
to Rodney Pont
Rodney Pont wrote 26 lines
On Mon, 18 Aug 2008 02:01:14 -0300, Eduardo Lopez wrote: >The following query works well: > > qry02.SQL.Clear; > qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' + >chr(39) + trim(pUsuario) + chr(39); > trn02.Active:=true; > qry02.Open; > ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <-- >ContrasenaDB get the value from the query > > >But this one don't get the value of 'PASSWOR': > > qry02.SQL.Clear; > qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU'; > qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario); > trn02.Active:=true; > qry02.Open; > ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <--- >ContrasenaDB is empty The first one has quotes around the data string you are comparing against, has the second one got the quotes too when it's passed to the database?

You should never put the quotes manually for parameters. The engine will do so if it is required.

Michael.

Reply by email

Eduardo Lopez
to Joost van der Sluis: Op maandag 18-08-2008 om 09:14 uur [tijdzone +0200], schreef Michael Van Canneyt: That…

Joost van der Sluis escribi?:

Show quoted text 14 lines
Op maandag 18-08-2008 om 09:14 uur [tijdzone +0200], schreef Michael Van Canneyt: > On Mon, 18 Aug 2008, Eduardo Lopez wrote: > > > ave parameters working. Is the ParseSQL property set to 'True' ? > That shoudn't make any difference. What if you use params[0].asstring := ... ? Joost

First, thanks all for yours reply.

The ParseSQL has no effect.

Joost, the change you suggest don't work too.

I isolate the problem doing a simple program and the problem remains. Then make a copy of this simple program and change the components to Zeos. (6.6.3-stable) and works well.

I'll consider change the sqldb components for Zeos in my application as a possible solution. But the sqldb must be work (i think :-) ).

Thanks to all.

Eduardo.

Reply by email

Joost van der Sluis
to Eduardo Lopez

Op maandag 18-08-2008 om 15:38 uur [tijdzone -0300], schreef Eduardo Lopez:

Show quoted text 28 lines
Joost van der Sluis escribi?: > Op maandag 18-08-2008 om 09:14 uur [tijdzone +0200], schreef Michael Van > Canneyt: > >> On Mon, 18 Aug 2008, Eduardo Lopez wrote: >> >> >> ave parameters working. Is the ParseSQL property set to 'True' ? >> > > That shoudn't make any difference. What if you use > params[0].asstring := ... ? > > Joost > First, thanks all for yours reply. The ParseSQL has no effect. Joost, the change you suggest don't work too. I isolate the problem doing a simple program and the problem remains. Then make a copy of this simple program and change the components to Zeos. (6.6.3-stable) and works well. I'll consider change the sqldb components for Zeos in my application as a possible solution. But the sqldb must be work (i think :-) ).

Offcourse, but then we have to find the problem. Parameters do work here, also in the testsuite. What happens if you remove the 'trim' in both cases? (Without the parameter and with?)

Joost

Reply by email

Eduardo Lopez
to Joost van der Sluis

Joost van der Sluis escribi?:

Show quoted text 12 lines
> I isolate the problem doing a simple program and the problem remains. > Then make a copy of this simple program and change the components to > Zeos. (6.6.3-stable) and works well. > > I'll consider change the sqldb components for Zeos in my application as > a possible solution. But the sqldb must be work (i think :-) ). > Offcourse, but then we have to find the problem. Parameters do work here, also in the testsuite. What happens if you remove the 'trim' in both cases? (Without the parameter and with?)

I tried and nothing happens.
I prepare the sample proyect, if someone want to see it and can find what stupid thing i'm doing... ;-)

http://www.sistemasrpm.com.ar/soporte/test_param.tar.g

TIA.
Eduardo.

Show quoted text 7 lines
Joost _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Michael Van Canneyt
to Eduardo Lopez
Show quoted text 22 lines
On Mon, 18 Aug 2008, Eduardo Lopez wrote: > Joost van der Sluis escribi?: >> I isolate the problem doing a simple program and the problem remains. >> Then make a copy of this simple program and change the components to >> Zeos. (6.6.3-stable) and works well. >> >> I'll consider change the sqldb components for Zeos in my application as >> a possible solution. But the sqldb must be work (i think :-) ). >> > > Offcourse, but then we have to find the problem. Parameters do work > here, also in the testsuite. What happens if you remove the 'trim' in > both cases? (Without the parameter and with?) > I tried and nothing happens. I prepare the sample proyect, if someone want to see it and can find what stupid thing i'm doing... ;-) http://www.sistemasrpm.com.ar/soporte/test_param.tar.g

I get a permission denied error trying to access this URL, and the same when I add a .gz

Michael.

Reply by email

Michael Van Canneyt
to Vincent Snijders
Vincent Snijders wrote 11 lines
Michael Van Canneyt schreef: >> >> On Mon, 18 Aug 2008, Eduardo Lopez wrote: >> http://www.sistemasrpm.com.ar/soporte/test_param.tar.g > > I get a permission denied error trying to access this URL, > and the same when I add a .gz > I can download: http://www.sistemasrpm.com.ar/soporte/test_param.tar.gz

Hehe, it's anti-robot measures. But I can circumvent that :-)

gru: >wget http://www.sistemasrpm.com.ar/soporte/test_param.tar.gz --09:43:58-- http://www.sistemasrpm.com.ar/soporte/test_param.tar.gz => `test_param.tar.gz'
Resolving www.sistemasrpm.com.ar... 201.216.232.68 Connecting to www.sistemasrpm.com.ar|201.216.232.68|:80... connected. HTTP request sent, awaiting response... 403 Forbidden 09:44:01 ERROR 403: Forbidden.

gru: >wget --user-agent=Konqueror
http://www.sistemasrpm.com.ar/soporte/test_param.tar.gz --09:44:53-- http://www.sistemasrpm.com.ar/soporte/test_param.tar.gz => `test_param.tar.gz'
Resolving www.sistemasrpm.com.ar... 201.216.232.68 Connecting to www.sistemasrpm.com.ar|201.216.232.68|:80... connected. HTTP request sent, awaiting response... 200 OK
Length: 2,842 (2.8K) [application/x-gzip]

100%[================================================================================>] 2,842 --.--K/s

09:44:54 (194.02 KB/s) - `test_param.tar.gz' saved [2842/2842]

Michael.

Reply by email

Michael Van Canneyt
to Eduardo Lopez: Joost van der Sluis escribi?: I tried and nothing happens. I prepare the sample proyect,…
Show quoted text 22 lines
On Mon, 18 Aug 2008, Eduardo Lopez wrote: > Joost van der Sluis escribi?: >> I isolate the problem doing a simple program and the problem remains. >> Then make a copy of this simple program and change the components to >> Zeos. (6.6.3-stable) and works well. >> >> I'll consider change the sqldb components for Zeos in my application as >> a possible solution. But the sqldb must be work (i think :-) ). >> > > Offcourse, but then we have to find the problem. Parameters do work > here, also in the testsuite. What happens if you remove the 'trim' in > both cases? (Without the parameter and with?) > I tried and nothing happens. I prepare the sample proyect, if someone want to see it and can find what stupid thing i'm doing... ;-) http://www.sistemasrpm.com.ar/soporte/test_param.tar.g

Can you please provide the CREATE statement for the table ? Without the correct table definition, it's hard to test.

Michael.

Reply by email

Eduardo Lopez

I'm sorry. The table has a basic structure:

CREATE TABLE USUARIOS
(
CODUSU Char(12) NOT NULL,
APENOMB Char(40) NOT NULL,
PASSWOR Char(12) NOT NULL,
CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU)
);

Thanks. Eduardo.

Earlier message 44 lines
----- Mensaje original ---- De: Michael Van Canneyt Para: General mailing list Enviado: martes 19 de agosto de 2008, 4:48:16 Asunto: Re: [Lazarus] Problem working with Params in TSQLQuery > > > On Mon, 18 Aug 2008, Eduardo Lopez wrote: > > > Joost van der Sluis escribi?: > >> I isolate the problem doing a simple program and the problem remains. > >> Then make a copy of this simple program and change the components to > >> Zeos. (6.6.3-stable) and works well. > >> > >> I'll consider change the sqldb components for Zeos in my application as > >> a possible solution. But the sqldb must be work (i think :-) ). > >> > > > > Offcourse, but then we have to find the problem. Parameters do work > > here, also in the testsuite. What happens if you remove the 'trim' in > > both cases? (Without the parameter and with?) > > > I tried and nothing happens. > I prepare the sample proyect, if someone want to see it and can find > what stupid thing i'm doing... ;-) > > http://www.sistemasrpm.com.ar/soporte/test_param.tar.g Can you please provide the CREATE statement for the table ? Without the correct table definition, it's hard to test. Michael. ____________________________________________________________________________________ ?Busc? desde tu celular! Yahoo! oneSEARCH ahora est? en Claro http://ar.mobile.yahoo.com/onesearch -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080819/987287c2/attachment.html

Reply by email

Michael Van Canneyt
to Eduardo Lopez
Eduardo Lopez wrote
I'm sorry. The table has a basic structure:

CREATE TABLE USUARIOS
(
CODUSU Char(12) NOT NULL,
APENOMB Char(40) NOT NULL,
PASSWOR Char(12) NOT NULL,
CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU)
);

Aha.
This is probably your problem. Try extending the parameter value so it has the declared length by padding it with spaces.

The other way is to declare the table as
CREATE TABLE USUARIOS
(
CODUSU VARChar(12) NOT NULL,
APENOMB VarChar(40) NOT NULL,
PASSWOR VarChar(12) NOT NULL,
CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU)
);

Could you try this ?

Michael.

Reply by email

Osvaldo Filho
to Eduardo Lopez: The scenario: Lazarus 0.9.25 svn: 16095M fpc 2.2.2 Ubuntu 8.04 GTK2 SQLDb components…

try UIB + FBDataset. Is very, very good.

2008/8/18 Eduardo Lopez

Show quoted text 44 lines
The scenario: Lazarus 0.9.25 svn: 16095M fpc 2.2.2 Ubuntu 8.04 GTK2 SQLDb components TIBConnection The following query works well: qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' + chr(39) + trim(pUsuario) + chr(39); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <-- ContrasenaDB get the value from the query But this one don't get the value of 'PASSWOR': qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU'; qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <--- ContrasenaDB is empty (The second code was working with fpc 2.2.0 and the UIB components, with some changes. When upgrade to fpc 2.2.2 i began to replace de UIB with the default SQLDb componentes). TIA. Eduardo. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080819/a6cec4f5/attachment.html

Reply by email

Eduardo Lopez

Yes!! It works now.!!

My challenge is now:

a) modify all my db structure or b) replace the sqldb components with zeos.

Thank you very much to all!!

Eduardo.

Eduardo Lopez wrote
I'm sorry. The table has a basic structure:

CREATE TABLE USUARIOS
(
CODUSU Char(12) NOT NULL,
APENOMB Char(40) NOT NULL,
PASSWOR Char(12) NOT NULL,
CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU)
);

Aha.
This is probably your problem. Try extending the parameter value so it has the declared length by padding it with spaces.

The other way is to declare the table as
CREATE TABLE USUARIOS
(
CODUSU VARChar(12) NOT NULL,
APENOMB VarChar(40) NOT NULL,
PASSWOR VarChar(12) NOT NULL,
CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU)
);

Could you try this ?

Michael.

Reply by email

Eduardo Lopez

Hi Osvaldo.

This was working with UIB and fpc 2.2.0.
When change to fpc 2.2.2 the UIB 2.1 don't work anymore.

I've tried the svn version of UIB, but i can't make it compile. Because it, i began to try the sqldb an zeoslib (with just a "new" stable release..)

Thanks!!. Eduardo.

Earlier message 51 lines
----- Mensaje original ---- De: Osvaldo Filho Para: General mailing list Enviado: martes 19 de agosto de 2008, 10:30:59 Asunto: Re: [Lazarus] Problem working with Params in TSQLQuery try UIB + FBDataset. Is very, very good. 2008/8/18 Eduardo Lopez The scenario: Lazarus 0.9.25 svn: 16095M fpc 2.2.2 Ubuntu 8.04 GTK2 SQLDb components TIBConnection The following query works well: qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = ' + chr(39) + trim(pUsuario) + chr(39); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <-- ContrasenaDB get the value from the query But this one don't get the value of 'PASSWOR': qry02.SQL.Clear; qry02.SQL.Text:= 'select PASSWOR from USUARIOS where CODUSU = :pCODUSU'; qry02.Params.ParamByName('pCODUSU').AsString:= trim(pUsuario); trn02.Active:=true; qry02.Open; ContrasenaDB:=qry02.FieldByName('PASSWOR').AsString; // <--- ContrasenaDB is empty (The second code was working with fpc 2.2.0 and the UIB components, with some changes. When upgrade to fpc 2.2.2 i began to replace de UIB with the default SQLDb componentes). TIA. Eduardo.

Reply by email

Bogusław Brandys
to Eduardo Lopez: Yes!! It works now.!! My challenge is now: a) modify all my db structure or b) replace…

Eduardo Lopez pisze:

Show quoted text 10 lines
Yes!! It works now.!! My challenge is now: a) modify all my db structure or b) replace the sqldb components with zeos. Thank you very much to all!! Eduardo.

c) write padding function

:-)

Show quoted text 46 lines
On Tue, 19 Aug 2008, Eduardo Lopez wrote: > I'm sorry. The table has a basic structure: CREATE TABLE USUARIOS ( CODUSU Char(12) NOT NULL, APENOMB Char(40) NOT NULL, PASSWOR Char(12) NOT NULL, CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU) ); Aha. This is probably your problem. Try extending the parameter value so it has the declared length by padding it with spaces. The other way is to declare the table as CREATE TABLE USUARIOS ( CODUSU VARChar(12) NOT NULL, APENOMB VarChar(40) NOT NULL, PASSWOR VarChar(12) NOT NULL, CONSTRAINT PK_USUARIOS PRIMARY KEY (CODUSU) ); Could you try this ? Michael. _______________________________________________ Lazarus mailing list <mailto:> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus Yahoo! Cocina Recetas pr?cticas y comida saludable Visit? http://ar.mujer.yahoo.com/cocina/ ------------------------------------------------------------------------ _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Michael Van Canneyt
to Eduardo Lopez: Yes!! It works now.!! My challenge is now: a) modify all my db structure or b) replace…
Show quoted text 9 lines
On Tue, 19 Aug 2008, Eduardo Lopez wrote: > Yes!! It works now.!! My challenge is now: a) modify all my db structure or b) replace the sqldb components with zeos.

Or pad your parameters.

Meanwhile I think I know why the problem exists, I will consult with Joost for a test and possible solution.

After we've committed a fix, you can then remove the padding function.

Michael.

Reply by email

Joost van der Sluis
to Michael Van Canneyt: Or pad your parameters. Meanwhile I think I know why the problem exists, I will consult…

Op dinsdag 19-08-2008 om 17:11 uur [tijdzone +0200], schreef Michael Van Canneyt:

Show quoted text 14 lines
> > > On Tue, 19 Aug 2008, Eduardo Lopez wrote: > > > Yes!! It works now.!! > > My challenge is now: > > a) modify all my db structure or b) replace the sqldb components with zeos. Or pad your parameters. Meanwhile I think I know why the problem exists, I will consult with Joost for a test and possible solution.

The problem is fixed in trunk. If you don't want to use trunk, or find it too much of a hassle. You can just place the new 'ibconnection.pp' unit in the search-path of your project.
(http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/packages/fcl-db/src/sqldb/interbase/ibconnection.pp?revision=11629)

Can you try and please give some feedback, so we know it's really solved?

Joost.

Reply by email