1
0

remove db table prefixes

This commit is contained in:
Mike Schwörer 2018-02-03 14:53:30 +01:00
parent 07227175af
commit e9bd5a783c
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
5 changed files with 61 additions and 18 deletions

47
data/schema.sql Normal file
View File

@ -0,0 +1,47 @@
CREATE TABLE IF NOT EXISTS an_statslog
(
ClientID varchar(256) NOT NULL,
Version varchar(256) DEFAULT NULL,
ProviderStr varchar(256) DEFAULT NULL,
ProviderID varchar(256) DEFAULT NULL,
NoteCount int(11) DEFAULT NULL,
LastChanged datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
CreatedAt datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
Comment varchar(1024) DEFAULT NULL,
PRIMARY KEY (ClientID)
);
CREATE TABLE IF NOT EXISTS highscoreentries
(
GAME_ID int(11) NOT NULL,
POINTS bigint(20) DEFAULT NULL,
PLAYER varchar(15) NOT NULL,
PLAYERID int(11) NOT NULL DEFAULT '-1',
CHECKSUM char(32) NOT NULL,
TIMESTAMP timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
IP char(41) NOT NULL,
PRIMARY KEY (CHECKSUM),
KEY GAME_ID (GAME_ID,POINTS,PLAYER)
);
CREATE TABLE IF NOT EXISTS highscoregames
(
ID int(11) NOT NULL AUTO_INCREMENT,
NAME varchar(63) NOT NULL,
SALT char(6) NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS updateslog
(
ID int(11) NOT NULL AUTO_INCREMENT,
programname varchar(64) NOT NULL DEFAULT '0',
ip varchar(24) DEFAULT NULL,
version varchar(64) DEFAULT NULL,
date datetime DEFAULT NULL,
PRIMARY KEY (ID)
);

View File

@ -203,11 +203,7 @@ try {
} }
//TODO fast
//TODO gzip (?) //TODO gzip (?)
//TODO better gh widget
//TODO remove db table prefixes
//TODO euler insert+show 32bit | 64bit mode //TODO euler insert+show 32bit | 64bit mode
//TODO send cache header (?) //TODO send cache header (?)
//TODO v4 subdomain+static //TODO v4 subdomain+static

View File

@ -6,21 +6,21 @@ class AlephNoteStatistics
{ {
public static function getTotalUserCount() public static function getTotalUserCount()
{ {
return Database::sql_query_num('SELECT COUNT(*) FROM ms4_an_statslog WHERE NoteCount>0'); return Database::sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0');
} }
public static function getUserCountFromLastVersion() public static function getUserCountFromLastVersion()
{ {
return Database::sql_query_num('SELECT COUNT(*) FROM ms4_an_statslog WHERE NoteCount>0 AND Version = (SELECT Version FROM ms4_an_statslog ORDER BY Version DESC LIMIT 1)'); return Database::sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 AND Version = (SELECT Version FROM an_statslog ORDER BY Version DESC LIMIT 1)');
} }
public static function getActiveUserCount($days) public static function getActiveUserCount($days)
{ {
return Database::sql_query_num('SELECT COUNT(*) FROM ms4_an_statslog WHERE NoteCount>0 AND LastChanged > NOW() - INTERVAL '.$days.' DAY'); return Database::sql_query_num('SELECT COUNT(*) FROM an_statslog WHERE NoteCount>0 AND LastChanged > NOW() - INTERVAL '.$days.' DAY');
} }
public static function getAllActiveEntriesOrdered() public static function getAllActiveEntriesOrdered()
{ {
return Database::sql_query_assoc('SELECT * FROM ms4_an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC'); return Database::sql_query_assoc('SELECT * FROM an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC');
} }
} }

View File

@ -14,7 +14,7 @@ class Highscores
public static function insert($gameid, $points, $name, $playerid, $check, $time, $ip) public static function insert($gameid, $points, $name, $playerid, $check, $time, $ip)
{ {
return Database::sql_exec_prep('INSERT INTO ms4_highscoreentries (GAME_ID, POINTS, PLAYER, PLAYERID, CHECKSUM, TIMESTAMP, IP) VALUES (:gid, :p, :pn, :pid, :cs, :ts, :ip)', return Database::sql_exec_prep('INSERT INTO highscoreentries (GAME_ID, POINTS, PLAYER, PLAYERID, CHECKSUM, TIMESTAMP, IP) VALUES (:gid, :p, :pn, :pid, :cs, :ts, :ip)',
[ [
[':gid', $gameid, PDO::PARAM_INT], [':gid', $gameid, PDO::PARAM_INT],
[':p', $points, PDO::PARAM_INT], [':p', $points, PDO::PARAM_INT],
@ -28,7 +28,7 @@ class Highscores
public static function update($gameid, $points, $name, $playerid, $check, $time, $ip) public static function update($gameid, $points, $name, $playerid, $check, $time, $ip)
{ {
return Database::sql_exec_prep('UPDATE ms4_highscoreentries SET POINTS = :p, PLAYER = :pn, CHECKSUM = :cs, IP = :ip, TIMESTAMP = :ts WHERE GAME_ID = :gid AND PLAYERID = :pid', return Database::sql_exec_prep('UPDATE highscoreentries SET POINTS = :p, PLAYER = :pn, CHECKSUM = :cs, IP = :ip, TIMESTAMP = :ts WHERE GAME_ID = :gid AND PLAYERID = :pid',
[ [
[':gid', $gameid, PDO::PARAM_INT], [':gid', $gameid, PDO::PARAM_INT],
[':p', $points, PDO::PARAM_INT], [':p', $points, PDO::PARAM_INT],
@ -42,7 +42,7 @@ class Highscores
public static function getGameByID($gameid) public static function getGameByID($gameid)
{ {
return Database::sql_query_single_prep('SELECT * FROM ms4_highscoregames WHERE ID = :id', return Database::sql_query_single_prep('SELECT * FROM highscoregames WHERE ID = :id',
[ [
[ ':id', $gameid, PDO::PARAM_INT ], [ ':id', $gameid, PDO::PARAM_INT ],
]); ]);
@ -50,7 +50,7 @@ class Highscores
public static function getOrderedEntriesFromGame($gameid, $limit = null) public static function getOrderedEntriesFromGame($gameid, $limit = null)
{ {
$sql = 'SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC'; $sql = 'SELECT * FROM highscoreentries WHERE GAME_ID = :id ORDER BY POINTS DESC';
if ($limit !== null) $sql .= " LIMIT $limit"; if ($limit !== null) $sql .= " LIMIT $limit";
return Database::sql_query_assoc_prep($sql, return Database::sql_query_assoc_prep($sql,
@ -61,7 +61,7 @@ class Highscores
public static function getNewestEntriesFromGame($gameid, $limit = null) public static function getNewestEntriesFromGame($gameid, $limit = null)
{ {
$sql = 'SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :id ORDER BY TIMESTAMP DESC'; $sql = 'SELECT * FROM highscoreentries WHERE GAME_ID = :id ORDER BY TIMESTAMP DESC';
if ($limit !== null) $sql .= " LIMIT $limit"; if ($limit !== null) $sql .= " LIMIT $limit";
return Database::sql_query_assoc_prep($sql, return Database::sql_query_assoc_prep($sql,
@ -72,7 +72,7 @@ class Highscores
public static function getEntryCountFromGame($gameid) public static function getEntryCountFromGame($gameid)
{ {
return Database::sql_query_num_prep('SELECT COUNT(*) FROM ms4_highscoreentries WHERE GAME_ID = :id', return Database::sql_query_num_prep('SELECT COUNT(*) FROM highscoreentries WHERE GAME_ID = :id',
[ [
[ ':id', $gameid, PDO::PARAM_INT ] [ ':id', $gameid, PDO::PARAM_INT ]
]); ]);
@ -80,12 +80,12 @@ class Highscores
public static function getAllGames() public static function getAllGames()
{ {
return Database::sql_query_assoc('SELECT * FROM ms4_highscoregames'); return Database::sql_query_assoc('SELECT * FROM highscoregames');
} }
public static function getNextPlayerID($gameid) public static function getNextPlayerID($gameid)
{ {
return Database::sql_query_num_prep('SELECT MAX(PLAYERID)+1 AS NID FROM ms4_highscoreentries WHERE GAME_ID = :gid', return Database::sql_query_num_prep('SELECT MAX(PLAYERID)+1 AS NID FROM highscoreentries WHERE GAME_ID = :gid',
[ [
[ ':id', $gameid, PDO::PARAM_INT ] [ ':id', $gameid, PDO::PARAM_INT ]
]); ]);
@ -93,7 +93,7 @@ class Highscores
public static function getSpecificScore($gameid, $playerid) public static function getSpecificScore($gameid, $playerid)
{ {
return Database::sql_query_single_prep('SELECT * FROM ms4_highscoreentries WHERE GAME_ID = :gid AND PLAYERID = :pid', return Database::sql_query_single_prep('SELECT * FROM highscoreentries WHERE GAME_ID = :gid AND PLAYERID = :pid',
[ [
[ ':gid', $gameid, PDO::PARAM_INT ], [ ':gid', $gameid, PDO::PARAM_INT ],
[ ':pid', $playerid, PDO::PARAM_INT ], [ ':pid', $playerid, PDO::PARAM_INT ],

View File

@ -16,7 +16,7 @@
{ {
Database::connect(); Database::connect();
Database::sql_exec_prep('INSERT INTO ms4_an_statslog (ClientID, Version, ProviderStr, ProviderID, NoteCount) VALUES (:cid, :ver, :prv, :pid, :tnc) ON DUPLICATE KEY UPDATE Version=:v,ProviderStr=:pstr,ProviderID=:pid,NoteCount=:nc', Database::sql_exec_prep('INSERT INTO an_statslog (ClientID, Version, ProviderStr, ProviderID, NoteCount) VALUES (:cid, :ver, :prv, :pid, :tnc) ON DUPLICATE KEY UPDATE Version=:v,ProviderStr=:pstr,ProviderID=:pid,NoteCount=:nc',
[ [
[':cid', $cid, PDO::PARAM_STR], [':cid', $cid, PDO::PARAM_STR],
[':ver', $ver, PDO::PARAM_STR], [':ver', $ver, PDO::PARAM_STR],