本文整理汇总了Python中DBManager.DBManager.executeSQL方法的典型用法代码示例。如果您正苦于以下问题:Python DBManager.executeSQL方法的具体用法?Python DBManager.executeSQL怎么用?Python DBManager.executeSQL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBManager.DBManager
的用法示例。
在下文中一共展示了DBManager.executeSQL方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from DBManager import DBManager [as 别名]
# 或者: from DBManager.DBManager import executeSQL [as 别名]
class NodeListMaker:
def __init__(self, host, db, user, passwd, charset):
self.data_extractor = Extractor()
self.data_manager = DBManager(
host, db, user, passwd, charset
)
def assortData(self):
self.data_manager.EstablishDBConnection()
# fetch all records from ofPubsubItem table
all_data = self.data_manager.fetchRecords(
"select serviceID,nodeID,id,payload \
from ofPubsubItem;"
)
# assort records in table
for data in all_data:
nodeID = data[1].encode("utf-8")
# execute when record was metadata record
if nodeID.rfind("_meta") > -1:
self.insertNodeListMetaDB(data)
# execute when record was data record
elif nodeID.rfind("_data") > -1:
self.insertNodeListDataDB(data)
self.data_manager.CloseDBConnection()
def junctionDB(self):
self.data_manager.EstablishDBConnection()
# fetch all records from nodelist_data table
all_data = self.data_manager.fetchRecords(
"select serviceID,nodeID,id,X(latlng),Y(latlng) \
from nodelist_data;"
)
meta_data = None
try:
for data in all_data:
nodeID = data[1].encode("utf-8")
# fetch record with certain nodeID
meta_data = self.data_manager.fetchSingleRecords(
"select type from nodelist_meta \
where nodeID='" + nodeID + "';"
)
# set datatype if exists
if meta_data:
datatype = meta_data[0]
# set datatype "other" if none exists
else:
datatype = "other"
# insert new record into nodelist table
self.insertNodeListDB(data, datatype)
self.data_manager.CloseDBConnection()
except Exception as e:
print e
def insertNodeListDB(self, data, datatype):
serviceID = data[0]
nodeID = data[1].encode("utf-8")
ID = data[2]
location = {
"lat": data[3],
"lng": data[4]
}
# generate SQL statement for nodelist table
sql = self.data_manager.generateSQLStatement(
"nodelist",
serviceID,
nodeID,
ID,
datatype,
location
)
self.data_manager.executeSQL(sql)
def insertNodeListMetaDB(self, data):
serviceID = data[0]
nodeID = data[1].encode("utf-8").replace("_meta", "")
ID = data[2]
payload = self.fixPayload(data[3].encode("utf-8"))
# extract datatype from given payload
datatype = self.data_extractor.extractDataType(payload)
# generate SQL statement for nodelist_meta table
sql = self.data_manager.generateSQLStatement(
"nodelist_meta",
serviceID,
nodeID,
#.........这里部分代码省略.........