def sql query -------------------- ------ Коннектимся Базе данных ----

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def sql(query):
#--------------------------
# Коннектимся к Базе данных
#--------------------------
connection = 0
try:
#conn = sqlite3.connect(":memory:")
cur = conn.cursor()
connection = 1
except sqlite3.Error:
connection = 0
if ((query=='def') and (connection == 1)):
try:
cur.execute("Select * from user")
conn.commit()
return(cur)
except:
print 'db not issue. Creating.'
cur.execute('''CREATE TABLE [user] ([id] INTEGER NOT NULL ON CONFLICT ABORT PRIMARY KEY ON CONFLICT ABORT AUTOINCREMENT, [jid] CHAR NOT NULL ON CONFLICT ABORT, [btc] CHAR NOT NULL ON CONFLICT ABORT, [ballance] FLOAT NOT NULL ON CONFLICT ABORT DEFAULT 0)''')
cur.execute("insert into user values (null,'user@tets.im','1F9LHP3DhGwanTW8dYMwEAUz4Aa8YgxtQE','0')")
conn.commit()
if ((query != 'def') and (connection == 1)):
try:
cur.execute(query)
return(cur)
except:
print "BAD SQL Query"