我想在ubuntu 14.04 LTS中從ubuntu 2.7.11在Azure sql server中存儲u'\ U0001f381'字符串。我已經將列類型設置爲nvarchar(MAX),以便它將接受unicode字符串。 下面是python腳本:從Unicode字符串轉義字符
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()
但我得到當我執行上面的腳本從Ubuntu的環境下面的錯誤。
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")
我從windows環境執行相同的腳本時沒有得到任何錯誤。我想我需要從Unicode字符串中跳出任何字符,但我不確定哪個字符。 請幫忙。
我試圖重複引號,但仍然我得到同樣的錯誤。我在插入表情符號時發現了這種情況。 – subhash