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).
I can reproduce it like so:
>>con = pymssql.connect (host='testdb', user='testuser' ,password='pass word',database= 'test') sql = "insert into table_1 values ('£')" cur.execute(s ql) con.commit( ) sql = "insert into table_1 values ('1')" cur.execute(s ql) con.commit( ) sql = "select * from table_1" cur.execute(s ql) cur.fetchall( )
[('\xc2\xa3',), ('1',)]
If I insert a £ symbol in using SQL management studio then select it back from Python I get this:
[('\xc2\xa3',), ('1',), ('\xa3',)]
If I look in SQL management studio it says this:
£
for the inserts I do through Python/pymssql.
Does anyone have any ideas whats happening and how to fix it?
Thanks
--
Darren Mansell <da************ @opengi.co.uk> 1 3418
On Nov 17, 2:52*pm, Darren Mansell <darren.mans... @opengi.co.uk>
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).
I can reproduce it like so:
>con = pymssql.connect (host='testdb', user='testuser' ,password='pass word',database= 'test') sql = "insert into table_1 values ('£')" cur.execute(sq l) con.commit() sql = "insert into table_1 values ('1')" cur.execute(sq l) con.commit() sql = "select * from table_1" cur.execute(sq l) cur.fetchall ()
[('\xc2\xa3',), ('1',)]
If I insert a £ symbol in using SQL management studio then select it back from Python I get this:
[('\xc2\xa3',), ('1',), ('\xa3',)]
If I look in SQL management studio it says this:
£
for the inserts I do through Python/pymssql.
Does anyone have any ideas whats happening and how to fix it?
Thanks
I recommend that you work with Unicode wherever possible. If pymssql
can't handle Unicode then use UTF-8 when talking to it. The result
should look something like this:
>>con = pymssql.connect (host='testdb', user='testuser' ,password='pass word',database= 'test') sql = u"insert into table_1 values ('£')".encode(" utf-8") cur.execute(s ql) con.commit( ) sql = u"insert into table_1 values ('1')".encode(" utf-8") cur.execute(s ql) con.commit( ) sql = u"select * from table_1".encode ("utf-8") cur.execute(s ql) result = cur.fetchall() result
[('\xc2\xa3',), ('1',)]
You'll then need to decode from UTF-8:
>>[tuple(field.dec ode("utf-8") for field in row) for row in result]
[(u'\xa3',), (u'1',)]
>>print u'\xa3'
£ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kristian Nybo |
last post by:
Hi,
I'm writing a simple image file exporter as part of a school project. To
implement my image format of choice I need to work with big-endian
bytes, where 'byte' of course means '8 bits', not 'sizeof(char)'. It
seems that I could use bitset<8> to represent a byte in my code --- if
you have a better suggestion, I welcome it --- but that still leaves me
with the question of how to write those bitsets to an image file as
big-endian bytes...
|
by: Eigenvector |
last post by:
I've been dinking around with this code for a while now and I can't seem to
figure out where the problem lies. The original problem was that I for some
reason or another couldn't allocate few 80,000,000 element arrays. Normally
that shouldn't be a problem but it was. So I tried to do some calloc calls
and everything went south from there.
Essentially I'm trying to read in a big file, stick each line into an array,
then from then on do...
|
by: Jason Curl |
last post by:
Dear C group,
I'm very interested in writing portable C, but I only have GNU, Sparc
and Cygwin to compile on.
What I find is the biggest problem to writing portable C is what headers
to include. What sites do people know about that are comprehensive in
their differences?
For example, MacOSX complained about <string.h>. With Solaris I needed
|
by: HNguyen |
last post by:
Hi,
I have a Web application in ASP.NET. My Application allows the users upload
files into the server after checking their user names and passwords. For
each transaction, the Web program will write the information about user
name, filename upload, filesize, date and time of uploading into the log
file. (The name of the log file is constructed by Current Year and Current
Month in my program). Is there any problems with writing into the...
|
by: =?UTF-8?B?SmVucyBNw7xsbGVy?= |
last post by:
(I also posted this to boost-user)
The BGL implementation of breadth-first search uses a dedicated color map.
I had the following idea: Some algorithms don't need to distinguish
black/gray, but have an unused value in e.g. a distance map, e.g. -1, to
which the map can be initialised.
So I tried to write a map adapter which can be passed such a map
together with the value indicating "white". This adapter will return
| |
by: Dr J R Stockton |
last post by:
(A) Some of us in the UK will have been watching with amusement what
seems to be happening in the USA and its Northern Sidekick with regard
to the change in DST rules.
I've discovered that the change will also be happening in the Bahamas
(Commonwealth), Bermuda and Turks & Caicos (British Overseas
Territories) - I wonder whether anyone told Her Majesty?
(B) Date Validation - ISTM that using D = new Date(y, m', d) then
|
by: rn5a |
last post by:
The date in my local machine is set to the dd/MM/yyyy format. When I
insert a date in a MS-Access DB table, it gets populated in the above
format. For e.g. if the date is, say, 8th March 2007, it gets
populated in the DB table as
08/03/2007
In other words, first the day is shown, then the month & finally the
year but when I retrieve it in ASP.NET & using DatePart, try to
extract the day & the month like this (assume that the date...
|
by: akilascartas |
last post by:
Hello all,
I have been facing a problem for several weeks with my C++ code. First of all, I am going to expose how my files/classes are written:
File ./SimulationManager/Simulation.h (with Simulation.cc in the same location, defining the functions)
Classes:
IControlSimulation (virtual)
InputSimulation : IControlSimulation -->contains a reference to IOutput (through InputSimulation, SimulationEvents and OutputManager)
|
by: tanmay |
last post by:
please tell me how to get the following output using loops...
1) *
* *
* * *
* * * *
* * *
* *
*
|
by: jacob navia |
last post by:
As many people know, I think that garbage collection is a good
solution for many memory allocation problems.
I am aware however, that nothing is "the silver bullet", not
even the GC.
A recent article in slashdot
http://developers.slashdot.org/article.pl?sid=07/11/17/0552247
proves that.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |