本文整理汇总了Python中db.Db.execScalar方法的典型用法代码示例。如果您正苦于以下问题:Python Db.execScalar方法的具体用法?Python Db.execScalar怎么用?Python Db.execScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Db
的用法示例。
在下文中一共展示了Db.execScalar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BookDbLayer
# 需要导入模块: from db import Db [as 别名]
# 或者: from db.Db import execScalar [as 别名]
class BookDbLayer(object):
def __init__(self, connectionName=None, db_to_clone=None):
super(BookDbLayer, self).__init__()
self._db = Db(connectionName, db_to_clone)
def __getattr__(self, name):
return getattr(self._db, name)
def create(self, databaseName, name, description, genrelist, grouplist):
db = self._db
db.open(databaseName)
db.transaction()
try:
for statement in schema.split(';'):
db.execUpdate(statement)
for pair in [('version', 1),
('name', name),
('description', description)]:
db.execUpdate("INSERT INTO info(name, value) VALUES(?,?)",
pair[0], pair[1])
for genre in genrelist:
db.execUpdate("INSERT INTO libgenrelist(genreid, genrecode, genredesc) VALUES(?,?,?)",
genre[0], genre[1], genre[2])
for groupname in grouplist:
db.execUpdate("INSERT INTO libgrouplist(groupname) VALUES(?)",
groupname)
except DatabaseError:
db.rollback()
raise
else:
if not db.commit():
raise DatabaseError, db.lastError().text()
def getDbProperty(self, name):
return self._db.execScalar("SELECT value FROM info WHERE name = ?",
name)
def setDbProperty(self, name, value):
self._db.execUpdate("INSERT OR REPLACE INTO info(name, value) VALUES(?,?)",
name, value)
def getBookCount(self):
return self._db.execScalar("SELECT COUNT(*) FROM libbook").toLongLong()[0]
def getFilenameByBookId(self, bookid):
return self._db.execScalar("SELECT filename FROM libfilename WHERE bookid = ?",
bookid).toString()
def getGroupsBookIn(self, bookid):
query = self._db.newQuery()
query.prepare("SELECT groupid, groupname FROM libgroup JOIN libgrouplist USING(groupid) WHERE bookid = ?")
query.addBindValue(bookid)
if not query.exec_():
raise DatabaseError, query.lastError().text()
groups = []
while query.next():
groups.append((query.value(0).toInt()[0],
query.value(1).toString()))
return groups
def getGroupsBookNotIn(self, bookid):
query = self._db.newQuery()
query.prepare("SELECT groupid, groupname FROM libgrouplist WHERE groupid NOT IN (SELECT groupid FROM libgroup WHERE bookid = ?)")
query.addBindValue(bookid)
if not query.exec_():
raise DatabaseError, query.lastError().text()
groups = []
while query.next():
groups.append((query.value(0).toInt()[0],
query.value(1).toString()))
return groups
def addBookToGroup(self, bookid, groupid):
self._db.execUpdate("INSERT INTO libgroup(bookid, groupid) VALUES(?,?)",
bookid, groupid)
def removeBookFromGroup(self, bookid, groupid):
self._db.execUpdate("DELETE FROM libgroup WHERE bookid = ? AND groupid = ?",
bookid, groupid)
def addGroup(self, groupname):
self._db.execUpdate("INSERT OR IGNORE INTO libgrouplist(groupname) VALUES(?)",
groupname)
def removeGroup(self, groupid):
db = self._db
db.transaction()
try:
db.execUpdate("DELETE FROM libgroup WHERE groupid = ?",
groupid)
db.execUpdate("DELETE FROM libgrouplist WHERE groupid = ?",
groupid)
except DatabaseError:
db.rollback()
raise
else:
#.........这里部分代码省略.........