witten
/
luminotes
Archived
1
0
Fork 0

Converting strings pulled out of the database from utf8 to unicode.

This commit is contained in:
Dan Helfman 2007-10-11 11:06:50 +00:00
parent a11ba8661b
commit b71b12fe50
1 changed files with 10 additions and 3 deletions

View File

@ -97,7 +97,8 @@ class Database( object ):
cursor.execute( sql_command )
row = cursor.fetchone()
row = self.__row_to_unicode( cursor.fetchone() )
print row
if not row:
return None
@ -124,7 +125,7 @@ class Database( object ):
cursor.execute( sql_command )
objects = []
row = cursor.fetchone()
row = self.__row_to_unicode( cursor.fetchone() )
while row:
if Object_type in ( tuple, list ):
@ -133,10 +134,16 @@ class Database( object ):
obj = Object_type( *row )
objects.append( obj )
row = cursor.fetchone()
row = self.__row_to_unicode( cursor.fetchone() )
return objects
def __row_to_unicode( self, row ):
if row is None:
return None
return [ isinstance( item, str ) and unicode( item, encoding = "utf8" ) or item for item in row ]
def execute( self, sql_command, commit = True ):
"""
Execute the given sql_command.