本文整理汇总了Python中tornado_mysql.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
username = self.get_argument('username', '')
passwd = self.get_argument('passwd', '')
print '!!!!!!!!!!!!!!!!!!'
print username
print username.encode('cp1251')
print '!!!!!!!!!!!!!!!!!!!'
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='drunk_adventures')
cur = conn.cursor()
yield cur.execute("SELECT password, session FROM avatar WHERE login = '%s' ;" % username)
cur.close()
del conn
creds = []
for row in cur:
creds.append(row)
if creds and creds[0][0] == passwd:
session_id = startSession(username)
h.update(session_id)
self.write({'auth_status': 'Authorization successful', 'se': h.hexdigest(), 'u': username})
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='drunk_adventures')
cur = conn.cursor()
yield cur.execute("UPDATE avatar SET session = %s WHERE login = %s; COMMIT;" , (session_id, username))
cur.close()
del conn
else:
self.write({'auth_status': 'Go fuck yourself asshole', 'se':''})
开发者ID:BlackCab,项目名称:drunk_adventures,代码行数:31,代码来源:tornado_periodic.py
示例2: _get_conn
def _get_conn(self): # -> Future[connection]
now = self.io_loop.time()
# Try to reuse in free pool
while self._free_conn:
conn = self._free_conn.popleft()
if now - conn.connected_time > self.max_recycle_sec:
self._close_async(conn)
continue
log.debug("Reusing connection from pool: %s", self.stat())
fut = Future()
fut.set_result(conn)
return fut
# Open new connection
if self.max_open == 0 or self._opened_conns < self.max_open:
self._opened_conns += 1
log.debug("Creating new connection: %s", self.stat())
fut = connect(**self.connect_kwargs)
fut.add_done_callback(self._on_connect) # self._opened_conns -=1 on exception
return fut
# Wait to other connection is released.
fut = Future()
self._waitings.append(fut)
return fut
开发者ID:PyMySQL,项目名称:Tornado-MySQL,代码行数:26,代码来源:pools.py
示例3: select_mysql
def select_mysql(host, port, db, query, login='root', password='root', connect_timeout=60, request_timeout=120):
import tornado_mysql
conn = yield tornado_mysql.connect(host=host, port=port, user=login, passwd=password, db=db)
cur = conn.cursor()
yield cur.execute('set names utf8;')
cur.close()
cur = conn.cursor()
yield cur.execute(query)
points = []
for row in cur:
toa = []
points.append(toa)
for val in row:
if isinstance(val, datetime):
val = val.timestamp()
elif isinstance(val, Number):
val = float(val)
toa.append(val)
tor = {
'name': query,
'columns': list(map(lambda c: c[0], cur.description)),
'points': points
}
cur.close()
conn.close()
raise tornado.gen.Return(tor)
开发者ID:KosyanMedia,项目名称:inhale,代码行数:27,代码来源:q2g.py
示例4: upd
def upd(self,user,prob_id):
#user submit_num+1
#user tongji[0]+1
#problems submit_num+1
#problems tongji[0]+1
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
sql = "SELECT submit_num,tongji FROM user WHERE user = %s LIMIT 1"
yield cur.execute(sql,(user,))
info = cur.fetchone()
tongji = json.loads(info[1])
tongji[0]=tongji[0]+1
sql = "UPDATE user SET submit_num = %s,tongji=%s WHERE user = %s"
yield cur.execute(sql,(info[0]+1,json.dumps(tongji),user))
yield conn.commit()
sql = "SELECT submit_num,tongji FROM problems WHERE id = %s LIMIT 1"
yield cur.execute(sql,(prob_id,))
info = cur.fetchone()
tongji = json.loads(info[1])
tongji[0]=tongji[0]+1
sql = "UPDATE problems SET submit_num = %s,tongji=%s WHERE id = %s"
yield cur.execute(sql,(info[0]+1,json.dumps(tongji),prob_id))
yield conn.commit()
cur.close()
conn.close()
开发者ID:zrt,项目名称:XOJ,代码行数:28,代码来源:judge_handler.py
示例5: post
def post(self):
event = self.get_argument('event', '')
if not event:
response = {
'error': True,
'msg': 'Пожалуйста, введите id события.'
}
else:
try:
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='ubuntu', passwd='', db='miemgames', charset='utf8')
cur = conn.cursor()
yield cur.execute("SELECT g.name, g.description, g.picture, e.place, e.time FROM events e, games g WHERE e.game = g.id AND e.id = %s",
(event))
response = []
for i, row in enumerate(cur):
response.append({'name': str(row[0]), 'description': str(row[1]), 'picture': str(row[2]), 'place': str(row[3]), 'time': str(row[4])})
response = {"events": response}
cur.close()
conn.close()
except:
response = {
'error' : True,
'msg' : 'Данного события не существует.'
}
self.write(response)
开发者ID:zhekalat,项目名称:miemgames,代码行数:26,代码来源:server.py
示例6: connect
def connect(self):
engine = self.param['engine']
if engine == 'mysql':
import tornado_mysql
self.conn = yield tornado_mysql.connect(host = self.param['host'],
port = self.param['port'],
user = self.param['user'],
passwd = self.param['passwd'],
db = self.param['db'],
charset = self.param['charset'],
connect_timeout = self.param.get('timeout', 10),
)
yield self.conn.autocommit(1)
cur = self.conn.cursor()
yield cur.execute("show variables like 'server_id'")
row = cur.fetchone()
self.server_id = int(row[1])
#if self.param.get('autocommit',None):
# log.note('set autocommit')
# self.conn.autocommit(1)
#initsqls = self.param.get('init_command')
#if initsqls:
# log.note('init sqls:', initsqls)
# cur = self.conn.cursor()
# cur.execute(initsqls)
# cur.close()
else:
raise ValueError, 'engine error:' + engine
开发者ID:zhaoweikid,项目名称:zbase,代码行数:30,代码来源:dbpool_tornado.py
示例7: post
def post(self):
p=[self.get_argument(s) for s in ['name','info','content','problems','begin_date','end_date','author','visible','invitecode'] ]
if p[-1] != 'addcontest':
self.redirect_msg('/contest/new','邀请码错误')
return
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
auth = self.auth()
if auth < 25:
self.redirect_msg('/contests','权限不足')
return
sql = "INSERT INTO contests (name,info,content,problems,begin_date,end_date,author,visible,gen_date,status,result) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
try:
yield cur.execute(sql,(p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],datetime.now(),1,''))
yield conn.commit()
except BaseException as e:
self.redirect_msg('/contest/new','数据库错误')
else:
sql = "SELECT id FROM contests ORDER BY id DESC LIMIT 1"
yield cur.execute(sql)
p=cur.fetchone()
self.redirect_msg('/contest/%d/edit'%p[0],'添加比赛成功')
finally:
cur.close()
conn.close()
开发者ID:zrt,项目名称:XOJ,代码行数:29,代码来源:contest_handler.py
示例8: get
def get(self,contest_id):
contest_id=int(contest_id)
if contest_id < 1 :
self.redirect_msg('/contests','比赛编号错误')
return
contest_id=norm_page(contest_id)
msg = self.get_argument('msg',None)
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
sql = "SELECT id,name,author,begin_date,end_date,status,content,problems,info,visible FROM contests WHERE id = %s"
yield cur.execute(sql,(contest_id,))
contest=cur.fetchone()
cur.close()
conn.close()
if contest == None:
self.redirect_msg('/contests','比赛编号错误')
return
user=self.current_user
auth = self.auth()
if contest[2].encode('utf-8')!=user and auth < 250:
self.redirect_msg('/contests','权限不足')
return
self.render('contest_edit.html',msg=msg,contest=contest,\
page_type='contest',page_title='编辑比赛#'+str(contest[0])+'. '+contest[1]+' -XOJ')
开发者ID:zrt,项目名称:XOJ,代码行数:29,代码来源:contest_handler.py
示例9: post
def post(self):
p=[self.get_argument(s) for s in ['name','content','invitecode'] ]
auth = self.auth()
if auth < 10:
self.redirect_msg('/posts','权限不足')
return
if p[2] != 'addpost':
self.redirect_msg('/post/new','邀请码错误')
return
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
sql = "INSERT INTO posts (name,author,content,gen_date,modify_date) VALUES (%s,%s,%s,%s,%s)"
try:
yield cur.execute(sql,(p[0],self.current_user,p[1],datetime.now(),datetime.now()))
yield conn.commit()
except BaseException as e:
self.redirect_msg('/post/new','数据库错误')
raise
else:
sql = "SELECT id FROM posts ORDER BY id DESC LIMIT 1"
yield cur.execute(sql)
p=cur.fetchone()
self.redirect_msg('/post/%d'%p[0],'发布文章成功')
finally:
cur.close()
conn.close()
开发者ID:zrt,项目名称:XOJ,代码行数:30,代码来源:post_handler.py
示例10: get
def get(self,post_id):
post_id=int(post_id)
if post_id < 1 :
self.redirect_msg('/posts','文章编号错误')
return
post_id=norm_page(post_id)
msg = self.get_argument('msg',None)
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
#
sql = "SELECT name,content,author FROM posts WHERE id = %s LIMIT 1"
yield cur.execute(sql,(post_id,))
post = cur.fetchone()
cur.close()
conn.close()
if post == None :
self.redirect_msg('/posts','题目编号错误')
return
user = self.current_user
auth = self.auth()
if auth < 200 and post[2].encode('utf-8')!= user:
self.redirect_msg('/posts','权限不足')
return
self.render('edit_post.html',msg=msg,post=post,page_type='post',\
page_title='修改文章:'+post[0]+' -XOJ')
开发者ID:zrt,项目名称:XOJ,代码行数:28,代码来源:post_handler.py
示例11: get
def get(self,judge_id):
judge_id=int(judge_id)
if judge_id < 1 :
self.redirect_msg('/status','评测记录未找到')
return
judge_id = norm_page(judge_id)
msg = self.get_argument('msg',None)
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
sql = "SELECT id,author,code,problem_id,problem_name,status,mem_use,tim_use,\
lang,code_len,submit_date,result,visible FROM judge WHERE id = %s"
yield cur.execute(sql,(judge_id,))
info = cur.fetchone()
cur.close()
conn.close()
if info == None :
self.redirect_msg('/status','评测记录未找到')
return
user = self.current_user
auth = self.auth()
if info[1].encode('utf-8') != self.current_user and auth < info[12]:
self.redirect_msg('/status','权限不足')
return
#if self.current_user != info[1].encode('utf-8') and self.current_user != 'zrt'.encode('utf-8') and self.current_user != 'sys'.encode('utf-8'):
# self.redirect_msg('/status','权限不足')
# return
self.render('status_info.html',msg=msg,info=info,page_type='status',\
page_title='评测记录 -XOJ')
开发者ID:zrt,项目名称:XOJ,代码行数:34,代码来源:judge_handler.py
示例12: __connect_to_ctl
def __connect_to_ctl(self):
self._ctl_connection_settings = dict(self.__connection_settings)
self._ctl_connection_settings["db"] = "information_schema"
self._ctl_connection_settings["cursorclass"] = DictCursor
self._ctl_connection = yield tornado_mysql.connect(**self._ctl_connection_settings)
self._ctl_connection._get_table_information = self.__get_table_information
self.__connected_ctl = True
开发者ID:plazix,项目名称:tornado-mysql-replication,代码行数:7,代码来源:binlogstream.py
示例13: on_connection_close
def on_connection_close(self):
t.cancel()
print 'Finish ', session_id
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='root', passwd='root', db='drunk_adventures')
cur = conn.cursor()
yield cur.execute("UPDATE avatar SET session = NULL WHERE login = %s; COMMIT;" , (player,) )
cur.close()
del conn
开发者ID:BlackCab,项目名称:drunk_adventures,代码行数:8,代码来源:tornado_periodic.py
示例14: test_issue_34
def test_issue_34(self):
try:
yield tornado_mysql.connect(host="localhost", port=1237, user="root")
self.fail()
except tornado_mysql.OperationalError as e:
self.assertEqual(2003, e.args[0])
except Exception:
self.fail()
开发者ID:Jamesleons,项目名称:Tornado-MySQL,代码行数:8,代码来源:test_issues.py
示例15: main
def main():
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='root', passwd='111111', db='autoops')
cur = conn.cursor()
sql = "SELECT * FROM users"
yield cur.execute(sql)
for row in cur:
print(row)
cur.close()
conn.close()
开发者ID:ivonlee,项目名称:test,代码行数:9,代码来源:db.py
示例16: test_issue_6
def test_issue_6(self):
""" exception: TypeError: ord() expected a character, but string of length 0 found """
# ToDo: this test requires access to db 'mysql'.
kwargs = self.databases[0].copy()
kwargs['db'] = "mysql"
conn = yield tornado_mysql.connect(**kwargs)
c = conn.cursor()
yield c.execute("select * from user")
yield conn.close_async()
开发者ID:Jamesleons,项目名称:Tornado-MySQL,代码行数:9,代码来源:test_issues.py
示例17: main
def main():
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='mysql')
cur = conn.cursor()
yield cur.execute("SELECT Host,User FROM user")
print(cur.description)
for row in cur:
print(row)
cur.close()
conn.close()
开发者ID:Jamesleons,项目名称:Tornado-MySQL,代码行数:9,代码来源:example.py
示例18: get
def get(self,contest_id,prob_id):
contest_id=int(contest_id)
prob_id=int(prob_id)
if contest_id < 1 :
self.redirect_msg('/contests','比赛编号错误')
return
contest_id=norm_page(contest_id)
msg = self.get_argument('msg',None)
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
sql = "SELECT id,problems,end_date,begin_date,author,visible FROM contests WHERE id = %s LIMIT 1"
yield cur.execute(sql,(contest_id,))
contest=cur.fetchone()
if contest == None:
cur.close()
conn.close()
self.redirect_msg('/contests','比赛编号错误')
return
user = self.current_user
auth = self.auth()
if contest[4].encode('utf-8') != user and auth < contest[5]:
self.redirect_msg('/contests','权限不足')
return
if datetime.now() < contest[3]:
self.redirect_msg('/contests','权限不足')
return
if datetime.now() > contest[2]:
self.redirect_msg('/contest/%d'%contest_id,'提交时间已过')
return
problems=json.loads(contest[1])
if prob_id < 0 or prob_id >= len(problems):
self.redirect_msg('/contest/%d'%contest_id,'题目编号配置错误')
return
contest_prob_id=prob_id
prob_id=problems[prob_id]
sql = "SELECT id,tp,name FROM problems WHERE id = %s LIMIT 1"
yield cur.execute(sql,(prob_id,))
problem = cur.fetchone()
cur.close()
conn.close()
if problem == None :
self.redirect_msg('/contest/%d'%contest_id,'题目编号错误')
return
self.render('contest_submit.html',msg=msg,problem=problem,page_type='contest',\
page_title='比赛提交#'+problem[2]+' -XOJ')
开发者ID:zrt,项目名称:XOJ,代码行数:56,代码来源:contest_judge_handler.py
示例19: get
def get(self):
conn = yield tornado_mysql.connect(host='127.0.0.1', port=3306, user='ubuntu', passwd='', db='miemgames', charset='utf8')
cur = conn.cursor()
yield cur.execute("SELECT e.id, g.name, e.time, g.picture, g.id FROM events e, games g WHERE g.id = e.game")
result = []
for row in cur:
result.append({'id': str(row[0]), 'game': str(row[1]), 'time': str(row[2]), 'picture': str(row[3])})
self.write({"events": result})
cur.close()
conn.close()
开发者ID:zhekalat,项目名称:miemgames,代码行数:10,代码来源:server.py
示例20: submit_callback
def submit_callback(self,response):
if response.error:
conn = yield tornado_mysql.connect(host=conf.DBHOST,\
port=conf.DBPORT,user=conf.DBUSER,passwd=conf.DBPW,db=conf.DBNAME,charset='utf8')
cur = conn.cursor()
sql = "UPDATE judge SET status=%s,result=%s WHERE id = %s LIMIT 1"
yield cur.execute(sql,(9,'####访问评测机时错误\n'+str(response.error),self.j_id,))
yield conn.commit()
cur.close()
conn.close()
开发者ID:zrt,项目名称:XOJ,代码行数:10,代码来源:contest_judge_handler.py
注:本文中的tornado_mysql.connect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论