Create reports table

This commit is contained in:
Trevor Slocum 2020-11-13 12:40:35 -08:00
parent b985ded3ee
commit b225fc00a1
5 changed files with 42 additions and 2 deletions

View File

@ -27,6 +27,11 @@ if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . TINYIB_DBBANS . "'")) == 0
mysql_query($bans_sql);
}
// Create the reports table if it does not exist
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . TINYIB_DBREPORTS . "'")) == 0) {
mysql_query($reports_sql);
}
if (mysql_num_rows(mysql_query("SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'")) == 0) {
mysql_query("ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN stickied TINYINT(1) NOT NULL DEFAULT '0'");
}

View File

@ -27,6 +27,11 @@ if (mysqli_num_rows(mysqli_query($link, "SHOW TABLES LIKE '" . TINYIB_DBBANS . "
mysqli_query($link, $bans_sql);
}
// Create the reports table if it does not exist
if (mysqli_num_rows(mysqli_query($link, "SHOW TABLES LIKE '" . TINYIB_DBREPORTS . "'")) == 0) {
mysqli_query($link, $reports_sql);
}
if (mysqli_num_rows(mysqli_query($link, "SHOW COLUMNS FROM `" . TINYIB_DBPOSTS . "` LIKE 'stickied'")) == 0) {
mysqli_query($link, "ALTER TABLE `" . TINYIB_DBPOSTS . "` ADD COLUMN stickied TINYINT(1) NOT NULL DEFAULT '0'");
}

View File

@ -36,7 +36,6 @@ if (TINYIB_DBDRIVER === 'pgsql') {
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBPOSTS));
$posts_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
}
if (!$posts_exists) {
$dbh->exec($posts_sql);
}
@ -49,11 +48,22 @@ if (TINYIB_DBDRIVER === 'pgsql') {
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBBANS));
$bans_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
}
if (!$bans_exists) {
$dbh->exec($bans_sql);
}
// Create the reports table if it does not exist
if (TINYIB_DBDRIVER === 'pgsql') {
$query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename LIKE " . $dbh->quote(TINYIB_DBREPORTS);
$reports_exists = $dbh->query($query)->fetchColumn() != 0;
} else {
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBREPORTS));
$reports_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
}
if (!$reports_exists) {
$dbh->exec($reports_sql);
}
if (TINYIB_DBDRIVER === 'pgsql') {
$query = "SELECT column_name FROM information_schema.columns WHERE table_name='" . TINYIB_DBPOSTS . "' and column_name='moderated'";
$moderated_exists = $dbh->query($query)->fetchColumn() != 0;

View File

@ -56,6 +56,16 @@ if (!$result->fetchArray()) {
)");
}
// Create the reports table if it does not exist
$result = $db->query("SELECT name FROM sqlite_master WHERE type='table' AND name='" . TINYIB_DBREPORTS . "'");
if (!$result->fetchArray()) {
$db->exec("CREATE TABLE " . TINYIB_DBREPORTS . " (
id INTEGER PRIMARY KEY,
ip TEXT NOT NULL,
post INTEGER NOT NULL
)");
}
// Add moderated column if it isn't present
@$db->exec("ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '0'");

View File

@ -55,6 +55,16 @@ if (sqlite_num_rows($result) == 0) {
)");
}
// Create the reports table if it does not exist
$result = sqlite_query($db, "SELECT name FROM sqlite_master WHERE type='table' AND name='" . TINYIB_DBREPORTS . "'");
if (sqlite_num_rows($result) == 0) {
sqlite_query($db, "CREATE TABLE " . TINYIB_DBREPORTS . " (
id INTEGER PRIMARY KEY,
ip TEXT NOT NULL,
post INTEGER NOT NULL
)");
}
// Add moderated column if it isn't present
sqlite_query($db, "ALTER TABLE " . TINYIB_DBPOSTS . " ADD COLUMN moderated INTEGER NOT NULL DEFAULT '0'");