Skip to content

Instantly share code, notes, and snippets.

@az0
Created September 18, 2014 16:07
Show Gist options
  • Save az0/1a89a166cec5d4d0a3c9 to your computer and use it in GitHub Desktop.
Save az0/1a89a166cec5d4d0a3c9 to your computer and use it in GitHub Desktop.
import os
import ceODBC
connection_string="driver=sql server;database=db;server=server;"
print connection_string
import ceODBC
conn = ceODBC.connect(connection_string)
cursor = conn.cursor()
try:
cursor.execute('drop table zzz_ceodbc_unicode')
except:
import traceback
traceback.print_exc()
create_sql="""
CREATE TABLE zzz_ceodbc_unicode (
col1 INT,
col2 NVARCHAR(50)
) """
cursor.execute(create_sql)
rows = []
rows.append((1,'abcd'))
rows.append((1,u'abcd'))
rows.append((1,u'I \u2665 unicode'))
insert_sql = 'insert into zzz_ceodbc_unicode (col1, col2) values (?,?)'
print 'inserting one at time: this works'
for row in rows:
print row
cursor.execute(insert_sql, row)
conn.commit()
print 'inserting all at once: this fails'
cursor.executemany(insert_sql, rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment