Skip to content
Snippets Groups Projects
Commit 004f4690 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add mysql convertor to avoid "bytearray" strings from mysql driver

Former-commit-id: 64c85ed8155a7034a145bc99b364c1f68a623def
parent 8efe9f64
No related branches found
No related tags found
No related merge requests found
22fcf51cee85dcecd7c0de2fecdd0852abb2ce71
\ No newline at end of file
2b15950995d163e68e50e2aabf1b4e9a4ff2dfeb
\ No newline at end of file
......@@ -9,6 +9,18 @@ from ippidb.models import Bibliography, Protein, Taxonomy, MolecularFunction, \
Domain, ProteinDomainBoundComplex, ProteinDomainPartnerComplex, Symmetry, Ppi, PpiComplex, Disease, \
Compound, MDDRCompoundImport, MDDRActivityClass
class MyConverter(mysql.connector.conversion.MySQLConverter):
def row_to_python(self, row, fields):
row = super(MyConverter, self).row_to_python(row, fields)
def to_unicode(col):
if type(col) == bytearray:
return col.decode('utf-8')
return col
return[to_unicode(col) for col in row]
class Command(BaseCommand):
help = "Import data from the local v1 database"
......@@ -73,7 +85,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
conn = mysql.connector.connect(host="localhost",user="root",password="ippidb", database="ippidb")
conn = mysql.connector.connect(converter_class=MyConverter, host="localhost", user="root", password="ippidb", database="ippidb")
cursor = conn.cursor()
if options['bibliographies']:
cursor.execute("""SELECT * FROM biblio""")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment