I've got a table containing a VARCHAR, and if I query for that field 'containing' a parameter value longer than the VARCHAR, it fails with an error.
If I use a literal in the SQL, it works though.
$ /opt/firebird/bin/isql Use CONNECT or CREATE DATABASE to specify a database SQL> create database 'localhost:/tmp/test.fdb'; SQL> create table test_table ( CON> test_field varchar(10) CON> ); SQL> commit ;
SQL> select * from test_table where test_field containing 'very_long_string'; SQL>
Using a parameterized query from Python, though:
import fdb
con = fdb.connect('localhost:/tmp/test.fdb')
cur = con.cursor()
for row in cur.execute("select * from test_table where cast(test_field as varchar(50)) containing ?", ("string_longer_than_10_characters",)):
print(row)
$ python3 test.py
Traceback (most recent call last):
File "/home/hamish/test.py", line 5, in <module>
for row in cur.execute("select * from test_table where test_field containing ?", ("string_longer_than_10_characters",)):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/fdb/fbcore.py", line 3695, in execute
self._ps._execute(parameters)
File "/usr/lib/python3/dist-packages/fdb/fbcore.py", line 3364, in _execute
self.__tuple2xsqlda(self._in_sqlda, parameters)
File "/usr/lib/python3/dist-packages/fdb/fbcore.py", line 3145, in __tuple2xsqlda
raise ValueError("Value of parameter (%i) is too long,"
ValueError: Value of parameter (0) is too long, expected 10, found 32
Though I have also seen this fail with "arithmetic exception, numeric overflow, or string truncation\n- string right truncation\n- expected length 10, actual 33".
Why does the query with parameter behave differently to the literal? And would you expect this to work?
Thanks
Hamish