diff options
author | Mysterious <mysteriousragnarok@hotmail.com> | 2013-02-14 18:56:08 -0800 |
---|---|---|
committer | Mysterious <mysteriousragnarok@hotmail.com> | 2013-02-14 18:56:08 -0800 |
commit | 7fa99e3524cb9cafdc797bcfc779ae5e0f730c8e (patch) | |
tree | 3a6cb20957b1486d92f7f017e0e6048951112d87 /src/common/sql.c | |
parent | 52e8c428bfc64a2285710256496331bfff19b651 (diff) | |
parent | 74c31098137aae3e0bfc962e4685a7050409df78 (diff) | |
download | hercules-7fa99e3524cb9cafdc797bcfc779ae5e0f730c8e.tar.gz hercules-7fa99e3524cb9cafdc797bcfc779ae5e0f730c8e.tar.bz2 hercules-7fa99e3524cb9cafdc797bcfc779ae5e0f730c8e.tar.xz hercules-7fa99e3524cb9cafdc797bcfc779ae5e0f730c8e.zip |
Merge pull request #4 from HerculesWS/master
Merging Hercules Changes
Diffstat (limited to 'src/common/sql.c')
-rw-r--r-- | src/common/sql.c | 47 |
1 files changed, 47 insertions, 0 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); } |