nasihere / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Null value converts to python None and when used for update converts to string 'None' #316

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Fetch the value of a varchar2 column that has Null as its current value.

2. Use the fetched value to update any table's column.

What is the expected output? What do you see instead?
Instead of updating to Null, the table column gets updated to a string value of 
'None'

What version of the product are you using? On what operating system?
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on 
win32
cx_Oracle - 5.1.2
Oracle 11G

Please provide any additional information below.

This could be because in the update query, I am using '%s' format....for example

cursor.execute("UPDATE EMP SET NAME='%s'" %(None))

But there is no other way. If i simply use

cursor.execute("UPDATE EMP SET NAME=%s" %(None)) then I get a syntax error.

There should be a way to update a column to NULL

Original issue reported on code.google.com by anurag.c...@gmail.com on 1 Apr 2013 at 6:56

GoogleCodeExporter commented 8 years ago
Use parameters instead:
  cursor.execute("UPDATE EMP SET NAME=?", (None, ))

Original comment by jtas...@gmail.com on 30 Apr 2013 at 7:09

GoogleCodeExporter commented 8 years ago
I'm using pyodbc to query Teradata database from a Linux machine.

I'm having some other issues when selecting a column with NULL values. 
If an integer is the next selected columns, it corrupts the data and returns 
some garbage value. 

I think it only happens when the NULL column is of type Date.

Any idea what should cause this issue and how to fix it?

Original comment by david.tz...@gmail.com on 24 Nov 2014 at 10:00