本文整理汇总了Python中tornado_mysql.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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':''})
示例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
示例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)
示例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()
示例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)
示例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
示例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()
示例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')
示例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()
示例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')
示例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')
示例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
示例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
示例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()
示例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()