Re: [firebird-python] fdb 1.4.3, SA 0.9.7 on Py2.7 conversion error

2015-02-04 Thread Pavel Cisar pci...@ibphoenix.cz [firebird-python]
Hi Werner,

Dne 4.2.2015 v 17:11 Werner werner...@gmx.ch [firebird-python] napsal(a):
>
> result = session.connection().execute(s, fk_authuser_id_1=1,
> maturityfirst_1='', maturityfirst_2='')
>
> for i in result:
>  print(i)
>
> The two "maturityfirst" are integer columns and I inadvertently used a
> string for the filter value.
>
> It would be nice if fdb could get a more detailed error to make it
> easier to track down such an error.

I see. The problem is that FDB supports automatic conversion from string 
values like KInterbasDB did, because it's feature of Firebird. It's also 
documented, see
http://pythonhosted.org//fdb/usage-guide.html#implicit-conversion-of-input-parameters-from-strings

So if you wouldn't use empty strings but numeric strings like '12565' it 
would work just fine. The conversion is done by Firebird, not by FDB 
(driver just changes XSQLVAR.sqltype to SQL_TEXT and passes the string 
parameter value to client library, so it's not checked for validity in 
any way (you know, it could be a date, timestamp, decimal or float etc. 
not just integer). if there is any problem, it's detected an reported by 
Firebird client (in this case it's SQLCODE: -303) so FDB couldn't help 
you here with more detailed error message.

best regards
Pavel Cisar
IBPhoenix


Re: [firebird-python] fdb 1.4.3, SA 0.9.7 on Py2.7 conversion error

2015-02-04 Thread Werner werner...@gmx.ch [firebird-python]

Hi,
On 2/3/2015 17:13, Werner werner...@gmx.ch [firebird-python] wrote:


Hi,

I am getting the following error during testing of my application, but
only on Py2.7, if I run the same application on Py3.4 with the same fdb
and SQLAlchemy version I don't see this error.

I'll continue to search for the reason but if someone has a tip, please
let me know.

OK, I found the actual culprit and fixed it in my code, but maybe fdb 
can be improved.


The code causing it is:
s = """
SELECT cellarbook.id AS cellarbook_id, cellarbook.maturityfirst AS 
cellarbook_maturityfirst, cellarbook.maturitybest AS 
cellarbook_maturitybest, cellarbook.maturitypast AS 
cellarbook_maturitypast, cellarbook.storagelocation AS 
cellarbook_storagelocation, cellarbook.lastpurchaseprice AS 
cellarbook_lastpurchaseprice, cellarbook.avgpurchaseprice AS 
cellarbook_avgpurchaseprice, cellarbook.currentvalue AS 
cellarbook_currentvalue, cellarbook.quantitypurchased AS 
cellarbook_quantitypurchased, cellarbook.quantityconsumed AS 
cellarbook_quantityconsumed, cellarbook.quantityonhand AS 
cellarbook_quantityonhand, cellarbook.purchasevalueonhand AS 
cellarbook_purchasevalueonhand, cellarbook.currentvalueonhand AS 
cellarbook_currentvalueonhand, cellarbook.isactive AS 
cellarbook_isactive, cellarbook.printlabel AS cellarbook_printlabel, 
cellarbook.minqoh AS cellarbook_minqoh, cellarbook.avgscore AS 
cellarbook_avgscore, cellarbook.avgscore2 AS cellarbook_avgscore2, 
cellarbook.maxprice AS cellarbook_maxprice, cellarbook.purchaseagain AS 
cellarbook_purchaseagain, cellarbook.uservint1 AS cellarbook_uservint1, 
cellarbook.uservint2 AS cellarbook_uservint2, cellarbook.userbot1 AS 
cellarbook_userbot1, cellarbook.userbot2 AS cellarbook_userbot2, 
cellarbook.fk_supplier_id AS cellarbook_fk_supplier_id, 
cellarbook.fk_cellar_id AS cellarbook_fk_cellar_id, 
cellarbook.fk_authuser_id AS cellarbook_fk_authuser_id, 
cellarbook.fk_bottle_id AS cellarbook_fk_bottle_id, 
cellarbook.fk_vintage_id AS cellarbook_fk_vintage_id, 
cellarbook.fk_drinkinfo_id AS cellarbook_fk_drinkinfo_id, 
cellarbook.created_at AS cellarbook_created_at, cellarbook.updated_at AS 
cellarbook_updated_at, cellarbook.created_by AS cellarbook_created_by, 
cellarbook.updated_by AS cellarbook_updated_by

FROM cellarbook
WHERE cellarbook.fk_authuser_id = :fk_authuser_id_1 AND 
cellarbook.maturityfirst BETWEEN :maturityfirst_1 AND :maturityfirst_2

"""

s = db.sasql.text(s)

result = session.connection().execute(s, fk_authuser_id_1=1, 
maturityfirst_1='', maturityfirst_2='')


for i in result:
print(i)

The two "maturityfirst" are integer columns and I inadvertently used a 
string for the filter value.


It would be nice if fdb could get a more detailed error to make it 
easier to track down such an error.


Werner