Fix duplicates check
This commit is contained in:
parent
a958b0268e
commit
8ac8951d8d
|
@ -199,8 +199,6 @@ public:
|
||||||
WITH all_addresses AS (
|
WITH all_addresses AS (
|
||||||
SELECT 'Functions' as table_name, name, address, filepath FROM Functions WHERE address != ''
|
SELECT 'Functions' as table_name, name, address, filepath FROM Functions WHERE address != ''
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 'Imports' as table_name, name, address, filepath FROM Imports WHERE address != ''
|
|
||||||
UNION ALL
|
|
||||||
SELECT 'Globals' as table_name, name, address, filepath FROM Globals WHERE address != ''
|
SELECT 'Globals' as table_name, name, address, filepath FROM Globals WHERE address != ''
|
||||||
)
|
)
|
||||||
SELECT address, COUNT(*) as count,
|
SELECT address, COUNT(*) as count,
|
||||||
|
@ -262,30 +260,6 @@ public:
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Imports table
|
|
||||||
const char *imports_sql = R"(
|
|
||||||
SELECT name, COUNT(*) as count,
|
|
||||||
GROUP_CONCAT(filepath, '; ') as filepaths
|
|
||||||
FROM Imports
|
|
||||||
GROUP BY name
|
|
||||||
HAVING COUNT(*) > 1
|
|
||||||
ORDER BY name;
|
|
||||||
)";
|
|
||||||
|
|
||||||
if (sqlite3_prepare_v2(db, imports_sql, -1, &stmt, nullptr) == SQLITE_OK) {
|
|
||||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
|
||||||
found_duplicates = true;
|
|
||||||
const char *name = (const char *)sqlite3_column_text(stmt, 0);
|
|
||||||
int count = sqlite3_column_int(stmt, 1);
|
|
||||||
const char *filepaths = (const char *)sqlite3_column_text(stmt, 2);
|
|
||||||
|
|
||||||
spdlog::error(
|
|
||||||
"DUPLICATE IMPORT NAME: '{}' appears {} times in files: {}", name,
|
|
||||||
count, filepaths);
|
|
||||||
}
|
|
||||||
sqlite3_finalize(stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Globals table
|
// Check Globals table
|
||||||
const char *globals_sql = R"(
|
const char *globals_sql = R"(
|
||||||
SELECT name, COUNT(*) as count,
|
SELECT name, COUNT(*) as count,
|
||||||
|
@ -734,24 +708,21 @@ bool dumpTreeFile(const std::string &filepath) {
|
||||||
bool processDuplicates(DatabaseManager &db) {
|
bool processDuplicates(DatabaseManager &db) {
|
||||||
spdlog::info("=== Checking for duplicate addresses ===");
|
spdlog::info("=== Checking for duplicate addresses ===");
|
||||||
bool found_address_duplicates = db.checkDuplicateAddresses();
|
bool found_address_duplicates = db.checkDuplicateAddresses();
|
||||||
|
if (found_address_duplicates) {
|
||||||
|
spdlog::error("Found duplicate addresses in the database!");
|
||||||
|
} else {
|
||||||
|
spdlog::info("No duplicate addresses found in the database.");
|
||||||
|
}
|
||||||
|
|
||||||
spdlog::info("=== Checking for duplicate names ===");
|
spdlog::info("=== Checking for duplicate names ===");
|
||||||
bool found_name_duplicates = db.checkDuplicateNames();
|
bool found_name_duplicates = db.checkDuplicateNames();
|
||||||
|
|
||||||
if (!found_address_duplicates && !found_name_duplicates) {
|
|
||||||
spdlog::info("No duplicates found in the database.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found_address_duplicates) {
|
|
||||||
spdlog::error("Found duplicate addresses in the database!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found_name_duplicates) {
|
if (found_name_duplicates) {
|
||||||
spdlog::error("Found duplicate names in the database!");
|
spdlog::error("Found duplicate names in the database!");
|
||||||
|
} else {
|
||||||
|
spdlog::info("No duplicate names found in the database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // Return false to indicate errors were found
|
return !found_address_duplicates && !found_name_duplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
Loading…
Reference in New Issue