Subject Re: [firebird-python] [fdb] ValueError: Value of parameter (0) is too long
Author Pavel Cisar
Dne 27.9.2012 17:57, Maximiliano Robaina napsal(a):
> Hi,
>
> Running the next sql, I get an ValueError exception:
>
> cur.execute('SELECT "DJANGO_SESSION"."SESSION_KEY",
> "DJANGO_SESSION"."SESSION_DATA", "DJANGO_SESSION"."EXPIRE_DATE" FROM
> "DJANGO_SESSION" WHERE "DJANGO_SESSION"."SESSION_KEY" = ?',
> ('1234567890123456789012345678901234567890',))
>
>
> The "DJANGO_SESSION"."SESSION_KEY" is defined as VARCHAR(40), then if
> I try to execute a sql with a value for SESSION_KEY bigger than 40,
> fdb raise an exception
>
> Traceback (most recent call last): File "<stdin>", line 1, in
> <module> File "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py",
> line 2233, in execute self._ps._execute(parameters) File
> "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 2070, in
> _execute self.__Tuple2XSQLDA(self.in_sqlda, parameters) File
> "/usr/local/lib/python2.7/dist-packages/fdb/fbcore.py", line 1887, in
> __Tuple2XSQLDA len(value))) ValueError: Value of parameter (0) is too
> long, expected 40, found 1240
>
> If I execute the same sql in FlameRobin it works fine, without error.
> Of course it returns a empty record because there isn't one record
> with this value.
>
> How fdb work in this sense?

Once again, this is the difference between executing parametrized and
non-parametrized SQL command. In FlameRobin, the whole string is sent to
server, while in FDB you passed the SESSION_KEY value as separate
parameter (via (X)SQLDA structure(s)). Firebird initializes these
structures for client, and part of that information is max. length for
each parameter Firebird expects, so FDB checks whether you're trying to
send more or not. Actually, all DSQL communication libraries should work
in the same way when you use parametrized statement. BTW, if you'll
execute this statement as a whole string, not parametrized, via FDB, you
should get the same result like with FlameRobin.

best regards
Pavel Cisar
IBPhoenix