@@ -1208,8 +1208,10 @@ func (d databaseService) executeSelectSQL(ctx context.Context, req *ExecuteSQLRe
1208
1208
}
1209
1209
selectReq .Fields = fields
1210
1210
}
1211
-
1212
- var complexCond * rdb.ComplexCondition
1211
+ var (
1212
+ finallyComplexCond * rdb.ComplexCondition
1213
+ complexCond * rdb.ComplexCondition
1214
+ )
1213
1215
var err error
1214
1216
if req .Condition != nil {
1215
1217
complexCond , err = convertCondition (ctx , req .Condition , fieldNameToPhysical , req .SQLParams )
@@ -1219,24 +1221,32 @@ func (d databaseService) executeSelectSQL(ctx context.Context, req *ExecuteSQLRe
1219
1221
}
1220
1222
1221
1223
// add rw mode
1224
+ var extraCondition * rdb.ComplexCondition
1222
1225
if tableInfo .RwMode == table .BotTableRWMode_LimitedReadWrite && req .UserID != "" {
1223
1226
cond := & rdb.Condition {
1224
1227
Field : database .DefaultUidColName ,
1225
1228
Operator : entity3 .OperatorEqual ,
1226
1229
Value : req .UserID ,
1227
1230
}
1231
+ extraCondition = & rdb.ComplexCondition {
1232
+ Conditions : []* rdb.Condition {cond },
1233
+ }
1234
+ }
1228
1235
1229
- if complexCond == nil {
1230
- complexCond = & rdb.ComplexCondition {
1231
- Conditions : []* rdb.Condition {cond },
1232
- }
1233
- } else {
1234
- complexCond .Conditions = append (complexCond .Conditions , cond )
1236
+ if extraCondition != nil {
1237
+ finallyComplexCond = & rdb.ComplexCondition {
1238
+ NestedConditions : []* rdb.ComplexCondition {
1239
+ complexCond ,
1240
+ extraCondition ,
1241
+ },
1242
+ Operator : entity3 .AND ,
1235
1243
}
1244
+ } else {
1245
+ finallyComplexCond = complexCond
1236
1246
}
1237
1247
1238
- if complexCond != nil {
1239
- selectReq .Where = complexCond
1248
+ if finallyComplexCond != nil {
1249
+ selectReq .Where = finallyComplexCond
1240
1250
}
1241
1251
1242
1252
if len (req .OrderByList ) > 0 {
@@ -1377,32 +1387,47 @@ func (d databaseService) executeUpdateSQL(ctx context.Context, req *ExecuteSQLRe
1377
1387
}
1378
1388
1379
1389
condParams := req .SQLParams [index :]
1380
- complexCond , err := convertCondition (ctx , req .Condition , fieldNameToPhysical , condParams )
1381
- if err != nil {
1382
- return - 1 , fmt .Errorf ("convert condition failed: %v" , err )
1390
+ var (
1391
+ finallyComplexCond * rdb.ComplexCondition
1392
+ complexCond * rdb.ComplexCondition
1393
+ )
1394
+ var err error
1395
+ if req .Condition != nil {
1396
+ complexCond , err = convertCondition (ctx , req .Condition , fieldNameToPhysical , condParams )
1397
+ if err != nil {
1398
+ return - 1 , fmt .Errorf ("convert condition failed: %v" , err )
1399
+ }
1383
1400
}
1384
1401
1385
1402
// add rw mode
1403
+ var extraCondition * rdb.ComplexCondition
1386
1404
if tableInfo .RwMode == table .BotTableRWMode_LimitedReadWrite && req .UserID != "" {
1387
1405
cond := & rdb.Condition {
1388
1406
Field : database .DefaultUidColName ,
1389
1407
Operator : entity3 .OperatorEqual ,
1390
1408
Value : req .UserID ,
1391
1409
}
1410
+ extraCondition = & rdb.ComplexCondition {
1411
+ Conditions : []* rdb.Condition {cond },
1412
+ }
1413
+ }
1392
1414
1393
- if complexCond == nil {
1394
- complexCond = & rdb.ComplexCondition {
1395
- Conditions : []* rdb.Condition {cond },
1396
- }
1397
- } else {
1398
- complexCond .Conditions = append (complexCond .Conditions , cond )
1415
+ if extraCondition != nil {
1416
+ finallyComplexCond = & rdb.ComplexCondition {
1417
+ NestedConditions : []* rdb.ComplexCondition {
1418
+ complexCond ,
1419
+ extraCondition ,
1420
+ },
1421
+ Operator : entity3 .AND ,
1399
1422
}
1423
+ } else {
1424
+ finallyComplexCond = complexCond
1400
1425
}
1401
1426
1402
1427
updateResp , err := d .rdb .UpdateData (ctx , & rdb.UpdateDataRequest {
1403
1428
TableName : physicalTableName ,
1404
1429
Data : updateData ,
1405
- Where : complexCond ,
1430
+ Where : finallyComplexCond ,
1406
1431
Limit : int64PtrToIntPtr (req .Limit ),
1407
1432
})
1408
1433
if err != nil {
@@ -1417,31 +1442,46 @@ func (d databaseService) executeDeleteSQL(ctx context.Context, req *ExecuteSQLRe
1417
1442
return - 1 , fmt .Errorf ("missing delete condition" )
1418
1443
}
1419
1444
1420
- complexCond , err := convertCondition (ctx , req .Condition , fieldNameToPhysical , req .SQLParams )
1421
- if err != nil {
1422
- return - 1 , fmt .Errorf ("convert condition failed: %v" , err )
1445
+ var (
1446
+ finallyComplexCond * rdb.ComplexCondition
1447
+ complexCond * rdb.ComplexCondition
1448
+ )
1449
+ var err error
1450
+ if req .Condition != nil {
1451
+ complexCond , err = convertCondition (ctx , req .Condition , fieldNameToPhysical , req .SQLParams )
1452
+ if err != nil {
1453
+ return - 1 , fmt .Errorf ("convert condition failed: %v" , err )
1454
+ }
1423
1455
}
1424
1456
1425
1457
// add rw mode
1458
+ var extraCondition * rdb.ComplexCondition
1426
1459
if tableInfo .RwMode == table .BotTableRWMode_LimitedReadWrite && req .UserID != "" {
1427
1460
cond := & rdb.Condition {
1428
1461
Field : database .DefaultUidColName ,
1429
1462
Operator : entity3 .OperatorEqual ,
1430
1463
Value : req .UserID ,
1431
1464
}
1465
+ extraCondition = & rdb.ComplexCondition {
1466
+ Conditions : []* rdb.Condition {cond },
1467
+ }
1468
+ }
1432
1469
1433
- if complexCond == nil {
1434
- complexCond = & rdb.ComplexCondition {
1435
- Conditions : []* rdb.Condition {cond },
1436
- }
1437
- } else {
1438
- complexCond .Conditions = append (complexCond .Conditions , cond )
1470
+ if extraCondition != nil {
1471
+ finallyComplexCond = & rdb.ComplexCondition {
1472
+ NestedConditions : []* rdb.ComplexCondition {
1473
+ complexCond ,
1474
+ extraCondition ,
1475
+ },
1476
+ Operator : entity3 .AND ,
1439
1477
}
1478
+ } else {
1479
+ finallyComplexCond = complexCond
1440
1480
}
1441
1481
1442
1482
deleteResp , err := d .rdb .DeleteData (ctx , & rdb.DeleteDataRequest {
1443
1483
TableName : physicalTableName ,
1444
- Where : complexCond ,
1484
+ Where : finallyComplexCond ,
1445
1485
Limit : int64PtrToIntPtr (req .Limit ),
1446
1486
})
1447
1487
if err != nil {
0 commit comments