my 'College' model data is :
my str_loader.py is :
class MySQLExporter(bulkloader.Exporter):
def output_entities(self, entity_generator):
conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
c = conn.cursor()
for entity in entity_generator:
c.execute("INSERT INTO haha (a,b) VALUES (%s, %s)",
(entity['cid'], entity['name']))
class Mysql_download(MySQLExporter):
def __init__(self):
MySQLExporter.__init__(self,'College',
[
('cid', str,None),
('name', lambda x: unicode(x, 'utf8'),None),
])
exporters = [Mysql_download]
and it running successful :
but it is not insert data to mysql :
thanks
updated
it is ok now :
class MySQLExporter(bulkloader.Exporter):
def output_entities(self, entity_generator):
conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
c = conn.cursor()
for entity in entity_generator:
c.execute("INSERT INTO haha (a,b) VALUES (%s, %s)",
(entity['cid'], entity['name']))
conn.commit()