本文整理汇总了Python中mydb.close_db函数的典型用法代码示例。如果您正苦于以下问题:Python close_db函数的具体用法?Python close_db怎么用?Python close_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了close_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store_message_in_database
def store_message_in_database(_from, _to, msg):
mydb.open()
ISOTIMEFORMAT='%Y-%m-%d %X'
createdTime=str(time.strftime( ISOTIMEFORMAT, time.localtime() ))
result = mydb.insert_db('insert into message(_from,_to,msg,createdAt) values(?,?,?,?)',
[_from,_to,msg,createdTime])
mydb.close_db()
示例2: delete_pattern
def delete_pattern(pattern_id):
mydb.open()
mydb.delete_db('delete from edge where _from = ? or _to = ?',[pattern_id, pattern_id])
mydb.delete_db('delete from pattern where pid=?', [pattern_id])
mydb.delete_db('delete from node where pid=? and node_index = 1', [pattern_id])
mydb.close_db()
return True
示例3: generate_graph
def generate_graph():
mydb.open()
graph= dict()
query = 'select * from edge'
result = mydb.query_db(query, one = False)
mydb.close_db()
inactive_pid_list=SendMessage.find_all_inactive_pid()
if not result==None:
for r in result:
f=r['_from']
t=r['_to']
if not f in inactive_pid_list and not t in inactive_pid_list:
# if the key is not exist in the graph
if f not in graph:
graph[f]=[t]
else:
temp_List=graph[f]
temp_List.append(t)
if t not in graph:
graph[t]=[f]
else:
temp_List=graph[t]
temp_List.append(f)
# print str(r['_from'])+' to '+ str(r['_to'])
return graph
示例4: delete_pattern
def delete_pattern(pattern_id):
mydb.open()
nodes = mydb.query_db('SELECT * FROM node WHERE pid = ?',[pattern_id])
if len(nodes) > 1:
return False
prohibited_node = []
results = mydb.query_db('SELECT * FROM pattern')
for p in results:
pid = p['pid']
re1 = mydb.query_db('SELECT * FROM edge WHERE _from = ?',[pid])
re2 = mydb.query_db('SELECT * FROM edge WHERE _to = ?',[pid])
if len(re1)+len(re2) == 1:
if len(re1) == 1:
pro = re1[0]['_to']
else:
pro = re2[0]['_from']
prohibited_node.append(pro)
print prohibited_node
if pid in prohibited_node:
mydb.close_db()
return False
else:
mydb.delete_db('delete from edge where _from = ? or _to = ?',[pattern_id, pattern_id])
mydb.delete_db('delete from pattern where pid=?', [pattern_id])
mydb.delete_db('delete from node where pid=? and node_index = 1', [pattern_id])
mydb.close_db()
return True
示例5: one_pattern_edge
def one_pattern_edge(pid):
edges = []
mydb.open()
results = mydb.query_db('SELECT * FROM edge WHERE _from = ?', [pid])
for e in results:
edges.append(e['_to'])
mydb.close_db()
return edges
示例6: add_connection
def add_connection(nid1,nid2):
mydb.open()
p1 = mydb.query_db('SELECT * FROM node WHERE nid = ?', [nid1], one = True)
p2 = mydb.query_db('SELECT * FROM node WHERE nid = ?', [nid2], one = True)
mydb.insert_db('INSERT INTO edge(_from, _to) VALUES (?,?)', [p1['pid'], p2['pid']])
mydb.close_db()
pass
示例7: change_pwd
def change_pwd(username,pwd):
mydb.open()
result=_valid_login_format(username,pwd)
if not result==None:
return result
mydb.insert_db("""update account set pwd=? WHERE username= ?""", [pwd, username])
mydb.close_db()
return None
示例8: delete_connection
def delete_connection(nid1,nid2):
mydb.open()
p1 = mydb.query_db('SELECT * FROM node WHERE nid = ?', [nid1], one = True)
p2 = mydb.query_db('SELECT * FROM node WHERE nid = ?', [nid2], one = True)
mydb.delete_db('delete from edge where _from = ? and _to = ?',[p1['pid'], p2['pid']])
mydb.delete_db('delete from edge where _from = ? and _to = ?',[p2['pid'], p1['pid']])
mydb.close_db()
pass
示例9: add_node
def add_node(pid,index):
mydb.open()
results = mydb.query_db('SELECT * FROM node WHERE pid = ? and node_index = ?', [pid, index/2] )
if len(results)!=0:
nid = mydb.insert_db('INSERT INTO node (pid,node_index,active) VALUES (?,?,1)',[pid,index])
mydb.close_db()
return nid
else:
return -1
示例10: get_node_byID
def get_node_byID(nid):
mydb.open()
# active =1 means it is active
result = mydb.query_db('select pid,node_index from node WHERE nid=?',[nid], one=True)
mydb.close_db()
if result:
# we only need pid, and node index for a node to find a path
node=Node(nid,result['pid'],result['node_index'])
return node
示例11: change_security_question
def change_security_question(index, q, a, username):
if len(a) == 0:
return -1
mydb.open()
query = 'update account set sq_%d= ?,as_%d=? WHERE username = ?' % (index, index)
print query
mydb.insert_db(query, [q, a, username])
mydb.close_db()
return 1
示例12: get_security_question
def get_security_question(username):
mydb.open()
result = mydb.query_db('select * from account WHERE username = ? ', [username], one=True)
mydb.close_db()
if result:
questions = question(result['sq_1'],result['as_1'],result['sq_2'],result['as_2'],result['sq_3'],result['as_3'])
return questions
else:
return None
示例13: add_pattern
def add_pattern(ps):
mydb.open()
pid = mydb.insert_db('INSERT INTO pattern (creator) VALUES (?)',['spikewang'])
print pid
nid = mydb.insert_db('INSERT INTO node (pid,node_index,active) VALUES (?,1,1)', [pid])
for p in ps:
mydb.insert_db('INSERT INTO edge(_from, _to) VALUES (?,?)',[pid,p])
mydb.close_db()
return (pid, nid)
示例14: get_all_users
def get_all_users():
mydb.open()
result = mydb.query_db('select * from account WHERE type = 0',[],one=False)
mydb.close_db()
userList=[]
for user in result:
dict = {'name':user['username'],'fname':user['fname'],'lname':user['lname']}
userList.append(dict)
return userList
示例15: transform_to_nidList
def transform_to_nidList(pid, path):
nidList=[]
mydb.open()
for index in path:
query='select nid from node WHERE pid=? AND node_index= ?'
result = mydb.query_db(query,[str(pid),index], one = True)
if not result==None:
nidList.append(result['nid'])
mydb.close_db()
return nidList