New file |
| | |
| | | #!/usr/bin/python
|
| | | # -*- coding: GBK -*-
|
| | |
|
| | | import datetime
|
| | |
|
| | | char_encoding = "gbk"
|
| | |
|
| | |
|
| | | def TranslteToSqlStaments( groupID, eventTypeStr, eventdataStr ):
|
| | | errorStr = "True;Translate successfully;"
|
| | | sqlStmts = ""
|
| | |
|
| | | try:
|
| | | #print eventdataStr
|
| | | #创建数据库的sql语句生成
|
| | | td = datetime.date.today()
|
| | | dbNameStr = "EventData_Group%d_%04d_%02d" % ( groupID, td.year, td.month )
|
| | | createDbStr = "create database if not exists %s default charset utf8 COLLATE utf8_general_ci;use %s;" % ( dbNameStr, dbNameStr )
|
| | | sqlStmts += createDbStr
|
| | |
|
| | | eventdict = eval( eventdataStr )
|
| | |
|
| | | tableColumnFmtStr = ""
|
| | | tableColumnStr = ""
|
| | | insertValStr = ""
|
| | | for key in eventdict.keys():
|
| | | val = eventdict[key]
|
| | | valc = type(val)
|
| | |
|
| | | typeStr = "UNKNOWN TYPE"
|
| | | if valc == type(1):
|
| | | typeStr = "INT"
|
| | | insertValStr += str(val) + ','
|
| | | elif valc == type(0.1):
|
| | | typeStr = "FLOAT"
|
| | | insertValStr += str(val) + ','
|
| | | #elif valc == type("") or valc == type({0:1}):
|
| | | else:
|
| | | typeStr = "VARCHAR(512)"
|
| | | insertValStr += '"' + str(val).decode(char_encoding).encode("utf-8") + '",'
|
| | |
|
| | | tableColumnFmtStr += key + " " + typeStr + ","
|
| | | tableColumnStr += key + ","
|
| | |
|
| | |
|
| | | tableNameStr = "%s_%04d_%02d_%02d" % ( eventTypeStr, td.year, td.month, td.day )
|
| | | createTableStr = "create table if not exists %s ( event_store_id INT NOT NULL AUTO_INCREMENT, %s, PRIMARY KEY (event_store_id) );" % ( tableNameStr, tableColumnFmtStr[0:-1] )
|
| | | sqlStmts += createTableStr
|
| | |
|
| | | insertDataStr = "insert into %s (%s) value(%s);" % ( tableNameStr, tableColumnStr[0:-1], insertValStr[0:-1] )
|
| | |
|
| | | return errorStr + sqlStmts + insertDataStr;
|
| | |
|
| | | except Exception, e:
|
| | | errorStr = "False;Failed to TranslteToSqlStaments:" + str(e) + ";"
|
| | | return errorStr + sqlStmts
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | if __name__ == '__main__':
|
| | | pass
|
| | | eventdata = "{'PlayerID': 40006, 'AccID': '155958472', 'FamilyName': '\xcc\xec\xcf\xc2\xc3\xcb', 'time': '2012-06-22 16:11:05', 'FamilyID': 334888786}"
|
| | | print TranslteToSqlStaments( 1, "DeleteItem_Add_LimitingBuff", eventdata )
|
| | |
|