I am seeing different outcomes from simple requests against a common database
when run from a freebsd machine and a win32 box.
The test script is
############### ########
import MySQLdb, sys
print sys.version
print MySQLdb.__versi on__
db=MySQLdb.conn ect(host='appx' ,db='sc_0',user ='user',passwd= 'secret',use_un icode=True)
cur=db.cursor()
cur.execute('se lect * from sc_accomodation where id=31')
data=cur.fetcha ll()
for i,t in enumerate(data[0]):
if isinstance(t,(s tr,unicode)): print i,repr(t)
############### ########
The table in question is charset='latin1 ', however the original owners put some
special windows characters in eg 0x92 (a quote).
in the windows version I see this kind of string in the output
2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
1.2.1_p2
..........
14 u'Built entirely of mahogany, Acajou seeks to introduce a new concept of
living in the midst of nature on the C\xf4te d\x92Or beach which stretches
along the island\x92s northern coast.\r\n\r\nT he hotel\x92s 24 standard
and 4 superior ro........
the freeBSD machine produces
2.4.3 (#2, Sep 7 2006, 09:34:29)
[GCC 3.4.4 [FreeBSD] 20050518]
............
14 u'Built entirely of mahogany, Acajou seeks to introduce a new concept of
living in the midst of nature on the C\xf4te d\u2019Or beach which stretches
along the island\u2019s northern coast.\r\n\r\nT he hotel\u2019s 24 standard
and 4 superior rooms.......
so the windows version seems to leave the \x92 as is and the freebsd version
converts it to its correct value.
This is already bad enough as I expected the outcomes to be the same, but given
that the encoding of the database is wrong I expected some problems.
However, if I don't have use_unicode=Tru e in the above script I get back
strings, but this time the difference is larger.
windows
2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)]
1.2.1_p2
........
2 "C\xf4te d'Or\r\nPraslin "
........
unix
2.4.3 (#2, Sep 7 2006, 09:34:29)
[GCC 3.4.4 [FreeBSD] 20050518]
1.2.1_p2
.......
2 "C\xc3\xb4t e d'Or\r\nPraslin "
........
so here the returned string appears to have been automatically converted to utf8.
My questions are
1) why the difference in the unicode version?
2) why does the unix version convert to utf8?
The database being common it seems it's either the underlying libraries or the
compiled extension or python that causes these differences, but which?
--
Robin Becker 3 2877
Try:
db=MySQLdb.conn ect(host='appx' ,db='sc_0',user ='user',passwd= 'secret',
use_unicode=Tru e, charset = "utf8")
The distinction is that "use_unicod e" tells Python to convert to Unicode,
but Python doesn't know the MySQL table type. 'charset="utf8" ' tells
MySQL to do the conversion to UTF8, which can be reliably converted
to Unicode.
John Nagle
Robin Becker wrote:
I am seeing different outcomes from simple requests against a common
database when run from a freebsd machine and a win32 box.
The test script is
....
db=MySQLdb.conn ect(host='appx' ,db='sc_0',user ='user',passwd= 'secret',use_un icode=True)
John Nagle wrote:
Try:
db=MySQLdb.conn ect(host='appx' ,db='sc_0',user ='user',passwd= 'secret',
use_unicode=Tru e, charset = "utf8")
The distinction is that "use_unicod e" tells Python to convert to Unicode,
but Python doesn't know the MySQL table type. 'charset="utf8" ' tells
MySQL to do the conversion to UTF8, which can be reliably converted
to Unicode.
John Nagle
.......
OK that seems to help. However, my database has tables with different
encodings. Does MySQLdb ignore the table encoding? That would be a bit lame.
Also it still doesn't explain the different behaviours between unix &
win32 (or perhaps different defaults are somehow magically decided upon).
-things were so much easier when bytes were bytes-ly yrs-
Robin Becker
Robin Becker wrote:
John Nagle wrote:
>Try:
db=MySQLdb.conn ect(host='appx' ,db='sc_0',user ='user',passwd= 'secret', use_unicode=Tru e, charset = "utf8")
The distinction is that "use_unicod e" tells Python to convert to Unicode, but Python doesn't know the MySQL table type. 'charset="utf8" ' tells MySQL to do the conversion to UTF8, which can be reliably converted to Unicode.
John Nagle
.......
OK that seems to help. However, my database has tables with different
encodings. Does MySQLdb ignore the table encoding? That would be a bit
lame.
MySQLdb, the client, doesn't know the table encoding. The
server end does.
Also it still doesn't explain the different behaviours between unix &
win32 (or perhaps different defaults are somehow magically decided upon).
The default encoding is an environment thing. It comes, somehow, from
the locale your system thinks it is in.
-things were so much easier when bytes were bytes-ly yrs-
Robin Becker
So convert the database to Unicode/UTF-8 and have everything
be consistent. MySQL 5 can do that dynamically with an ALTER
TABLE statement.
John Nagle This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave Harrison |
last post by:
Hi all, got a problem combinging mx and MySQLdb, when I build and install both for my Python2.1 install on a Solaris 9 box I can import mx fine, but importing MySQLdb causing python to core dump.
I am using egenenix 2.0.4 and MySQLdb 0.9.2.
I have also replaced the -shared flag in the Makefile is /usr/local/lib/Python2.1/config with -G (a recommended solaris change to let the build of the modules work in the first place) -> notably I also...
|
by: Peter Nikolaidis |
last post by:
Greetings,
I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a
Fink distribution of Python 2.2.2. I have seen only a few posts on the
subject, some of them relate to "conflicting header files," but I don't
know what to do about conflicting header files, or where I would find
them, and once I found them, which ones to remove.
I have compiled MySQL 4.1 and installed into /usr/local/mysql, but
since have moved to a Fink...
|
by: Tim Williams |
last post by:
I'm trying to write a simple python program to access a MySQL
database. I'm having a problem with using MySQLdb to get the results
of a SQL command in a cursor. Sometimes the cursor.execute works,
sometimes not.
From mysql:
mysql> show databases;
+-----------+
| Database |
|
by: T. Kaufmann |
last post by:
Hi,
RDBMS MySQL works fine on my machine. I want to install MySQL-python
1.0.0 under Red Hat 9.0.
>>> platform.platform()
'Linux-2.4.20-8-i686-with-redhat-9-Shrike'
There are some problems. If I call python
|
by: ws Wang |
last post by:
MySQLdb is working fine at command line, however when I tried to use
it with mod_python, it give me a "server not initialized" error.
This is working fine:
----------------------- testmy.py -------------------------------
#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root", passwd="mypass",
db="my_db")
cursor = db.cursor()
| |
by: Steve |
last post by:
Darwin steve.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3
20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh
powerpc
MacOSX 10.4.3
mysql Ver 14.7 Distrib 4.1.14, for apple-darwin8.2.0 (powerpc) using
readline 4.3
runing the software gives me
steve:~/MySQL-python-1.2.0 steve$ python setup.py build
|
by: Mondal |
last post by:
Hi,
I am using MySQL 5.0 beta and Active Python 2.4. I have the correct
version of MySQLdb installed. The problem is that I can't connect to
MySQL through the Active Python interactive window.
Here is a sample error:
>>> c=MySQLdb.Connect(host='localhost',user='root',passwd='',db='shop',port=3306)
Traceback (most recent call last):
|
by: Yi Xing |
last post by:
Hi,
I met the following error when I tried to install MySQLdb. I had no
problem installing numarray, Numeric, Rpy, etc. Does anyone know
what's the problem? Thanks!
running install
running build
running build_py
creating build
|
by: Tommy Grav |
last post by:
I am trying to install mysqldb-1.2.2 on my PPC running 10.5.2 and
Activepython 2.5.1.1
when I get this error:
running build
running build_py
copying MySQLdb/release.py -build/lib.macosx-10.3-fat-2.5/MySQLdb
running build_ext
building '_mysql' extension
gcc -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: 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...
| |