2

I am trying to store u'\U0001f381' string in Azure sql server from python 2.7.11 in ubuntu 14.04 LTS. I have set the column type as nvarchar(MAX) so that it will accept unicode strings. following is the python script:

import pymssql
from creds import *
conn = pymssql.connect(host=HOST, user=USER, password=PASSWORD, database=DATABASE)
cursor = conn.cursor()

lst = [u'2017-07-04', u'\U0001f3e8', 1.0, 0.0, 0.0, 9.0]

print lst
placeholder = '%s,' * len(lst)

query = 'INSERT INTO Example_SearchAnalytics VALUES ( '+placeholder.rstrip(',')+ ')'

cursor.execute(query,tuple(lst))

conn.commit()

conn.close()

But I am getting following error when I execute above script from ubuntu environment.

pymssql.OperationalError: (105, "Unclosed quotation mark after the character string ''.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")

I don't get any error when I execute same script from windows environment. I think I need to escape any character from unicode string but I am not sure which. Please help.

Subhash Deshmukh
  • 350
  • 3
  • 18

1 Answers1

2

Repeat quotation marks or use CHAR(39) as explained on below thread:

Escaping single quote in SQL Server

Hope this helps.

Regards,

Alberto Morillo

Alberto Morillo
  • 13,893
  • 2
  • 24
  • 30