@@ -8000,11 +8000,18 @@ namespace http {
8000
8000
}
8001
8001
8002
8002
char szOrderBy[50];
8003
- if (order == "")
8003
+ std::string szQuery;
8004
+ bool isAlpha = true;
8005
+ const std::string orderBy = order.c_str();
8006
+ for(int i = 0; i < orderBy.size(); i++) {
8007
+ if( !isalpha(orderBy[i])) {
8008
+ isAlpha = false;
8009
+ }
8010
+ }
8011
+ if (order.empty() || (!isAlpha)) {
8004
8012
strcpy(szOrderBy, "A.[Order],A.LastUpdate DESC");
8005
- else
8006
- {
8007
- sprintf(szOrderBy, "A.[Order],A.%s ASC", order.c_str());
8013
+ } else {
8014
+ sprintf(szOrderBy, "A.[Order],A.%%s ASC");
8008
8015
}
8009
8016
8010
8017
unsigned char tempsign = m_sql.m_tempsign[0];
@@ -8065,14 +8072,16 @@ namespace http {
8065
8072
" WHERE (C.FloorplanID=='%q') AND (C.ID==B.PlanID) AND (B.DeviceRowID==a.ID)"
8066
8073
" AND (B.DevSceneType==1) ORDER BY B.[Order]",
8067
8074
floorID.c_str());
8068
- else
8069
- result = m_sql.safe_query (
8075
+ else {
8076
+ szQuery = (
8070
8077
"SELECT A.ID, A.Name, A.nValue, A.LastUpdate, A.Favorite, A.SceneType,"
8071
8078
" A.Protected, B.XOffset, B.YOffset, B.PlanID, A.Description"
8072
8079
" FROM Scenes as A"
8073
8080
" LEFT OUTER JOIN DeviceToPlansMap as B ON (B.DeviceRowID==a.ID) AND (B.DevSceneType==1)"
8074
- " ORDER BY %q",
8075
- szOrderBy);
8081
+ " ORDER BY ");
8082
+ szQuery += szOrderBy;
8083
+ result = m_sql.safe_query(szQuery.c_str(), order.c_str());
8084
+ }
8076
8085
8077
8086
if (result.size() > 0)
8078
8087
{
@@ -8236,15 +8245,15 @@ namespace http {
8236
8245
bAllowDeviceToBeHidden = true;
8237
8246
}
8238
8247
8239
- if (order == "" )
8248
+ if (order.empty() || (!isAlpha) )
8240
8249
strcpy(szOrderBy, "A.[Order],A.LastUpdate DESC");
8241
8250
else
8242
8251
{
8243
- sprintf(szOrderBy, "A.[Order],A.%s ASC", order.c_str() );
8252
+ sprintf(szOrderBy, "A.[Order],A.%% s ASC");
8244
8253
}
8245
8254
//_log.Log(LOG_STATUS, "Getting all devices: order by %s ", szOrderBy);
8246
8255
if (hardwareid != "") {
8247
- result = m_sql.safe_query (
8256
+ szQuery = (
8248
8257
"SELECT A.ID, A.DeviceID, A.Unit, A.Name, A.Used,A.Type, A.SubType,"
8249
8258
" A.SignalLevel, A.BatteryLevel, A.nValue, A.sValue,"
8250
8259
" A.LastUpdate, A.Favorite, A.SwitchType, A.HardwareID,"
@@ -8255,11 +8264,12 @@ namespace http {
8255
8264
"FROM DeviceStatus as A LEFT OUTER JOIN DeviceToPlansMap as B "
8256
8265
"ON (B.DeviceRowID==a.ID) AND (B.DevSceneType==0) "
8257
8266
"WHERE (A.HardwareID == %q) "
8258
- "ORDER BY %q",
8259
- hardwareid.c_str(), szOrderBy);
8267
+ "ORDER BY ");
8268
+ szQuery += szOrderBy;
8269
+ result = m_sql.safe_query(szQuery.c_str(), hardwareid.c_str(), order.c_str());
8260
8270
}
8261
8271
else {
8262
- result = m_sql.safe_query (
8272
+ szQuery = (
8263
8273
"SELECT A.ID, A.DeviceID, A.Unit, A.Name, A.Used,A.Type, A.SubType,"
8264
8274
" A.SignalLevel, A.BatteryLevel, A.nValue, A.sValue,"
8265
8275
" A.LastUpdate, A.Favorite, A.SwitchType, A.HardwareID,"
@@ -8269,8 +8279,9 @@ namespace http {
8269
8279
" A.Options "
8270
8280
"FROM DeviceStatus as A LEFT OUTER JOIN DeviceToPlansMap as B "
8271
8281
"ON (B.DeviceRowID==a.ID) AND (B.DevSceneType==0) "
8272
- "ORDER BY %q",
8273
- szOrderBy);
8282
+ "ORDER BY ");
8283
+ szQuery += szOrderBy;
8284
+ result = m_sql.safe_query(szQuery.c_str(), order.c_str());
8274
8285
}
8275
8286
}
8276
8287
}
@@ -8351,14 +8362,14 @@ namespace http {
8351
8362
bAllowDeviceToBeHidden = true;
8352
8363
}
8353
8364
8354
- if (order == "" )
8365
+ if (order.empty() || (!isAlpha) )
8355
8366
strcpy(szOrderBy, "A.[Order],A.LastUpdate DESC");
8356
8367
else
8357
8368
{
8358
- sprintf(szOrderBy, "A.[Order],A.%s ASC", order.c_str() );
8369
+ sprintf(szOrderBy, "A.[Order],A.%% s ASC");
8359
8370
}
8360
8371
// _log.Log(LOG_STATUS, "Getting all devices for user %lu", m_users[iUser].ID);
8361
- result = m_sql.safe_query (
8372
+ szQuery = (
8362
8373
"SELECT A.ID, A.DeviceID, A.Unit, A.Name, A.Used,"
8363
8374
" A.Type, A.SubType, A.SignalLevel, A.BatteryLevel,"
8364
8375
" A.nValue, A.sValue, A.LastUpdate, A.Favorite,"
@@ -8371,8 +8382,9 @@ namespace http {
8371
8382
"FROM DeviceStatus as A, SharedDevices as B "
8372
8383
"LEFT OUTER JOIN DeviceToPlansMap as C ON (C.DeviceRowID==A.ID)"
8373
8384
"WHERE (B.DeviceRowID==A.ID)"
8374
- " AND (B.SharedUserID==%lu) ORDER BY %q",
8375
- m_users[iUser].ID, szOrderBy);
8385
+ " AND (B.SharedUserID==%lu) ORDER BY ");
8386
+ szQuery += szOrderBy;
8387
+ result = m_sql.safe_query(szQuery.c_str(), m_users[iUser].ID, order.c_str());
8376
8388
}
8377
8389
}
8378
8390
0 commit comments