zjm1126
zjm1126

Reputation: 66637

How to Exporter gae data to MySQL?

I have a 'College' model data.

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. However, it does not insert data to MySQL.

Upvotes: 0

Views: 157

Answers (1)

Nick Johnson
Nick Johnson

Reputation: 101139

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

Upvotes: 1

Related Questions