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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Golden

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

    Darren Mansell wrote:
    Hi.
    >
    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
    circumflex).

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

    <code>
    import pyodbc
    import unicodedata

    db = pyodbc.connect (r"Driver={SQ L Server};Server= SVR17;Database= TDI;TrustedConn ection=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), unicodedata.nam e (x[0])

    </code>

    [*] 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.

    TJG
Working...