On Tuesday 27 May 2008 10:06:37 pm Jorge Mota wrote:
> Someone have a idea to try for this problem ?
>
> The only way encountered is use Str and encode.
>
> Best regards.
>
> On 5/23/08, Jorge Mota <[EMAIL PROTECTED]> wrote:
> > Ok I cannot use str.
> >
> > But your script is different approach that in app
> >
> > put this at dException:
> >
> > class DBQueryException(DatabaseException):
> > def __init__(self, err, sql):
> > print type(err)
> > self.sql = sql
> > self.err_desc = err
> > def __str__(self):
> > return self.err_desc + '\nSQL: ' + self.sql
> >
> > try it with a dabo application that fail with triggers, type return:
> >
> > <class 'pymssql.DatabaseError'>
> >
> > in your script return
> >
> > <type 'str'>
> >
> > and with your string no fail, with str() get same type of var and no
> > fail.
> >
> > Is pymssql.DatabaseError with bad encoding ?
> >
> > Best regards
> >
> > On 5/23/08, Ed Leafe <[EMAIL PROTECTED]> wrote:
> >> On May 23, 2008, at 7:38 PM, Jorge Mota wrote:
> >> > Right now the only way to avoid this error is assign err to a local
> >> > variable
> >> > before and use "decode"
> >> >
> >> > class DBQueryException(DatabaseException):
> >> > def __init__(self, err, sql):
> >> > self.sql = sql.lower()
> >> > errMsg= str(err)
> >> > self.err_desc =errMsg.decode('utf-8','ignore')
> >> > def __str__(self):
> >> > return self.err_desc + '\nSQL: ' + self.sql
> >>
> >> I wrote a small script:
> >>
> >> #!/usr/bin/env python
> >> # -*- coding: utf-8 -*-
> >> from dabo.dException import DBQueryException
> >> x= DBQueryException("Error Message: øüé", "select foo from bar")
> >> print x
> >>
> >> ...and it runs without a problem. It simulates what would happen
> >> when
> >> the framework receives a database error containing non-ASCII
> >> characters; in this case, using a default UTF-8 encoding.
> >>
> >> I'm concerned about your use of str(err) above. If 'err' is a
> >> unicode
> >> value, casting it to a string without an encoding specified can cause
> >> lots of those painful unicode bugs.
> >>
> >>
> >> -- Ed Leafe
let's go over what we know.
DBQueryException() will accept unicode. So you suspect that pymssql.py is the
issue. Have you tested pymssql?
something like
import pymssql
con =
pymssql.connect(host='servername',user='sa',password='master',database='Northwind'
)
cur=con.cursor()
cur.execute("select lastname, firstname, employeeid from employees where
lastname = %s" % '\'Fuller\'')
And check to see if you get the error.
--
John Fabiani
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]