summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-02-14 17:04:42 -0200
committershennetsind <ind@henn.et>2013-02-14 17:15:36 -0200
commit810ba40b78087cc6aa7eb9ad3a3e46534393b9e8 (patch)
treee205d88bc02194101fc2a7aa2d80e5d884fe8a9c /src/common
parent20abc4a94a4bd3a7428c042cc6d1c313272fbc28 (diff)
downloadhercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.tar.gz
hercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.tar.bz2
hercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.tar.xz
hercules-810ba40b78087cc6aa7eb9ad3a3e46534393b9e8.zip
Introducing MySQL DB Update Checker
First version. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/sql.c47
-rw-r--r--src/common/sql.h2
2 files changed, 48 insertions, 1 deletions
diff --git a/src/common/sql.c b/src/common/sql.c
index b842db46d..fdb6e0114 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -1016,6 +1016,53 @@ void Sql_inter_server_read(const char* cfgName, bool first) {
return;
}
+void Sql_HerculesUpdateCheck(Sql* self) {
+ char line[22];// "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
+ FILE* ifp;/* index fp */
+ unsigned int performed = 0;
+
+ if( !( ifp = fopen("sql-files/upgrades/index.txt", "r") ) ) {
+ ShowError("SQL upgrade index was not found!\n");
+ return;
+ }
+
+ while(fgets(line, sizeof(line), ifp)) {
+ char path[41];// "sql-files/upgrades/" (19) + "yyyy-mm-dd--hh-mm" (17) + ".sql" (4) + 1
+ char timestamp[11];// "1360186680" (10) + 1
+ FILE* ufp;/* upgrade fp */
+
+ sprintf(path,"sql-files/upgrades/%s",line);
+
+ if( !( ufp = fopen(path, "r") ) ) {
+ ShowError("SQL upgrade file %s was not found!\n",path);
+ continue;
+ }
+
+ if( fgetc(ufp) != '#' )
+ continue;
+
+ fseek (ufp,1,SEEK_SET);/* woo. skip the # */
+
+ if( fgets(timestamp,sizeof(timestamp),ufp) ) {
+ unsigned int timestampui = atol(timestamp);
+ if( SQL_ERROR == Sql_Query(self, "SELECT 1 FROM `sql_updates` WHERE `timestamp` = '%u' LIMIT 1", timestampui) )
+ Sql_ShowDebug(self);
+ if( Sql_NumRows(self) != 1 ) {
+ ShowSQL("'"CL_WHITE"%s"CL_RESET"' wasn't applied to the database\n",path);
+ performed++;
+ }
+ }
+
+ fclose(ufp);
+ }
+
+ fclose(ifp);
+
+ if( performed ) {
+ ShowSQL("If you did apply these updates or would like to be skip, insert a new entry in your sql_updates table with the timestamp of each file\n");
+ }
+}
+
void Sql_Init(void) {
Sql_inter_server_read("conf/inter-server.conf",true);
}
diff --git a/src/common/sql.h b/src/common/sql.h
index b7159ec90..ebbd1711f 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -325,7 +325,7 @@ int SqlStmt_NextRow(SqlStmt* self);
/// Frees the result of the statement execution.
void SqlStmt_FreeResult(SqlStmt* self);
-
+void Sql_HerculesUpdateCheck(Sql* self);
#if defined(SQL_REMOVE_SHOWDEBUG)
#define SqlStmt_ShowDebug(self) (void)0