• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mysql.Mysql类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mysql.Mysql的典型用法代码示例。如果您正苦于以下问题:Python Mysql类的具体用法?Python Mysql怎么用?Python Mysql使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Mysql类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_systematics

	def get_systematics(question_id):
		
		mysql = Mysql()

		mysql.connect_master()
		
		query_sql = "select D.name as module_name,C.name as unit_name,B.name as topic_name from (select topic_id from link_question_topic where question_id=%(question_id)d)A left outer join (select id,name,unit_id from entity_topic)B on (A.topic_id=B.id) left outer join (select id,name,module_id from entity_unit)C on (B.unit_id=C.id) left outer join (select id,name from entity_module)D on (C.module_id=D.id);" 
		
		try:
			if mysql.query(query_sql,question_id = int(question_id)):

				res = mysql.fetchall()
				systematics_list = []

				for line in res:
					module = line[0]
					unit = line[1]
					topic = line[2]					
					systematics_dict = {'module':module,'unit':unit,'topic':topic}
					systematics_list.append(systematics_dict)

				return systematics_list
			else:
				return False

		except DBException as e:
			LOG.error('get systematics error [%s]' % e)
			raise CKException('get systematics error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:28,代码来源:business.py


示例2: get_question_by_id

	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
开发者ID:XDF-server,项目名称:exhibit,代码行数:32,代码来源:exhibit_handler.py


示例3: q_subject_list

	def q_subject_list():

		mysql = Mysql()
		
		mysql.connect_master()

		query_sql = "select distinct subject from entity_question_new where type is not null;"	

		subject_list = []

		try:
			if mysql.query(query_sql):
				subject_tuple =  mysql.fetchall()
				
				for type in subject_tuple:
					tmp_tuple = (type[0])
					subject_list.append(tmp_tuple)
				return subject_list

			else:
				return None

		except DBException as e:
			LOG.error('get subject error [%s]' % e)
			raise CkException('get subject error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:25,代码来源:business.py


示例4: get_group_list

	def get_group_list(system_id):
	
		mysql = Mysql()

		mysql.connect_master()
		
		query_sql = "select A.id,A.name,B.num from (select id,name from entity_group where system_id=%(system_id)d or id=0)A left outer join (select question_group,count(1) as num from entity_question where upload_id=%(system_id)d group by question_group)B on (A.id=B.question_group);" 
		
		try:
			if mysql.query(query_sql,system_id = system_id):

				res = mysql.fetchall()

				group_list = []

				for line in res:
					group_id = line[0]
					group_name = line[1]
					question_num = int(line[2]) if line[2] else 0					
					group_dict = {'id':int(group_id),'name':group_name,'num':int(question_num)}
					group_list.append(group_dict)
			
				return group_list
			else:
				return False

		except DBException as e:
			LOG.error('check topic error [%s]' % e)
			raise CKException('check topic error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:29,代码来源:business.py


示例5: _new_question

	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
开发者ID:XDF-server,项目名称:exhibit,代码行数:29,代码来源:exhibit_handler.py


示例6: q_mark_list

	def q_mark_list():

		mysql = Mysql()
		
		mysql.connect_master()

		query_sql = "select id,name from link_question_mark where enable=1;"	

		mark_list = []

		try:
			if mysql.query(query_sql):
				mark_tuple =  mysql.fetchall()
				
				for mark in mark_tuple:
					tmp_tuple = (mark[0],mark[1])
					mark_list.append(tmp_tuple)
				return mark_list

			else:
				return None

		except DBException as e:
			LOG.error('get mark error [%s]' % e)
			raise CkException('get mark error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:25,代码来源:business.py


示例7: chapter_id_exist

	def chapter_id_exist(chapter_id):

		mysql = Mysql()

		mysql.connect_master()
		
		query_sql = "select 1 from entity_teaching_chapter where id='%(chapter_id)d';" 
		
		try:
			if mysql.query(query_sql,chapter_id = int(chapter_id)):
				return True
			else:
				return False

		except DBException as e:
			LOG.error('check chapter error [%s]' % e)
			raise CKException('check chapter error')
开发者ID:XDF-server,项目名称:api_resource,代码行数:17,代码来源:business.py


示例8: is_type

	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')
开发者ID:XDF-server,项目名称:exhibit,代码行数:17,代码来源:business.py


示例9: group_id_exist

	def group_id_exist(group_id):
		
		mysql = Mysql()

		mysql.connect_master()
		
		query_sql = "select 1 from entity_group where id = '%(group_id)d';" 
		
		try:
			if mysql.query(query_sql,group_id = int(group_id)):
				return True
			else:
				return False

		except DBException as e:
			LOG.error('check topic error [%s]' % e)
			raise CKException('check topic error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:17,代码来源:business.py


示例10: update_json_by_id

	def update_json_by_id(oldid,json):
		
		mysql = Mysql()

		mysql.connect_master()

		query_sql = "update entity_question_new set json='%(question_json)s' where oldid=%(oldid)d;"	

		try:
			if mysql.query(query_sql,oldid = int(oldid),question_json = json):
				return True
			else:
				return False

		except DBException as e:
			LOG.error('update json error [%s]' % e)
			raise CkException('update json error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:17,代码来源:business.py


示例11: is_seriess

	def is_seriess(seriess_id):
		
		mysql = Mysql()
		
		mysql.connect_master()

		query_sql = "select 1 from entity_seriess where id = %(seriess_id)d;"
		
		try:
			if mysql.query(query_sql,seriess_id = int(seriess_id)):
				return True
			else:
				return False

		except DBException as e:
			LOG.error('check seriess error [%s]' % e)
			raise CkException('check seriess error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:17,代码来源:business.py


示例12: is_topic

	def is_topic(topic_id):
		
		mysql = Mysql()

		mysql.connect_master()
		
		query_sql = "select 1 from entity_topic where id = %(topic_id)d;" 
		
		try:
			if mysql.query(query_sql,topic_id = int(topic_id)):
				return True
			else:
				return False

		except DBException as e:
			LOG.error('check topic error [%s]' % e)
			raise CKException('check topic error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:17,代码来源:business.py


示例13: get_json_by_id

	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')
开发者ID:XDF-server,项目名称:exhibit,代码行数:18,代码来源:business.py


示例14: verify

	def verify(username,oldid,newid,verify):
		
		mysql = Mysql()

		mysql.connect_master()

		query_sql = "insert into entity_verify (username,oldid,newid,state) values ('%(username)s',%(oldid)d,%(newid)d,%(verify)d);"	

		try:
			if mysql.query(query_sql,username = username,oldid = int(oldid),newid = int(newid),verify = int(verify)):
				return mysql.get_last_id()

			else:
				return None

		except DBException as e:
			LOG.error('add mark error [%s]' % e)
			raise CkException('add mark error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:18,代码来源:business.py


示例15: add_mark

	def add_mark(name):

		mysql = Mysql()

		mysql.connect_master()

		query_sql = "insert into link_question_mark (name,mark_time) values ('%(name)s',now());"	

		try:
			if mysql.query(query_sql,name = name):
				return mysql.get_last_id()

			else:
				return None

		except DBException as e:
			LOG.error('add mark error [%s]' % e)
			raise CkException('add mark error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:18,代码来源:business.py


示例16: q_mark

	def q_mark(oldid,newid,mark):

		mysql = Mysql()

		mysql.connect_master()

		query_sql = "insert into entity_question_mark (oldid,newid,mark,mark_time) values (%(oldid)d,%(newid)d,%(mark)d,now());"	

		try:
			if mysql.query(query_sql,oldid = oldid,newid = newid,mark = mark):
				return 'success'

			else:
				return None

		except DBException as e:
			LOG.error('mark error [%s]' % e)
			raise CkException('mark error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:18,代码来源:business.py


示例17: q_subject_filter

	def q_subject_filter(type,start,num):

		mysql = Mysql()

		mysql.connect_master()

		query_sql = "select oldid,subject from entity_question_new where subject = '%(type)s' limit %(start)d,%(num)d;"	

		try:
			if mysql.query(query_sql,type = type,start = start,num = num):
				return mysql.fetchall()

			else:
				return None

		except DBException as e:
			LOG.error('filtet type error [%s]' % e)
			raise CkException('filter type error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:18,代码来源:business.py


示例18: q_subject_filter_num

	def q_subject_filter_num(type):

		mysql = Mysql()

		mysql.connect_master()

		query_sql = "select count(*) from entity_question_new where subject = '%(type)s';"	

		try:
			if mysql.query(query_sql,type = type):
				return mysql.fetchall()[0][0]

			else:
				return None

		except DBException as e:
			LOG.error('filtet type error [%s]' % e)
			raise CkException('filter type error')
开发者ID:XDF-server,项目名称:exhibit,代码行数:18,代码来源:business.py


示例19: __init__

 def __init__(self):
     db_config = config.getConfig('db')
     weibo_config = config.getConfig('weibo')
     app_config = config.getConfig('app')
     
     self.db = Mysql(db_config['host'], db_config['user'], db_config['passwd'], db_config['db'], db_config['charset'])
     self.user = User()
     self.wb = Weibo(weibo_config['username'], weibo_config['password'], weibo_config['appkey'])
     self.config = app_config
开发者ID:squarezhou,项目名称:weibo-notify,代码行数:9,代码来源:subscribe.py


示例20: get_condition_keys

 def get_condition_keys(self):
     where = ""
     if self.conditions:
         where = ' AND '.join("`%s`=%s" % (str(k), self.placeholder)
                              for k in self.conditions)
     if self.extras:
         where = Mysql.merge_sql(
             where,
             ' AND '.join([i.replace('%', '%%') for i in self.extras]))
     return "WHERE %s" % (where, ) if where else ""
开发者ID:Catcherman,项目名称:mymaps,代码行数:10,代码来源:query.py



注:本文中的mysql.Mysql类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python connector.connect函数代码示例发布时间:2022-05-27
下一篇:
Python mysql.switch_to_db函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap