當前位置: 首頁>>代碼示例>>Python>>正文


Python DBManager.executeSQL方法代碼示例

本文整理匯總了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,
#.........這裏部分代碼省略.........
開發者ID:shinnyht,項目名稱:SoXSearch,代碼行數:103,代碼來源:nodelistMaker.py


注:本文中的DBManager.DBManager.executeSQL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。