Python script to read SQLite files and check the differences between them.
This document provides a step-by-step guide to performing comparison between SQLite databases using the Database_Difference_Checker-Python_SQLite script.
- Table Filters: Edit the
constants/general.pyfile and add the names of the tables you want to exclude from the comparison within theEXCLUDED_TABLESconstant.EXCLUDED_TABLES = {"table1", "table2", "table3"} - Column Filters: Edit the same file and add the names of the columns to be excluded from the comparison within the
EXCLUDED_COLUMNSconstant.EXCLUDED_COLUMNS = {"column1", "column2", "column3"}
Place the SQLite (.db) files you want to compare inside the MOCK/DATA folder.
- For contexts of different databases (for example, databases from different companies), it is ideal, but not mandatory, to organize the databases in different folders within
MOCK/DATA.
Add the file with the reference data to the MOCK/PATTERN folder. The reference file can be in .txt, .json, .sqlite or .db format.
- The
.sqliteand.dbfiles take precedence over the others - The file must follow the pattern key-value (key: value), with the VALUE ALWAYS WRAPPED IN BRACKETS.
- Example 1 (without line break):
TABLE_1:[{...}]TABLE_2:[...]TABLE_3:[...] - Example 2 (with line break):
TABLE_1:[{...}, {...}] TABLE_2:[{...}] TABLE_3:[...]
{ "TABLE_1": [ { "name": "XXXX", "type": "XXXX" }, { "name": "XXXX", "type": "XXXX" } ], "TABLE_2": [ { "name": "XXXX", "type": "XXXX" } ], ... } - Example 1 (without line break):
After executing the script, check the trackingCode. The code 00 indicates that the process completed without errors (other tracking codes in the section below).
The comparison results will be saved in a JSON file in the project root folder, called Output.json .
{
"MAIN_DATABASE_1": {
"DATABASE_SQLite_1": {
"Missing_Tables": [...],
"Missing_Data": {
"TABLE_1": [
{
"name": "XXXX",
"type": "XXXX"
}
],
"TABLE_2": [...]
}
},
"DATABASE_SQLite_2": {...}
},
"MAIN_DATABASE_2": {...}
}
Tracking codes indicate the status of the process:
00: Finished without errors01: An unexpected error occurred02: Error reading file(s)03: Error reading file(s) from directory04: Error in the comparison process05: Error generatingOutput.jsonfile06: Error reading data from databases07: Error generating JSON from databases08: Error when fetching JSON files from databases09: Error creating reference JSON10: Invalid file extension
| Name | Version |
|---|---|
| 🐍 Python | 3.8.0 |