Skip to content

Commit 3d3dabc

Browse files
Merge pull request #1 from GabrielTorelo/feat/ComparingSQLite
feat/ComparingSQLite - OK
2 parents 2d4d79f + 37cb8b0 commit 3d3dabc

17 files changed

Lines changed: 336 additions & 131 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*$py.class
55

66
# Local use
7-
MOCK/*
87
Output.json
98

109
# Distribution / packaging

MOCK/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore directory contents
2+
/OUTPUT_DB/*

MOCK/DATA/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore everything in this directory
2+
*
3+
!.gitignore

MOCK/PATTERN/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore everything in this directory
2+
*
3+
!.gitignore

constants/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .general import *
1+
from .general import *
2+
from .sqlite_queries import *

constants/general.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
TRACKING_CODE = 'PRJ0000.X.X'
1+
TRACKING_CODE = "PRJ0000.X.X"
2+
DB_PATHS = "MOCK/DATA"
3+
PATTERN_PATH = "MOCK/PATTERN"
4+
PATTERN_PATH_JSON = "MOCK/PATTERN/padrao_db.json"
5+
OUTPUT_DB_PATH = "MOCK/OUTPUT_DB"
6+
EXCLUDED_TABLES = {"android_metadata", "sqlite_sequence"}
7+
EXCLUDED_COLUMNS = {""}

constants/sqlite_queries.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SELECT_TABLES = "SELECT name FROM sqlite_master WHERE type='table';"
2+
PRAGMA_TABLE_INFO = "PRAGMA table_info(%s);"

dao/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .db_sqlite import *

dao/db_sqlite.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from sqlite3 import connect
2+
from err import Errors
3+
from constants import SELECT_TABLES, EXCLUDED_TABLES, EXCLUDED_COLUMNS, PRAGMA_TABLE_INFO
4+
5+
6+
def list_tables(db_path):
7+
tables_info = {}
8+
9+
try:
10+
connection = connect(db_path)
11+
cursor = connection.cursor()
12+
13+
cursor.execute(SELECT_TABLES)
14+
tables = [row[0] for row in cursor.fetchall()]
15+
16+
tables = sorted(tables)
17+
18+
for table in tables:
19+
if table in EXCLUDED_TABLES:
20+
continue
21+
22+
cursor.execute(PRAGMA_TABLE_INFO % table)
23+
columns = cursor.fetchall()
24+
25+
tables_info[table] = sorted([
26+
{'nome': col[1], 'tipo': col[2]} for col in columns if col[1] not in EXCLUDED_COLUMNS
27+
], key=lambda x: x['nome'])
28+
29+
connection.close()
30+
return tables_info
31+
except Exception as e:
32+
raise Errors(code=6, message=f"Error listing database tables: {e}")

err/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .errors import *
1+
from .errors import *

0 commit comments

Comments
 (0)