当前位置: 首页>>代码示例>>Python>>正文


Python DBManager.fetchRecords方法代码示例

本文整理汇总了Python中DBManager.DBManager.fetchRecords方法的典型用法代码示例。如果您正苦于以下问题:Python DBManager.fetchRecords方法的具体用法?Python DBManager.fetchRecords怎么用?Python DBManager.fetchRecords使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBManager.DBManager的用法示例。


在下文中一共展示了DBManager.fetchRecords方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from DBManager import DBManager [as 别名]
# 或者: from DBManager.DBManager import fetchRecords [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.fetchRecords方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。