本文整理汇总了Python中db函数的典型用法代码示例。如果您正苦于以下问题:Python db函数的具体用法?Python db怎么用?Python db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_profile
def create_profile(op, msg, usrid):
req = proto_profile.CreateProfile()
try:
req.ParseFromString(msg)
except:
raise IlleagalMsgExcept(op, '')
query = db().query(Profile)
pf = query.get(usrid)
if pf:
err = proto_common.RequestError()
err.errop = op
err.errno = ACCOUNT_EXIST
return opcode_response.REQUEST_ERROR, err.SerializeToString()
pf = Profile(usrid, req.nickname, 1, 0, 0, 0)
db().add(pf)
db().commit()
#db().flush()
log_root().info('create profile %d:%s' % (usrid, req.nickname))
ret = proto_profile.CreateProfileResponse()
return opcode_response.CREATE_PROFILE_RESPONSE, \
ret.SerializeToString()
示例2: redrawAll
def redrawAll(canvas, data):
#table
canvas.create_rectangle(5,5,data.width-5,data.height-5,fill = 'orange4')
canvas.create_rectangle(10,10,data.width-10,data.height-10,fill = 'green4')
#gametext
canvas.create_text(20,30,text = 'Players: %s' % ', '.join(data.botTuple),
anchor = 'sw', font = 'msserif 12')
drawAllActive(canvas, data)
#readout
if data.gameOver:
canvas.create_text(data.width/2, 40, text = 'Game Over',
fill = 'white', font = 'msserif 12 bold')
n = data.readoutCount!=None
if n and data.readoutCount>len(data.allHistories)-1 and not data.gameOver:
canvas.create_text(data.width/2, 40, text = 'Game Over',
fill = 'white', font = 'msserif 12 bold')
data.gameOver = True
if not n or data.readoutCount>len(data.allHistories)-1: pass
else:
currEvent = data.allHistories[data.readoutCount]
db('currEvent',currEvent)
readOut = parseEvent(data,currEvent)
db('readout',readOut)
if readOut!=None:
readoutParse(readOut,data,canvas,currEvent)
示例3: grade2
def grade2():
lastxs=db().select(db.zuoye.zuozhe).last().zuozhe
banji=db.auth_user[lastxs].banji
if len(request.args):
banji=request.args[0]
rows=db((db.keshi.xuenian==xuenian)&(db.keshi.xueqi==xueqi)&(db.keshi.nianji==2)).select(left=db.keshi.on(db.keshi.kecheng==db.course.id))
return dict(rows=rows,banji=banji)
示例4: get_by_tag
def get_by_tag():
"""
return list of images for the selected tag value
this is an ajax response - caller will expect json format
"""
if not request.vars.search: return []
tname = request.vars.search
if len(tname) < 2 : return []
try:
tg = db(db.xtg.name==tname).select().first()
except:
return ['No Matches Found']
if not tg: return ['No matches found']
#tg_eu = db(db.xtg.name=='EU').select().first()
rows = (db(db.xref.xtg==tg.id).select())
#rows = (db(db.xref.xtg==tg.id).select()).as_list()
imglist = []
for r in rows:
#imglist.append(r.xim.title)
# build array here for proprt table rendering by 'TABLE'
imglist.append([r.xim.title])
#xmlstr =""
#tbl = TABLE(TR(*rows) for rows in imglist).xml()
tbl = TABLE(*[TR(*rows) for rows in imglist])
return tbl
示例5: put
def put(self, record):
"""
stores a record
>>> db = setup_test()
>>> class Person(Record): pass
>>> class People(RecordStore): pass
>>> people = People(db, Person)
>>> sally = Person(name='Sally', age=25)
>>> sally
<Person {'name': 'Sally', 'age': 25}>
>>> id = people.put(Person(name='Sally', age=25))
>>> id
1L
>>> sally
<Person {'name': 'Sally', 'age': 25}>
>>> sally = people.get(id)
>>> sally
<Person {'name': 'Sally', 'age': 25}>
>>> sally.age = 35
>>> people.put(sally)
1L
>>> person = people.get(id)
>>> person
<Person {'name': 'Sally', 'age': 35}>
>>> id = people.put({'name':'James', 'age':15})
>>> id
2L
>>> people.get(id)
<Person {'name': 'James', 'age': 15}>
"""
keys = [k for k in record.keys() if k <> '_id']
values = [record[k] for k in keys]
datatypes = [repr(type(i)).strip("<type >").strip("'") for i in values]
values = [i for i in values]
valid_types = ['str','unicode','long','int','float','datetime.date','datetime.datetime','bool','NoneType']
db = self.db
for atype in datatypes:
if atype not in valid_types:
raise TypeException,'unsupported type <type %s>' % atype
if '_id' in record:
id = record['_id']
sc = ', '.join('%s=%s' % (i,'%s') for i in keys)
cmd = 'update %s set %s where id=%d' % (self.kind, sc, id)
db(cmd, *values)
else:
kc = ', '.join(keys)
placeholders = ','.join(['%s'] * len(keys))
cmd = 'insert into %s (%s) values (%s)' % (self.kind, kc, placeholders)
_id = db(cmd, *values)
id = record['_id'] = _id
return id
示例6: read_edges
def read_edges(identifier=None):
if identifier:
edge = db().find(Edge, Edge.identifier == identifier)
export = edge.one().serialize()
else:
all_edges = db().find(Edge)
export = map(lambda edge: edge.serialize(), all_edges)
return json.dumps(export)
示例7: read_nodes
def read_nodes(identifier=None):
if identifier:
node = db().find(Node, Node.identifier == identifier)
export = node.one().serialize()
else:
all_nodes = db().find(Node)
export = map(lambda node: node.serialize(), all_nodes)
return json.dumps(export)
示例8: createupdate_node
def createupdate_node():
req = request.get_json()
try:
identifier = req[u"id"]
node = db().find(Node, Node.identifier == identifier).one()
if node is None:
node = db().add(Node())
node.identifier = identifier
props = db().find(NodeProperty, NodeProperty.node_id == Node.id, Node.identifier == identifier)
for prop in props:
db().remove(prop)
for key, value in req[u"properties"].items():
prop = NodeProperty()
prop.key = unicode(key)
prop.value = unicode(value)
node.properties.add(prop)
db().commit()
except Exception, e:
db().rollback()
raise e
示例9: create_test_tables
def create_test_tables(db):
db("""
create table if not exists person (
id int not null auto_increment,
name varchar(100),
age smallint,
kids smallint,
birthdate date,
PRIMARY KEY (id)
)
""")
示例10: delete_edge
def delete_edge(identifier=None):
edge = db().find(Edge, Edge.identifier == identifier).one()
if not node:
raise Exception("not found")
db().remove(edge)
db().commit()
return ""
示例11: query_by_img
def query_by_img():
"""
get all tags for an image
"""
cnt = 0
img = db(db.xim.title=='Paris').select().first()
rows = (db(db.xref.xim==img.id).select())
tlist = []
for r in rows:
cnt +=1
tlist.append(r.xtg.name)
return
示例12: addwenti
def addwenti():
keshi_id=request.args[0]
keshi=db.keshi[keshi_id]
course=keshi.kecheng
timus=db(db.timu.course==course).select()
for timu in timus:
db.lianxi.update_or_insert(
(db.lianxi.keshi==keshi_id)&
(db.lianxi.timu==timu),
keshi=keshi_id,
timu=timu
)
lianxis=db(db.lianxi.keshi==keshi_id).select()
return dict(timus=timus,lianxis=lianxis)
示例13: uitslag
def uitslag():
T.force("nl")
jaar = str(mvhutils.huidigJaar())
kalender = db.kalender(db.kalender.jaar==jaar)
uitslagen = db(db.uitslag)._select(db.uitslag.wedstrijd, distinct=True)
print "uitslagen = ", uitslagen
wedstrijden = db((db.wedstrijd.kalender==kalender) &
(db.wedstrijd.id.belongs(uitslagen))).select(db.wedstrijd.id,
db.wedstrijd.datum,
db.wedstrijd.omschrijving,
orderby=db.wedstrijd.datum
)
print "wedstrijden = ", wedstrijden
return dict(wedstrijden=wedstrijden, jaar=jaar)
示例14: list_by_image
def list_by_image():
"""
build a dict of images and related tags
"""
imgs = db(db.xim.id>0).select()
imgdict = {}
for img in imgs:
rows = (db(db.xref.xim==img.id).select())
tlist = []
for r in rows:
tlist.append(r.xtg.name)
# key is a tuple of image title and tag count
dk = (img.title,len(tlist))
imgdict[dk] = tlist
return imgdict
示例15: historial
def historial():
C = Storage()
C.escuela = db.escuela(1)
menu_migas.append(T("Control de cambios"))
tbl_n = request.args(0)
r_id = int(request.args(1))
C.titulo = T("Historial de cambios TABLA: {} REGISTRO ID: {}").format(tbl_n, r_id)
tbl = db["{}_archive".format(tbl_n)]
query = (tbl.current_record == r_id)
for f in tbl:
f.readable = True
tbl.current_record.readable = False
C.current_record = SQLTABLE(db(db[tbl_n].id == r_id).select(),
headers="labels",
_class="table")
C.grid = SQLFORM.grid(query, args=request.args[:2],
orderby=[~tbl.modified_on],
create=False,
searchable=False,
editable=False,
deletable=False,
details=False,
csv=False)
return dict(C=C)