views:

25

answers:

1

my 'College' model data is :

alt text

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 :

alt text

but it is not insert data to mysql :

alt text

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() 
+1  A: 

Try calling .commit() on the connection after loading the entities.

Nick Johnson
Nick, so cool ..
zjm1126