-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleDataBase.py
70 lines (58 loc) · 1.92 KB
/
ConsoleDataBase.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import operator
import sqlite3
import Configuratoins
def DataBaseDecrypter(DBName):
#This Method Decrypts Encrypted Input Sqlite Database File
Input = open (Configuratoins.CurrentWorkingDirectory + DBName, 'rb')
Output = open (Configuratoins.CurrentWorkingDirectory + 'Decrypted_' + DBName, 'ab')
Counter = 0
print 'Decrypter is running. please wait ...'.title()
while 1:
try:
byte = Input.read(1)
if not byte:
break
Wrapper = ((1+Counter)*(1+Counter)*1997)%991
Ucode = ord(byte)
newbyte = operator.xor(Ucode,Wrapper)
newbyte = operator.__and__(newbyte,255)
Output.write(chr(newbyte))
Counter += 1
except Exception as e:
print e.message
Input.close()
Output.close()
def DataBaseTableNames(DBName):
#This Method Returns All Table Names Of Given Database
TablesNameList = []
Input = Configuratoins.CurrentWorkingDirectory + DBName
try:
Conn = sqlite3.connect(Input)
Cursor = Conn.cursor()
for row in Cursor.execute('select name from sqlite_master where type = \'table\''):
TablesNameList.append(row[0])
return TablesNameList
except Exception as e :
print e.message
def ColumnsProperties(DbName, TableName):
#This Method Returns A Dictionary Of Columns Name And Column Type Of Given Table
Columns = {}
DataBasePath = Configuratoins.CurrentWorkingDirectory + DbName
try:
Conn = sqlite3.connect(DataBasePath)
Cursor = Conn.cursor()
for row in Cursor.execute('PRAGMA TABLE_INFO(%s)'%TableName):
Columns[row[1]] = row[2]
return Columns
except Exception as e:
print e.message
def ReadLastNRow(DbName, TableName, n):
DataBasePath = Configuratoins.CurrentWorkingDirectory + DbName
try:
Conn = sqlite3.connect(DataBasePath)
Cursor = Conn.cursor()
for row in Cursor.execute('select * from %s order by id DESC limit %s'%(TableName,n)):
print row
except Exception as e:
print e.message