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


Python cursors.DictCursor方法代码示例

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


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

示例1: __init__

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def __init__(self, min_conn=2):
        self.__host = DATABASE_CONFIG['HOST']
        self.__user = DATABASE_CONFIG['USER']
        self.__password = DATABASE_CONFIG['PASSWORD']
        self.__database = DATABASE_CONFIG['DATABASE']
        self.__min_conn = min_conn
        self.__pool = PooledDB(
            MySQLdb,
            self.__min_conn,
            host=self.__host,
            user=self.__user,
            passwd=self.__password,
            db=self.__database,
            charset='utf8',
            use_unicode=True,
            cursorclass=DictCursor) 
开发者ID:pskun,项目名称:finance_news_analysis,代码行数:18,代码来源:mysql_pool.py

示例2: execute_sql_with_fetch

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def execute_sql_with_fetch(self, resource_name, sql, values):
        """Executes a provided sql statement with fetch.

        Args:
            resource_name (str): String of the resource name.
            sql (str): String of the sql statement.
            values (tuple): Tuple of string for sql placeholder values.

        Returns:
            list: A list of dict representing rows of sql query result.

        Raises:
            MySQLError: When an error has occured while executing the query.
        """
        try:
            cursor = self.conn.cursor(cursorclass=cursors.DictCursor)
            cursor.execute(sql, values)
            return cursor.fetchall()
        except (DataError, IntegrityError, InternalError, NotSupportedError,
                OperationalError, ProgrammingError) as e:
            raise MySQLError(resource_name, e) 
开发者ID:GoogleCloudPlatform,项目名称:forseti-security,代码行数:23,代码来源:dao.py

示例3: from_settings

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def from_settings(cls, settings):
        '''[email protected]?????????????????????????
           2??????????cls?class????????????????????????self??????????
           3????????????C.f()????java??????'''
        # ??settings?????????
        dbparams = dict(
            host=settings['MYSQL_HOST'],
            db=settings['MYSQL_DBNAME'],
            user=settings['MYSQL_USER'],
            passwd=settings['MYSQL_PASSWD'],
            charset='utf8',  # ??????????????????
            cursorclass = DictCursor,
            use_unicode=False,
        )
        dbpool = adbapi.ConnectionPool('MySQLdb', **dbparams)  # **?????????????,???host=xxx,db=yyy....
        return cls(dbpool)  # ???dbpool???????self?????

    # pipeline???? 
开发者ID:Labyrinth108,项目名称:Content-Based-News-Recommendation-System-in-Spark,代码行数:20,代码来源:pipelines.py

示例4: __getConn

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def __getConn():

        if Mysql.__pool is None:
            __pool = PooledDB(creator=MySQLdb, mincached=1, maxcached=20,
                              host=Config.DBHOST, port=Config.DBPORT, user=Config.DBUSER, passwd=Config.DBPWD,
                              db=Config.DBNAME, use_unicode=False, charset=Config.DBCHAR, cursorclass=DictCursor)
        return __pool.connection() 
开发者ID:puyangsky,项目名称:DockerSecurityResearch,代码行数:9,代码来源:image_list.py

示例5: getSingleConnection

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def getSingleConnection():
        conn = MySQLdb.connect(
            DATABASE_CONFIG['HOST'],
            DATABASE_CONFIG['USER'],
            DATABASE_CONFIG['PASSWORD'],
            DATABASE_CONFIG['DATABASE'],
            charset='utf8',
            use_unicode=True,
            cursorclass=DictCursor
        )
        wraped_conn = MySQLConnection(conn)
        return wraped_conn 
开发者ID:pskun,项目名称:finance_news_analysis,代码行数:14,代码来源:mysql_pool.py

示例6: connect

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def connect(self):
        self.con = my.connect(
            host=self.host, user=self.user, passwd=self.password,
            db=self.dbname, port=self.port, cursorclass=mycursors.DictCursor) 
开发者ID:CESNET,项目名称:STaaS,代码行数:6,代码来源:warden_server.py

示例7: select_group_ids

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def select_group_ids(self, resource_name, timestamp):
        """Select the group ids from a snapshot table.

        Args:
            resource_name (str): String of the resource name.
            timestamp (str): String of timestamp, formatted as
                YYYYMMDDTHHMMSSZ.

        Returns:
            list: A list of group ids.

        Raises:
            MySQLError: When an error has occured while executing the query.
        """
        try:
            group_ids_sql = select_data.GROUP_IDS.format(timestamp)
            cursor = self.conn.cursor(cursorclass=cursors.DictCursor)
            cursor.execute(group_ids_sql)
            rows = cursor.fetchall()
            return [row['group_id'] for row in rows]
        except (DataError, IntegrityError, InternalError, NotSupportedError,
                OperationalError, ProgrammingError) as e:
            raise MySQLError(resource_name, e) 
开发者ID:GoogleCloudPlatform,项目名称:forseti-security,代码行数:25,代码来源:dao.py

示例8: test_collect

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def test_collect(self, mock_adbapi):
        self.device.zMySQLConnectionString = ['{"user":"root",'
                                              '"passwd":"zenoss",'
                                              '"port":"3306"}']
        self.collector.collect(self.device, self.logger)
        mock_adbapi.ConnectionPool.assert_called_with(
            'MySQLdb',
            passwd='zenoss',
            port=3306,
            host='127.0.0.1',
            user='root',
            cursorclass=cursors.DictCursor
        ) 
开发者ID:krull,项目名称:docker-zenoss4,代码行数:15,代码来源:test_modeler.py

示例9: collect

# 需要导入模块: from MySQLdb import cursors [as 别名]
# 或者: from MySQLdb.cursors import DictCursor [as 别名]
def collect(self, device, log):
        log.info("Collecting data for device %s", device.id)
        try:
            servers = parse_mysql_connection_string(
                device.zMySQLConnectionString)
        except ValueError, error:
            self.is_clear_run = False
            log.error(error.message)
            self._send_event(error.message, device.id, 5)
            defer.returnValue('Error')
            return

        result = []
        for el in servers.values():
            dbpool = adbapi.ConnectionPool(
                "MySQLdb",
                user=el.get("user"),
                port=el.get("port"),
                host=device.manageIp,
                passwd=el.get("passwd"),
                cursorclass=cursors.DictCursor
            )

            res = {}
            res["id"] = "{0}_{1}".format(el.get("user"), el.get("port"))
            for key, query in self.queries.iteritems():
                try:
                    res[key] = yield dbpool.runQuery(query)
                except Exception, e:
                    self.is_clear_run = False
                    res[key] = ()
                    msg, severity = self._error(
                        str(e), el.get("user"), el.get("port"))

                    log.error(msg)

                    if severity == 5:
                        self._send_event(msg, device.id, severity)
                        dbpool.close()
                        defer.returnValue('Error')
                        return

            dbpool.close()
            result.append(res)

        defer.returnValue(result) 
开发者ID:krull,项目名称:docker-zenoss4,代码行数:48,代码来源:MySQLCollector.py


注:本文中的MySQLdb.cursors.DictCursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。