2010-06-19 35 views
0

我的 '學院' 模型數據是:如何出口GAE數據到mysql

alt text http://omploader.org/vNG9zNw

我str_loader.py是:

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] 

,它運行成功:

alt text http://omploader.org/vNG9zNA

但它沒有向mysql插入數據:

alt text http://omploader.org/vNG9zNg

感謝

更新

現在已確定:

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

嘗試調用.commit()加載實體後,連接上。

+0

Nick,so cool .. – zjm1126 2010-06-19 20:22:38