473,468 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unicode and mysql

Hi all,

I'm having a problem inserting into a mysql database (its not the mysql, its
the encoding of the query sting), could someone point me in the
right direction. The code resembles the following:

text1=hdtext.encode("utf-8") #this is acquired earlier in the script
string1="just testing"

#this first one would work fine
cursor.execute("insert into table1 (col1) values (%s)" %(text1))
#the next one works too
cursor.execute("insert into table1 (col2) values ('%s')" %(string1))

#however what i need to work is the following
cursor.execute("insert into table1 (col1,col2) values (%s,'%s')"
% (text1,string1)
Thanks,
Ilya


Jul 18 '05 #1
1 1837

Ilya> I'm having a problem inserting into a mysql database (its not the
Ilya> mysql, its the encoding of the query sting), could someone point
Ilya> me in the right direction. The code resembles the following:

Ilya> text1=hdtext.encode("utf-8") #this is acquired earlier in the script
Ilya> string1="just testing"

Ilya> #this first one would work fine
Ilya> cursor.execute("insert into table1 (col1) values (%s)" %(text1))
Ilya> #the next one works too
Ilya> cursor.execute("insert into table1 (col2) values ('%s')" %(string1))

Ilya> #however what i need to work is the following
Ilya> cursor.execute("insert into table1 (col1,col2) values (%s,'%s')"
Ilya> % (text1,string1)

Let your database module (presumably MySQLdb) do the encoding for you:

cursor.execute("insert into table1 (col1,col2) values (%s, %s)",
(text1, string1))

Skip

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bill Eldridge | last post by:
I'm trying to grab a document off the Web and toss it into a MySQL database, but I keep running into the various encoding problems with Unicode (that aren't a problem for me with GB2312, BIG 5,...
2
by: Vincent Bouret | last post by:
Hi, I have read that Unicode (UTF-8) was not enabled by default in the mysql-4.1.0-alpha binaries. How can I enable it? What should I change in the code to do so? Thanks Vincent
0
by: Stormblade | last post by:
Hey all, I have an existing JSP web application which retrieved data from a SQLServer database and displayed it. The data contained Unicode chars. This worked fine. I changed databases/JDBC...
0
by: Andy Fish | last post by:
Hi, I have ported a .NET application which supports unicode from MS SQL Server to mysql. The .net framework itself is unicode throughout and I am using utf-8 innodb tables in mysql. When...
4
by: JJ | last post by:
Hi, usually, I'm not using MS servers, but I have a big problem with a Access table. I should create a web application for a Historical Dipartment. They have created a populated a Access...
1
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
6
by: Bill Nguyen | last post by:
I'm getting data from a mySQL database (default char set = UTF-8). I need to display data in Unicode but got only mongolian characters like this: Phạm Thị Ngọc I changed the textbox font to...
3
by: roland.saad | last post by:
Hi Everyone, I have been trying to build a website that has multilingual support using the LAMP setup. I have created tables that store language information and correlate different strings ids...
1
by: erikcw | last post by:
Hi, I'm trying to insert some data from an XML file into MySQL. However, while importing one of the files, I got this error: Traceback (most recent call last): File "wa.py", line 304, in ?...
6
by: Bill Nguyen | last post by:
Below are sometext I extracted from a mySQL database. How can I decode them so that I can read them in Unicode? Thanks Bill ------------ Virginia Hamilton Adair / Lâm Thị Mỹ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
1
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...
0
tracyyun
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.