本文整理汇总了Python中MysqlObj类的典型用法代码示例。如果您正苦于以下问题:Python MysqlObj类的具体用法?Python MysqlObj怎么用?Python MysqlObj使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MysqlObj类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insertTags
def insertTags(tags):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
for id in tags:
try:
db.insert('tags', {'id': id, 'name': tags[id]})
except Exception, e:
print "tag exists"
示例2: getTags
def getTags(tids):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
if len(tids) == 0:
return {}
res = db.getAll('tags', where=["id in (%s)" % ','.join(['%s' for i in range(0, len(tids))]), tids])
tags = {}
for row in res:
tags[row.id] = row.name
return tags
示例3: getAllTagsCounts
def getAllTagsCounts(uid):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
cur = db.query('select a.tid, a.cnt from (select tid, count(*) as cnt from posts_tags where uid = "%s" group by tid) a where a.cnt > 1' % uid)
result = cur.fetchall()
tcnt = {}
for tid, cnt in result:
tcnt[tid] = cnt
tags = db.getAll('tags')
res = []
for tag in tags:
if tag.id in tcnt:
res.append([tag.id, tag.name, tcnt[tag.id]])
return sorted(res, key=lambda x: x[2], reverse=True)
示例4: getPostsTags
def getPostsTags(pids):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
if len(pids) == 0:
return {}, {}
res = db.getAll('posts_tags', where=["pid in (%s)" % ','.join(['%s' for i in range(0, len(pids))]), pids])
posts_tags = {}
tagids = {}
for row in res:
if not posts_tags.has_key(row.pid):
posts_tags[row.pid] = []
posts_tags[row.pid].append(row.tid)
tagids[row.tid] = 1
return posts_tags, getTags(tagids.keys())
示例5: insertAction
def insertAction(uid, statdate, stattime, action):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
db.insert('action', {'uid': uid, 'statdate': statdate, 'stattime': stattime, 'action': action})
示例6: changeMedicine
def changeMedicine(id, medicine):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
return db.update('medicine', {'medicine': medicine}, where=("id = %s", [id]))
示例7: getMedicine
def getMedicine(uid):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
return db.getAll('medicine', where=['uid=%s', [uid]], order=['statdate', 'ASC'])
示例8: insertPasswd
def insertPasswd(uid, project, idno, passwd):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
db.insert('passwd', {'uid': uid, 'project': project, 'idno': idno, 'passwd': passwd})
示例9: toggleDone
def toggleDone(id, flag):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
return db.update('tvshow', {'isdone': flag}, where=("id = %s", [id]))
示例10: insertTvshow
def insertTvshow(uid, name, season, episode):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
db.insert('tvshow', {'uid': uid, 'name': name, 'season': season, 'episode': episode})
示例11: deletePost
def deletePost(postid):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
db.delete('posts', where=['id=%s', [postid]])
示例12: insertPost
def insertPost(post):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
return db.insert('posts', post).lastrowid
示例13: insertPostsTags
def insertPostsTags(posts_tags, uid):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
for pid in posts_tags:
for tid in posts_tags[pid]:
db.insert('posts_tags', {'pid': pid, 'tid': tid, 'uid': uid})
示例14: getTagIdByName
def getTagIdByName(name):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
tag = db.getOne('tags', where=['name=%s', [name]])
return tag.id
示例15: getUser
def getUser(id):
db = MysqlObj(host=MYSQL_HOST, db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, port=int(MYSQL_PORT))
return db.getOne('users', where=['id=%s', [id]])