waliwali / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

python crashed instead of raising error message on executemany #86

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.

    def run_test_execute_many(self):
        conn = ibm_db.connect(config.database, config.user, config.password)

        if conn:
            try:
            ibm_db.exec_immediate(conn, "DROP TABLE mytable")
            ibm_db.exec_immediate(conn, "DROP TABLE mytable2")
            except:
                pass

            #create table tabmany
            ibm_db.exec_immediate(conn, "CREATE TABLE mytable (col1 "\
              "INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY "\
              "(START WITH 1), col2 VARCHAR(30), PRIMARY KEY (col1))")                       
            ibm_db.exec_immediate(conn, "CREATE TABLE mytable2 (col1 "\
              "INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START "\
              "WITH 1), col2 VARCHAR(30), col3 INTEGER, PRIMARY KEY (col1),"\
              " FOREIGN KEY(col3) REFERENCES mytable (col1))")

            #Populate the tabmany table with execute_many
            insert = "INSERT INTO mytable (col2) VALUES (?)"
            insert2 = "INSERT INTO mytable2 (col1, col3) VALUES (?, ?)"
            params = (('a',), ('a',), ('b',), ('b',),)
            stmt_insert = ibm_db.prepare(conn, insert)
            ibm_db.execute_many(stmt_insert, params)
            #check the number of rows inserted
            row_count = ibm_db.num_rows(stmt_insert)
            print row_count

            # chaeck the inserted columns                      
            #populate the tabmany table 
            params = ((3, 'b1'), (4, 'b2'))
            try:                                              
                stmt_insert = ibm_db.prepare(conn, insert2)                
                ibm_db.execute_many(stmt_insert, params)
            except Exception, inst:
                #check the no. of rows inserted successfully
                # row_count = ibm_db.num_rows(stmt_insert)
                #check the exception raised by execute_many API
                print inst
                # print row_count
            ibm_db.close(conn)

        else:
            print ibm_db.conn_errormsg()

What is the expected output? What do you see instead?

When inserting values into mytable2 which having no reference value on foreign 
key, it should produce error message instead of crash.

Please use labels and text to provide additional information.

* ibm_db-1.0.5
* Python 2.6
* Windows 32 bit

Original issue reported on code.google.com by jazlee on 5 Oct 2011 at 4:41

GoogleCodeExporter commented 9 years ago

Original comment by jazlee on 9 Oct 2011 at 12:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi jaimy,
 The segmentation fault is coming not due to reference value on foreign key, it is coming due to you are trying to insert string values('b1', 'b2') in INTEGER field(col3 field of mytable2 table).

In any case this API should not raise segmentation field. I am investigating 
this issue and will update you once i find the solution.

Please let me know if this issue is critical for you and blocking you somewhere.

Original comment by rahul.pr...@in.ibm.com on 10 Oct 2011 at 8:14

GoogleCodeExporter commented 9 years ago
not too critical, I found this when testing the ibm_db_sa with default 
sqlalchemy test suite. mainly it was due to improper finalization to drop 
tables used on previous tests done by those suite.

Original comment by jazlee on 11 Oct 2011 at 3:39

GoogleCodeExporter commented 9 years ago
Hi Jaimy,
 I have investigated the issue and found that segmentation fault cames due to underlined CLI ODBC driver issue. 

 I have an workaround through which we can avoid the segmentation fault. 
 If transaction is in autocommit mode than only the segmentation fault is coming so if we remove the autocommit mode during the execution of execute_many() then segmentation fault will not come. You can manage the tansaction manualy to avoid this or use the patch of ibm_db_dbi.py which i have created for this issue. 
 Download the modified copy ibm_db_dbi.py from attachment and replace the existing working copy of ibm_db_dbi.py with downloaded one.

 I have created a defect against the CLI but a customer created defect will resolve more quickly. So, if you have valid DB2 license then please open a PMR to get it resolve more quickly.

please let me know after creating PMR.

Original comment by rahul.pr...@in.ibm.com on 19 Oct 2011 at 6:42

Attachments:

GoogleCodeExporter commented 9 years ago
Sadly, the only valid license we did have was DB2 for iSeries, though they were 
still on DB2 family I believe this were out of context of CLI ODBC driver. for 
DB2 UDB, I did use the Express edition, mainly for development only, while for 
production purpose we use AS/400.

Original comment by jazlee on 18 Nov 2011 at 1:48

GoogleCodeExporter commented 9 years ago
The above patch is now the part of the mainstream ibm_db driver, and have been 
released with ibm_db-1.0.6.

The above cli defect is the part DB2 v97fp6 so, it will get release with 
DB2v97fp6.

Original comment by rahul.pr...@in.ibm.com on 25 May 2012 at 7:00