Converting strings pulled out of the database from utf8 to unicode.
This commit is contained in:
parent
a11ba8661b
commit
b71b12fe50
|
@ -97,7 +97,8 @@ class Database( object ):
|
||||||
|
|
||||||
cursor.execute( sql_command )
|
cursor.execute( sql_command )
|
||||||
|
|
||||||
row = cursor.fetchone()
|
row = self.__row_to_unicode( cursor.fetchone() )
|
||||||
|
print row
|
||||||
if not row:
|
if not row:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ class Database( object ):
|
||||||
cursor.execute( sql_command )
|
cursor.execute( sql_command )
|
||||||
|
|
||||||
objects = []
|
objects = []
|
||||||
row = cursor.fetchone()
|
row = self.__row_to_unicode( cursor.fetchone() )
|
||||||
|
|
||||||
while row:
|
while row:
|
||||||
if Object_type in ( tuple, list ):
|
if Object_type in ( tuple, list ):
|
||||||
|
@ -133,10 +134,16 @@ class Database( object ):
|
||||||
obj = Object_type( *row )
|
obj = Object_type( *row )
|
||||||
|
|
||||||
objects.append( obj )
|
objects.append( obj )
|
||||||
row = cursor.fetchone()
|
row = self.__row_to_unicode( cursor.fetchone() )
|
||||||
|
|
||||||
return objects
|
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 ):
|
def execute( self, sql_command, commit = True ):
|
||||||
"""
|
"""
|
||||||
Execute the given sql_command.
|
Execute the given sql_command.
|
||||||
|
|
Reference in New Issue