waliwali / ibm-db

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

Prepare doesn't insert correctly int/long python types in a BIGINT column #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. db2 "create table test(a bigint)"
2. stmt = ibm_db.prepare(db,"insert into test values(?)")
3. ibm_db.execute(stmt,(9999999999999,))

What is the expected output? What do you see instead?
I expect 9999999999999
but i get
1316134911

What version of the product are you using? On what operating system?
0.4.1

Please provide any additional information below.

I write a patch for ibm_db.c
In function _python_ibm_db_bind_data
after the line  "case PYTHON_FIXNUM:"
you can add the following code:
if (curr->data_type == SQL_BIGINT) {
   PyObject *temp_str;

   temp_str =  PyObject_Str(bind_data);
   curr->svalue = PyString_AsString(temp_str);
   curr->ivalue = strlen(curr->svalue);
   curr->bind_indicator = curr->ivalue;
   curr->svalue = memcpy(ALLOC_N(char, curr->ivalue+1), curr->svalue, curr->ivalue);
   Py_DecRef(temp_str);

   curr->svalue[curr->ivalue] = '\0';
   rc = SQLBindParameter(stmt_res->hstmt, curr->param_num,
   curr->param_type, SQL_C_CHAR, curr->data_type, curr->param_size,
   curr->scale, (SQLPOINTER)(curr->svalue), curr->ivalue, &(curr->bind_indicator));
   if ( rc == SQL_ERROR ) {
      _python_ibm_db_check_sql_errors(stmt_res->hstmt, SQL_HANDLE_STMT, 
                                            rc, 1, NULL, -1, 1);
   }
   curr->data_type = SQL_C_CHAR;
   break;
}

Original issue reported on code.google.com by gtsys...@gmail.com on 22 Jan 2009 at 3:15

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,
   Thanks for identifying the problem and submitting the patch, please go through 
our wiki page http://code.google.com/p/ibm-db/wiki/Contributions to understand 
contribution process. After you sign the CLA, I will have a look at the patch. 
Please revert back if you have any concerns/issues. 
In case you don't wish to sign CLA, I will make a note of the problem and will 
rectify it in next releases.

Thanks,
Abhigyan

Original comment by abhigyan...@in.ibm.com on 28 Jan 2009 at 8:46

GoogleCodeExporter commented 9 years ago
Fixed in ibm_db-0.7.2.5

Original comment by abhigyan...@in.ibm.com on 29 Jun 2009 at 6:43