By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

Re: Problems Writing =?UTF-8?B?wqMgKHBvdW5kIHN0ZXJsaW5nKSBUbyBNUw==?==?UTF-8?B?IFNRTCBTZXJ2ZXIgdXNpbmcgcHltc3NxbA==?=

P: n/a
Darren Mansell wrote:

I'm relatively new to python so please be gentle :)

I'm trying to write a £ symbol to an MS SQL server using pymsssql . This
works but when selecting the data back (e.g. using SQL management
studio) the £ symbol is replaced with £ (latin capital letter A with

This is a bit of a non-answer but... use pyodbc[*],
use NVARCHAR cols, and use unicode values on insert:

import pyodbc
import unicodedata

db = pyodbc.connect (r"Driver={SQL Server};Server=SVR17;Database=TDI;TrustedConnectio n=Yes")

db.execute ("CREATE TABLE b (x NVARCHAR (1))")
db.execute ("INSERT INTO b (x) VALUES (?)", ['£'])
db.execute ("INSERT INTO b (x) VALUES (?)", [u'£'])
db.execute ("COMMIT")

for x, in db.execute ("SELECT x FROM b"):
print repr (x), (x[0])


[*] Don't know if it's strictly necessary, but I gave up
on pymssql a while back when it had issues with unicode and
was using the ntwdblib which is more-and-more unsupported.

Nov 17 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.