FirebirdSQL / fdb

Firebird Driver for Python
https://www.firebirdsql.org/en/devel-python-driver/
Other
60 stars 26 forks source link

Inserted (or updated) but not inserted !! (or updated) [PYFB80] #95

Closed firebird-automations closed 5 years ago

firebird-automations commented 5 years ago

Submitted by: christophe derenne (cdr60530)

All is in the title :

First, i'm using interbase then firebird since 20 years ago so i know what is a sql script and how to write it I'm using unix shell since 20 years ago so i know how to write script and use it with linux I'm using python since 5 years ago, so i know how to write a pyton script But i'm newbee using fdb package because, i always use firebird with unix shell or C or Pascal or Php

So I explain what is the trouble : Doing a littre script that do this things (with always for same row in the same table)

First : connect to firebird database with python - fdb with no error Second : Check Existing of a specific row with no error Third : Insert this row with no error Fourth : Check that the row exist with no error

This is my results : 1) connecting ok 2) the row does not exist 3) inserting with no error 4) the row exists

Re launching the script give me the same result !!! The row is never inserted Checking with flamerobin tells me that the row does not exist (or the trasaction has not been commited but fdb tells me that it did it did !!)

My sql scripts are all between ; con.main_transaction.begin() cur = con.cursor() sql="my sql statement : insert or select count(*)" try: cur.execute(sql) for row in cur: N=row[0] // if select count(*) print(str(N)) // if select count(*)

    except Exception,e:
        result=\-1
        print \("Erreur "\)
        print\(e\)
        print\(" dans "\)
        print \(str\(sql\)\)

    con\.main\_transaction\.commit      
    con\.close\(\)

I've try a lot of things, including with explicit transaction or not including better excepting script including with or without con.close including with volontary sql error to check that the exception will work including volontary insert a row and not checking the existance of this row to check that the existence fonction work (select count(*) syntax is correct)

So, i can not use python to write my script I wanted to use python because i need at the end to insert data in a blob field and isql-fb can not So what can i do ? Rewriting all the script with php ?

Information: before this problem my script is inserting 43 row with success in another table And this part is between a "fdb.connect / fdb.close" and use the same syntaxe (try - except, cursor, explicit transaction)

firebird-automations commented 5 years ago

Commented by: @pcisar

1. this is not a bug report, but support request. Use the firebird-python mailing list for such questions as bug tracker is the wrong place. 2. If you are really using: con.main_transaction.commit as you wrote, then transaction was not committed as without () it's a method reference and not a method call, i.e. you need to use con.main_transaction.commit(). That would explain why inserted row was not committed (but visible to current transaction while its active).

firebird-automations commented 5 years ago
Modified by: @pcisar status: Open \[ 1 \] =\> Closed \[ 6 \] resolution: Cannot Reproduce \[ 5 \]
firebird-automations commented 5 years ago

Commented by: christophe derenne (cdr60530)

I know ! And I you'd read all my message, you will see that I did it If not I won't open this issuie

I wrote : : " My sql scripts are all between ;

con.main_transaction.begin() cur = con.cursor() sql="my sql statement : insert or select count(*)" try: cur.execute(sql) for row in cur: N=row[0] // if select count(*) print(str(N)) // if select count(*)

except Exception,e: result=-1 print ("Erreur ") print(e) print(" dans ") print (str(sql))

con.main_transaction.commit
con.close() " You see con.main_transaction.commit ?? just before the last line ??

So It is a Bug

firebird-automations commented 5 years ago

Commented by: christophe derenne (cdr60530)

I've found it !! And this is a python bug

At the end, i wrote con.main_transaction.commit instead of con.main_transaction.commit () !!!

python gave me no error, all the script was running fine, no exception. But this last transaction was never commited With the parentesis, it is commited

So, this is a bug : using a function without parenthesis should be see has getting a variable (commit) that does not exist, so, python should give me a syntax exception

firebird-automations commented 5 years ago

Commented by: @pcisar

No, it's not a Python bug. You simply don't know Python enough. Please read Python documentation, at least about Python Data model (https://docs.python.org/2.7/reference/datamodel.html), look for "Callable types", callable() built-in function etc. Or better, read good book about Python, for example "Python Essential Reference" from David M. Beazley.