1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-26 10:36:23 -07:00

Properly handle multiple gochan databases in MySQL/Postgres, use wrapper for "Get posts with this IP" JSON request

This commit is contained in:
Eggbertx 2024-09-20 23:13:44 -07:00
parent 52adfc0847
commit 605972bd86
2 changed files with 27 additions and 10 deletions

View file

@ -377,9 +377,9 @@ func doesTableExist(tableName string) (bool, error) {
switch config.GetSQLConfig().DBtype {
case "mysql":
fallthrough
existQuery = `SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ? AND TABLE_SCHEMA = DATABASE()`
case "postgres":
existQuery = `SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?`
existQuery = `SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ? AND TABLE_CATALOG = CURRENT_DATABASE()`
case "sqlite3":
existQuery = `SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name = ?`
default:
@ -391,7 +391,7 @@ func doesTableExist(tableName string) (bool, error) {
if err != nil {
return false, err
}
return count == 1, nil
return count > 0, nil
}
// getDatabaseVersion gets the version of the database, or an error if none or multiple exist