本文整理汇总了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)
示例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)
示例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????
示例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()
示例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
示例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)
示例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)
示例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
)
示例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)