本文整理汇总了Python中mysql.Mysql.fetch方法的典型用法代码示例。如果您正苦于以下问题:Python Mysql.fetch方法的具体用法?Python Mysql.fetch怎么用?Python Mysql.fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.Mysql
的用法示例。
在下文中一共展示了Mysql.fetch方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _new_question
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
def _new_question(data):
for i in range(1):
mysql = Mysql()
try:
mysql.connect_master()
search_sql = "select id,json,subject,type from entity_question_new where oldid = %(oldid)d;"
if 0 == mysql.query(search_sql,oldid = int(data)):
return None
else:
question_set = mysql.fetch()
except DBException as e:
break
newid = question_set[0]
question_json = question_set[1]
question_subject = question_set[2]
question_type = question_set[3]
new_question_dict = {}
new_question_dict['q_new_id'] = newid
new_question_dict['new_question'],new_question_dict['blank_num'] = Business.q_json_parse(question_type,question_json)
new_question_dict['subject'] = question_subject
#print new_question_dict
return new_question_dict
示例2: get_question_by_id
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
def get_question_by_id(self,question_id):
mysql = Mysql()
try:
mysql.connect_master()
search_sql = "select A.Knowledge,B.TypeValue,A.QuesAbility,A.QuesDiff,A.QuesBody,A.QuesAnswer,A.QuesParse from(select Knowledge,QuesType,QuesAbility,QuesDiff,QuesBody,QuesAnswer,QuesParse from paper.paper where ID=%(question_id)d union all select Knowledge,QuesType,QuesAbility,QuesDiff,QuesBody,QuesAnswer,QuesParse from paper.cz_paper where ID=%(question_id)d)A left outer join (select TypeId,TypeValue from paper.questype)B on (A.QuesType=B.TypeId);"
if 0 == mysql.query(search_sql,question_id = int(question_id)):
return None
else:
question_set = mysql.fetch()
except DBException as e:
pass
question_ability_dict ={'1':'了解和识记','2':'理解和掌握','3':'简单应用','4':'综合应用'}
question_diff_dict = {'1':'容易','2':'较易','3':'一般','4':'较难','5':'困难'}
question_dict = {}
question_dict['knowledge'] = question_set[0]
question_dict['type'] = question_set[1]
question_dict['ability'] = question_ability_dict[question_set[2]]
question_dict['diff'] = question_diff_dict[question_set[3]]
question_dict['body'] = question_set[4]
question_dict['answer'] = question_set[5]
question_dict['parse'] = question_set[6]
return question_dict
示例3: is_type
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
def is_type(type_id):
mysql = Mysql()
mysql.connect_master()
query_sql = "select name from entity_question_type where type_id = %(type_id)d and enable = 1;"
try:
if mysql.query(query_sql,type_id = int(type_id)):
return mysql.fetch()[0]
else:
return False
except DBException as e:
LOG.error('check type error [%s]' % e)
raise CkException('check type error')
示例4: get_json_by_id
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
def get_json_by_id(oldid):
mysql = Mysql()
mysql.connect_master()
query_sql = "select json from entity_question_new where oldid=%(oldid)d;"
try:
if mysql.query(query_sql,oldid = int(oldid)):
json = mysql.fetch()[0]
return json
else:
return False
except DBException as e:
LOG.error('get json error [%s]' % e)
raise CkException('get json error')
示例5: check_user
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
def check_user(username,password):
password = Base.md5(password)
mysql = Mysql()
mysql.connect_master()
query_sql = "select password from verify_user where username='%(username)s';"
try:
if mysql.query(query_sql,username = username):
pwd = mysql.fetch()[0]
if password == pwd:
return True
else:
return False
except DBException as e:
LOG.error('check user error [%s]' % e)
raise CkException('check user error')
示例6: Mysql
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
from mysql import Mysql
reader = Mysql()
writer = Mysql()
reader.query('SELECT * FROM directories')
data = reader.fetch()
while data != dict():
id = str(data['id'])
new_directory = data['directory'].replace('/home/albertyw/','/home/albertyw/Drive2/')
query = "UPDATE directories SET directory = '"+new_directory+"' WHERE id='"+id+"';"
print query
writer.query(query)
data = reader.fetch()
reader.query('SELECT * FROM localfiles')
data = reader.fetch()
while data != dict():
id = str(data['id'])
new_directory = data['filedirectory'].replace('/home/albertyw/','/home/albertyw/Drive2/')
query = "UPDATE localfiles SET filedirectory = '"+new_directory+"' WHERE id='"+id+"';"
print query
writer.query(query)
data = reader.fetch()
示例7: _old_question
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import fetch [as 别名]
def _old_question(data):
for i in range(1):
mysql = Mysql()
try:
mysql.connect_master()
search_sql = "select id,question_body,question_options,question_answer,question_analysis,question_type,difficulty from entity_question_old where id = %(question_id)d;"
if 0 == mysql.query(search_sql,question_id = int(data)):
return None
else:
question_set = mysql.fetch()
children_sql = "select id,question_body,question_options,question_answer,question_analysis,question_type,difficulty from entity_question_old where parent_question_id = %(parent_id)d order by id;"
if 0 == mysql.query(children_sql,parent_id = int(data)):
children_set = None
else:
children_set = mysql.fetchall()
except DBException as e:
break
domain = "http://%s.okjiaoyu.cn/%s"
question_body = question_set[1]
question_option = question_set[2]
question_answer = question_set[3]
question_analysis = question_set[4]
question_type = question_set[5]
question_level = question_set[6]
url_list = []
body_url = ''
option_url = ''
answer_url = ''
analysis_url = ''
if question_body is not None:
body_bucket = question_body[0:2]
body_url = domain % (body_bucket,question_body)
url_list.append(body_url)
if question_option is not None:
option_bucket = question_option[0:2]
option_url = domain % (option_bucket,question_option)
url_list.append(option_url)
if question_answer is not None:
answer_bucket = question_answer[0:2]
answer_url = domain % (answer_bucket,question_answer)
url_list.append(answer_url)
if question_analysis is not None:
analysis_bucket = question_analysis[0:2]
analysis_url = domain % (analysis_bucket,question_analysis)
url_list.append(analysis_url)
if children_set is not None:
for children in children_set:
for i in range(1,5):
if children[i] is not None:
children_bucket = children[i][0:2]
children_url = domain % (children_bucket,children[i])
url_list.append(children_url)
return {'url_list' : url_list,'type' : question_type,'level' : question_level,'q_old_id' : data}