]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/store/mysql/mysql_store.cpp
Fixed stupid things in MySQL backend.
[stg.git] / projects / stargazer / plugins / store / mysql / mysql_store.cpp
index 11c2def3b5c1d2ca0dc3b82fb036fa6afcc00e71..995ed5385d43141b806e6251e0059e8fe39f227c 100644 (file)
@@ -243,7 +243,7 @@ else
         }
         if (!ret)
         {
-            WriteServLog("MYSQL_STORE: Current DB schema version: %d", schemaVersion);
+            logger("MYSQL_STORE: Current DB schema version: %d", schemaVersion);
             MakeUpdates(sock);
         }
         mysql_close(sock);
@@ -500,8 +500,13 @@ if(!IsTablePresent("users",sock))
     res = "INSERT INTO users SET login='test',Address='',AlwaysOnline=0,"\
         "Credit=0.0,CreditExpire=0,Down=0,Email='',DisabledDetailStat=0,"\
         "StgGroup='',IP='192.168.1.1',Note='',Passive=0,Password='123456',"\
-        "Phone='', RealName='',Tariff='tariff',TariffChange='',Userdata0='',"\
-        "Userdata1='',";
+        "Phone='', RealName='',Tariff='tariff',TariffChange='',NAS='',";
+    
+    for (int i = 0; i < USERDATA_NUM; i++)
+        {
+        strprintf(&param, " Userdata%d='',", i);
+        res += param;
+        }
     
     for (int i = 0; i < DIR_NUM; i++)
         {
@@ -600,7 +605,7 @@ if (schemaVersion  < 1)
         return -1;
         }
     schemaVersion = 1;
-    WriteServLog("MYSQL_STORE: Updated DB schema to version %d", schemaVersion);
+    logger("MYSQL_STORE: Updated DB schema to version %d", schemaVersion);
     }
 return 0;
 }
@@ -676,9 +681,12 @@ return 0;
 //-----------------------------------------------------------------------------
 int MYSQL_STORE::AddUser(const std::string & login) const
 {
-sprintf(qbuf,"INSERT INTO users SET login='%s'", login.c_str());
-    
-if(MysqlSetQuery(qbuf))
+std::string query = "INSERT INTO users SET login='" + login + "',Note='',NAS=''";
+
+for (int i = 0; i < USERDATA_NUM; i++)
+    query += ",Userdata" + x2str(i) + "=''";
+
+if(MysqlSetQuery(query.c_str()))
 {
     errorStr = "Couldn't add user:\n";
     //errorStr += mysql_error(sock);
@@ -903,7 +911,7 @@ for (int i = 0; i < DIR_NUM; i++)
         mysql_close(sock);
         return -1;
         }
-    stat->down[i] = traff;
+    stat->monthDown[i] = traff;
 
     sprintf(s, "U%d", i);
     if (GetULongLongInt(row[startPos+i*2+1], &traff, 0) != 0)
@@ -913,7 +921,7 @@ for (int i = 0; i < DIR_NUM; i++)
         mysql_close(sock);
         return -1;
         }
-    stat->up[i] = traff;
+    stat->monthUp[i] = traff;
     }//for
 
 startPos += (2*DIR_NUM);
@@ -1033,10 +1041,10 @@ res = "UPDATE users SET";
 
 for (int i = 0; i < DIR_NUM; i++)
     {
-    strprintf(&param, " D%d=%lld,", i, stat.down[i]);
+    strprintf(&param, " D%d=%lld,", i, stat.monthDown[i]);
     res += param;
 
-    strprintf(&param, " U%d=%lld,", i, stat.up[i]);
+    strprintf(&param, " U%d=%lld,", i, stat.monthUp[i]);
     res += param;
     }
 
@@ -1196,10 +1204,10 @@ strprintf(&res, "INSERT INTO stat SET login='%s', month=%d, year=%d,",
     
 for (int i = 0; i < DIR_NUM; i++)
     {
-    strprintf(&param, " U%d=%lld,", i, stat.up[i]); 
+    strprintf(&param, " U%d=%lld,", i, stat.monthUp[i]); 
     res += param;
 
-    strprintf(&param, " D%d=%lld,", i, stat.down[i]);        
+    strprintf(&param, " D%d=%lld,", i, stat.monthDown[i]);        
     res += param;
     }