本文整理汇总了Python中useless.db.midlevel.StatementCursor.fetchall方法的典型用法代码示例。如果您正苦于以下问题:Python StatementCursor.fetchall方法的具体用法?Python StatementCursor.fetchall怎么用?Python StatementCursor.fetchall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类useless.db.midlevel.StatementCursor
的用法示例。
在下文中一共展示了StatementCursor.fetchall方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addDbSchemaok
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import fetchall [as 别名]
def addDbSchemaok(self):
dlg = self.dialogs['new-schema']
schema = str(dlg.grid.entries['schema'].text())
self.manager.create_schema(schema)
cursor = StatementCursor(self.db.conn)
cursor.execute('set SESSION search_path to %s' % schema)
self.db.conn.commit()
cursor.execute('show search_path')
print cursor.fetchall()
kschema.create_schema(cursor)
self.refreshlistView()
示例2: Family
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import fetchall [as 别名]
class Family(object):
def __init__(self, conn):
object.__init__(self)
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.current = None
self.parent = SimpleRelation(self.conn, 'family_parent', 'family')
self.env = FamilyEnvironment(self.conn)
def set_family(self, family):
self.current = family
self.parent.set_current(family)
self.env.set_family(family)
def _check_family(self, family):
if family is not None:
return family
else:
family = self.current
if family is None:
raise Error, 'either pass a family argument or call set_family on this object'
return family
def get_related_families(self, families=[]):
rows = self.cursor.select(table='family_parent')
graph = kjGraph([(r.family, r.parent) for r in rows])
dfamilies = Set()
for fam in families:
dfamilies |= Set([fam]) | Set(graph.reachable(fam).items())
return dfamilies
def parent_rows(self, family=None):
family = self._check_family(family)
self.parent.set_clause(family)
rows = self.parent.cmd.select(fields=['parent'], order='parent')
self.parent.reset_clause()
return rows
def parents(self, family=None):
family = self._check_family(family)
rows = self.parent_rows(family)
return [x.parent for x in rows]
def environment_rows(self, family=None):
family = self._check_family(family)
clause = Eq('family', family)
args = dict(fields=['trait', 'name', 'value'], clause=clause, order=['trait', 'name'])
return self.env.cursor.select(**args)
def family_rows(self):
return self.cursor.select(fields=['family'], table='families', order='family')
def all_families(self):
return [r.family for r in self.family_rows()]
def get_all_defaults(self):
suite_cursor = SuiteCursor(self.conn)
suites = suite_cursor.get_suites()
stmt = select_multisuite_union(suites, 'variables')
print stmt
self.cursor.execute(stmt)
return self.cursor.fetchall()
def create_family(self, family):
if family not in self.all_families():
self.cursor.insert(table='families', data=dict(family=family))
else:
raise ExistsError, '%s already exists' % family
def delete_family(self, family=None):
family = self._check_family(family)
self.cursor.execute("select * from delete_family('%s')" % family)
def insert_parents(self, parents, family=None):
family = self._check_family(family)
self.parent.insert('parent', parents)
def delete_parents(self, parents=[], family=None):
family = self._check_family(family)
if not parents:
parents = self.parents()
if not parents:
return
table= 'family_parent'
clause = Eq('family', family) & In('parent', parents)
self.cursor.delete(table=table, clause=clause)
def FamilyData(self, families=[]):
# change sep here
sep = PAELLA_TRAIT_NAME_SEP
# we don't know what to do here
# it is possible to have an empty
# list of families, and if that's the
# case we don't need to make the
# list of [self.current] . I need to look
# for everywhere this method is called.
# In the installer, the family is never set,
# and we use the list of families provided
# by the profile and the machine. In this
# case, the families argument will always
#.........这里部分代码省略.........
示例3: BaseDatabase
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import fetchall [as 别名]
class BaseDatabase(QSqlDatabase):
def __init__(self, dsn, name, parent=None, objname=None):
deprecated('useless.kdedb.BaseDatabase is deprecated')
QSqlDatabase.__init__(self, 'QPSQL7', name, parent, objname)
if hasattr(dsn, 'items'): #if dsn is dictionary
self.conn = BasicConnection(**dsn)
self.setDatabaseName(dsn['dbname'])
self.setHostName(dsn['host'])
self.dbuser = dsn['user']
else: #else a conn was passed as dsn
self.conn = dsn
self.setDatabaseName(self.conn.conn.db)
self.setHostName(self.conn.conn.host)
self.dbuser = self.conn.conn.user
self.setUserName(self.dbuser)
self.stmt = Statement()
self.mcursor = StatementCursor(self.conn)
def set_table(self, table):
self.stmt.table = table
def set_clause(self, items, cmp='=', join='and'):
self.stmt.set_clause(items, cmp=cmp, join=join)
def set_data(self, data):
self.stmt.set(data)
def set_fields(self, fields):
self.stmt.fields = fields
def qdelete(self, table=None, clause=None):
query = self.stmt.delete(table=table, clause=clause)
return self.execStatement(query)
def qinsert(self, table=None, data=None):
query = self.stmt.insert(table=table, data=data)
return self.execStatement(query)
def qupdate(self, table=None, data=None, clause=None):
query = self.stmt.update(table=table, data=data, clause=clause)
return self.execStatement(query)
def qselect(self, fields=None, table=None, clause=None,
group=None, having=None, order=None):
query = self.stmt.select(fields=fields, table=table, clause=clause,
group=group, having=having, order=order)
return self.execStatement(query)
def delete(self, table=None, clause=None):
query = self.stmt.delete(table=table, clause=clause)
return self.mcursor.execute(query)
def insert(self, table=None, data=None):
query = self.stmt.insert(table=table, data=data)
return self.mcursor.execute(query)
def update(self, table=None, data=None, clause=None):
query = self.stmt.update(table=table, data=data, clause=clause)
return self.mcursor.execute(query)
def select(self, fields=None, table=None, clause=None,
group=None, having=None, order=None):
query = self.stmt.select(fields=fields, table=table, clause=clause,
group=group, having=having, order=order)
self.mcursor.execute(query)
return self.mcursor.fetchall()
def select_row(self, fields=None, table=None, clause=None,
group=None, having=None, order=None):
query = self.stmt.select(fields=fields, table=table, clause=clause,
group=group, having=having, order=order)
self.mcursor.execute(query)
rows = len(self.mcursor)
if rows == 1:
return self.mcursor.next()
elif rows == 0:
raise NoExistError
else:
raise RuntimeError, 'bad row count %s' % rows
def clear(self, **args):
self.stmt.clear(**args)
def stdclause(self, data):
return reduce(and_, [Eq(k, v) for k,v in data.items()])
def insertData(self, idcol, table, data, commit=True):
clause = self.stdclause(data)
try:
self.mcursor.select_row(fields=[idcol], table=table, clause=clause)
except NoExistError:
self.mcursor.insert(table=table, data=data)
if commit:
self.conn.commit()
def identifyData(self, idcol, table, data, commit=True):
clause = self.stdclause(data)
self.insertData(idcol, table, data, commit=commit)
return self.mcursor.select_row(fields=['*'], table=table, clause=clause)
示例4: Family
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import fetchall [as 别名]
class Family(object):
def __init__(self, conn):
object.__init__(self)
self.conn = conn
self.cursor = StatementCursor(self.conn)
self.current = None
self.parent = SimpleRelation(self.conn, 'family_parent', 'family')
self.env = FamilyEnvironment(self.conn)
def set_family(self, family):
self.current = family
self.parent.set_current(family)
self.env.set_family(family)
def _check_family(self, family):
if family is not None:
return family
else:
family = self.current
if family is None:
raise Error, 'either pass a family arguement or call set_family on this object'
return family
def add_family(self, family, type='general'):
pass
def get_related_families(self, families=[]):
rows = self.cursor.select(table='family_parent')
graph = kjGraph([(r.family, r.parent) for r in rows])
dfamilies = Set()
for fam in families:
dfamilies |= Set([fam]) | Set(graph.reachable(fam).items())
return dfamilies
def parent_rows(self, family=None):
family = self._check_family(family)
self.parent.set_clause(family)
rows = self.parent.cmd.select(fields=['parent'], order='parent')
self.parent.reset_clause()
return rows
def parents(self, family=None):
family = self._check_family(family)
rows = self.parent_rows(family)
return [x.parent for x in rows]
def environment_rows(self, family=None):
family = self._check_family(family)
clause = Eq('family', family)
args = dict(fields=['trait', 'name', 'value'], clause=clause, order=['trait', 'name'])
return self.env.cursor.select(**args)
def family_rows(self):
return self.cursor.select(fields=['family'], table='families', order='family')
def all_families(self):
return [r.family for r in self.family_rows()]
def get_all_defaults(self):
suite_cursor = SuiteCursor(self.conn)
suites = suite_cursor.get_suites()
stmt = select_multisuite_union(suites, 'variables')
print stmt
self.cursor.execute(stmt)
return self.cursor.fetchall()
def create_family(self, family):
if family not in self.all_families():
self.cursor.insert(table='families', data=dict(family=family))
else:
raise ExistsError, '%s already exists' % family
def insert_parents(self, parents, family=None):
family = self._check_family(family)
self.parent.insert('parent', parents)
def FamilyData(self, families=[]):
if families is None:
families = [self.current]
all = self.make_familylist(families)
superdict = {}
for f in all:
superdict.update(self.env.make_tagdict(f))
return superdict
def make_familylist(self, families):
deps = families
all = list(self.get_related_families(families))
setfun = self.set_family
parfun = self.parents
return make_deplist(deps, all, setfun, parfun)
def export_family(self, family=None):
if family is None:
family = self.current
element = FamilyElement(family)
element.append_parents(self.parents(family))
element.append_variables(self.environment_rows(family))
#.........这里部分代码省略.........
示例5: BaseDatabase
# 需要导入模块: from useless.db.midlevel import StatementCursor [as 别名]
# 或者: from useless.db.midlevel.StatementCursor import fetchall [as 别名]
class BaseDatabase(object):
def __init__(self, conn=None):
if conn is None:
self.conn = KonsultantConnection()
else:
self.conn = conn
self.stmt = Statement()
self.mcursor = StatementCursor(self.conn)
def set_table(self, table):
self.stmt.table = table
def set_clause(self, items, cmp='=', join='and'):
self.stmt.set_clause(items, cmp=cmp, join=join)
def set_data(self, data):
self.stmt.set(data)
def set_fields(self, fields):
self.stmt.fields = fields
def delete(self, table=None, clause=None):
query = self.stmt.delete(table=table, clause=clause)
return self.mcursor.execute(query)
def insert(self, table=None, data=None):
query = self.stmt.insert(table=table, data=data)
return self.mcursor.execute(query)
def update(self, table=None, data=None, clause=None):
query = self.stmt.update(table=table, data=data, clause=clause)
return self.mcursor.execute(query)
def select(self, fields=None, table=None, clause=None,
group=None, having=None, order=None):
query = self.stmt.select(fields=fields, table=table, clause=clause,
group=group, having=having, order=order)
self.mcursor.execute(query)
return self.mcursor.fetchall()
def select_row(self, fields=None, table=None, clause=None,
group=None, having=None, order=None):
query = self.stmt.select(fields=fields, table=table, clause=clause,
group=group, having=having, order=order)
self.mcursor.execute(query)
rows = len(self.mcursor)
if rows == 1:
return self.mcursor.next()
elif rows == 0:
raise NoExistError
else:
raise Error, 'bad row count %s' % rows
def clear(self, **args):
self.stmt.clear(**args)
def stdclause(self, data):
return reduce(and_, [Eq(k, v) for k,v in data.items()])
def insertData(self, idcol, table, data, commit=True):
clause = self.stdclause(data)
try:
self.mcursor.select_row(fields=[idcol], table=table, clause=clause)
except NoExistError:
self.mcursor.insert(table=table, data=data)
if commit:
self.conn.commit()
def identifyData(self, idcol, table, data, commit=True):
clause = self.stdclause(data)
self.insertData(idcol, table, data, commit=commit)
return self.mcursor.select_row(fields=['*'], table=table, clause=clause)