row = cur.fetchone() #the 4th field is the create sql #print row[4] sql = row[4].replace('[', '`').replace(']', '`').replace( 'autoincrement', 'auto_increment').replace('Content', tableName) tmpsql = sql.split(',') #删除已发和已采字段 del tmpsql[1:3] #重新组装sql语句 sql = ','.join(tmpsql) sql = sql.replace('名称', 'name').replace('标签', 'tags').replace( '星级', 'grade').replace('点评数', 'comment') # add new column to table sql = sql[:-2] + ",`address` Text,`lng` Text,`lat` Text )" mysqlconn = mydb.Connection(host=mysql_host, database=mysql_database, user=mysql_user, password=mysql_password) psql = "show tables like '%s'" % tableName #print psql exist = mysqlconn.query(psql) #print exist if exist == []: #create new table mysqlconn.execute(sql) else: #delete old table then create new table esql = "drop table %s" % tableName mysqlconn.execute(esql) mysqlconn.execute(sql) #get all data in sqlite
#mysqlconn=mydb.Connection(host="localhost",user="******",passwd="ronald",db="ftpoi",port=3306) #mycur=mysqlconn.cursor() #exist=mycur.execute('show tables like %s','%'+tableName+'%') #print exist ## if exist ==0: ## mycur.execute(sql) ## else: ## pass ## cur.execute('select * from Content') ## rows=cur.fetchall() ## for row in rows: ## sqlstr="insert into " + tableName + " values(%s,%s,%s,%s,%s,%s,%s,%s)" ## values=[row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]] ## cur.execute(sqlstr,values) mysqlconn = mydb.Connection(host="localhost", database="ftpoi", user="******", password="******") exist = mysqlconn.query('show tables like %s', '%' + tableName + '%') if exist == []: #create new table mysqlconn.execute(sql) else: pass mysqlconn2 = MySQLdb.Connection(host="localhost", user="******", passwd="ronald", db="ftpoi", port=3306, charset="utf8") mycur = mysqlconn2.cursor() #get all data in sqlite