Re: [Tutor] pgdb and unicode

2007-10-22 Thread Ismael Farfán Estrada

>Ismael Farfán Estrada wrote:
>> Hi there.
>> I have a small system in production with wxPython and PostgreSQL running on
>> a machine with Centos 5.
>> At first everytihing was running ok but now a weird bug was discovered:
>> they can't insert characters like á é í ó ú ä ë ñ  (non english 
>> characters)
>> Does anyone knows how can I make pgdb accept that kind of characters?
>> I wrote a little script...
>> 
>> But first
>> CREATE DATABASE test;
>> CREATE TABLE tabla(
>> cad character varying
>> ) ;
>> 
>> #!/usr/bin/python
>> # -*- coding: utf8 -*-
>> import pgdb
>> con = pgdb.connect(user="farfan", password='00', host='localhost', 
>> database='test')
>> cur = con.cursor()
>> cur.execute("INSERT INTO tabla VALUES ('é')")
>> con.commit()
>> cur.execute(u"INSERT INTO tabla VALUES ('é')")
>> con.commit()
>> 
>> As you can see, the first insert statement is executed in ascii format and 
>> is succeful,
>> the second, which is in Unicode, fails
>
>Why do you need the whole statement to be Unicode? It looks like the 
>database wants utf-8. Probably you should encode the data as utf-8 first.
>
>> the problem is thas wxPython will allways send the script in unicode 
>> format...
>
>What is coming from wxPython? I guess it is just the data value, not the 
>SQL statement or the entire script. Try something like
>
>data= u'é' # Unicode data from wxPython
>data = data.encode('utf-8')
>cur.execute('INSERT INTO tabla VALUES (%s)', [data])

Tanks, that did the trick:
data = []
data.append(self.marca.GetLineText(0))#.encode('utf-8'))
sql = "INSERT INTO Marca (marca) VALUES (%s);"
cur.execute(sql, data)

>
>Note I am passing the data as a separate list, not using string 
>interpolation. Let the database worry about quoting, etc.
>
>Kent

It seems that just by sending the data in a list fixed the problem
though adding the encode doesn't harm either ...
I'll have to make a looot of changes.

by the way, does sending the data as a list prevent SQL injection?
I haven't worried for that yet.

_
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pgdb and unicode

2007-10-22 Thread Ismael Farfán Estrada

Hi there.
I have a small system in production with wxPython and PostgreSQL running on
a machine with Centos 5.
At first everytihing was running ok but now a weird bug was discovered:
they can't insert characters like á é í ó ú ä ë ñ  (non english characters)
Does anyone knows how can I make pgdb accept that kind of characters?
I wrote a little script...

But first
CREATE DATABASE test;
CREATE TABLE tabla(
  cad character varying
) ;

#!/usr/bin/python
# -*- coding: utf8 -*-
import pgdb
con = pgdb.connect(user="farfan", password='00', host='localhost', 
database='test')
cur = con.cursor()
cur.execute("INSERT INTO tabla VALUES ('é')")
con.commit()
cur.execute(u"INSERT INTO tabla VALUES ('é')")
con.commit()

and this is the result

python Aplicacion.py
Traceback (most recent call last):
  File "Aplicacion.py", line 10, in ?
cur.execute(u"INSERT INTO tabla VALUES ('é')")
  File "/usr/lib/python2.4/site-packages/pgdb.py", line 175, in execute
self.executemany(operation, (params,))
  File "/usr/lib/python2.4/site-packages/pgdb.py", line 198, in executemany
raise OperationalError, "internal error in '%s': %s" % (sql,err)
[EMAIL PROTECTED] ~]$ python Aplicacion.py
Traceback (most recent call last):
  File "Aplicacion.py", line 8, in ?
cur.execute(u"INSERT INTO tabla VALUES ('é')")
  File "/usr/lib/python2.4/site-packages/pgdb.py", line 175, in execute
self.executemany(operation, (params,))
  File "/usr/lib/python2.4/site-packages/pgdb.py", line 198, in executemany
raise OperationalError, "internal error in '%s': %s" % (sql,err)
pg.OperationalError

As you can see, the first insert statement is executed in ascii format and is 
succeful,
the second, which is in Unicode, fails

the problem is thas wxPython will allways send the script in unicode format...

any ideas on how to fix it?


rb3m dijo: Un buen programador no es uno que se sepa un lenguaje al derecho y 
al revés, sino el que sabe resolver un problema y después implementar la 
solución en el lenguaje más adecuado.

_
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] howto call DOM with python

2007-03-02 Thread Ismael Farfán Estrada
>
>I don't think you can make it work under Linux. The Jython applet
>is your nearest option. You will be better learing the ninimum of
>JavaScript IMHO. Try my tutorial as a quickl way in, especially
>if you know Python...
>
>Finally, you may be able to do what you want using the urllib
>module to replace the browser entirely!
>
>http://www.freenetpages.co.uk/hp/alan.gauld
>

By any chance is this your tutorial?
http://www.freenetpages.co.uk/hp/alan.gauld
I entered there but the parts "Writing web clients" and "Writing
Web Applications" are dissabled

Maybe you can send the direct ling to how to use that jython
applet, I'll give it a try. And now that we are here mabe a tutorial
for DOM to, I entered to the page of DOM but I found no
downloadable tutorial or a reference manual


Tanks for your time

_
Te gusta estar en control, crea tu propia experiencia en Internet 
http://live.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] howto call DOM with python

2007-02-28 Thread Ismael Farfán Estrada
hi there

I was wondering wheter someone knows how to use python to write
a client-side scripts like if it were java, I want to get someting like
this working


window.alert("python")



but nothing happens. I don't know javascript but this code works
if I put javascript instead of python, I've also tried with pythonscript
python-source, etc

hope you can help me, I'm using GNU/Suse, Opera, and Firefox for test

_
El mejor destino, con los mejores contenidos http://www.prodigy.msn.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor