We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import pymysql from dbutils.pooled_db import PooledDB from pymysql.cursors import DictCursor
class DatabasePool: """ 数据库连接初始化类 """ host = '127.0.0.1' port = 3306 user = 'xxx' # noqa password = 'xxxx' # noqa database = 'events'
pool = PooledDB( # 使用链接数据库的模块 creator=pymysql, # 连接池允许的最大连接数,0和None表示不限制连接数 maxconnections=1000, # 初始化时,链接池中至少创建的空闲的链接,0表示不创建 mincached=50, # 链接池中最多闲置的链接,0和None不限制 maxcached=5, maxshared=0, # 连接池中如果没有可用连接后,是否阻塞等待。True,等待;False,不等待然后报错 blocking=True, # 一个链接最多被重复使用的次数,None表示无限制 maxusage=None, # 开始会话前执行的命令列表。如:["set xxx to ...", "set time zone ..."] setsession=[], # ping MySQL服务端,检查是否服务可用。# 如:0 = None = never, 1 = default = whenever it is requested, 2 = when a cursor is # created, 4 = when a query is executed, 7 = always ping=0, host=host, port=port, user=user, password=password, database=database, charset='utf8mb4' )
if name == 'main': pass
from component.dbutils_pool_service import DatabasePool
def insertData(sqlQuery): """ :param sqlQuery: 具体需要执行的sql语句 """ conn = None try: conn = DatabasePool.pool.connection() cursor = conn.cursor(cursor=DictCursor) try: # 短链接执行sql cursor.execute(sqlQuery) conn.commit() cursor.close() conn.close() except Exception as e: cursor.close() conn.close() logout(logging.ERROR, "执行sql报错" + str(sqlQuery) + "报错信息" + str(e)) except Exception as e: logout(logging.ERROR, "链接数据库报错" + str(e)) try: conn.close() except Exception as e: # noqa pass
The text was updated successfully, but these errors were encountered:
No branches or pull requests
import pymysql
from dbutils.pooled_db import PooledDB
from pymysql.cursors import DictCursor
class DatabasePool:
"""
数据库连接初始化类
"""
host = '127.0.0.1'
port = 3306
user = 'xxx' # noqa
password = 'xxxx' # noqa
database = 'events'
if name == 'main':
pass
from component.dbutils_pool_service import DatabasePool
根据传入的sql,进行数据库执行操作
def insertData(sqlQuery):
"""
:param sqlQuery: 具体需要执行的sql语句
"""
conn = None
try:
conn = DatabasePool.pool.connection()
cursor = conn.cursor(cursor=DictCursor)
try:
# 短链接执行sql
cursor.execute(sqlQuery)
conn.commit()
cursor.close()
conn.close()
except Exception as e:
cursor.close()
conn.close()
logout(logging.ERROR, "执行sql报错" + str(sqlQuery) + "报错信息" + str(e))
except Exception as e:
logout(logging.ERROR, "链接数据库报错" + str(e))
try:
conn.close()
except Exception as e: # noqa
pass
The text was updated successfully, but these errors were encountered: