@@ -387,35 +387,37 @@ func (u *userStore) listUsers(filters map[string]string, offset uint32, limit ui
387
387
getSql += " AND user_type != 0 "
388
388
}
389
389
390
- args := make ([]interface {}, 0 )
391
- var index = 1
390
+ var (
391
+ args = make ([]interface {}, 0 )
392
+ idx = 1
393
+ )
392
394
393
395
if len (filters ) != 0 {
394
396
for k , v := range filters {
395
397
getSql += " AND "
396
398
countSql += " AND "
397
399
if k == NameAttribute {
398
400
if utils .IsPrefixWildName (v ) {
399
- getSql += " " + k + fmt .Sprintf (" like $%d " , index )
400
- countSql += " " + k + fmt .Sprintf (" like $%d " , index )
401
+ getSql += " " + k + fmt .Sprintf (" like $%d " , idx )
402
+ countSql += " " + k + fmt .Sprintf (" like $%d " , idx )
401
403
args = append (args , "%" + v [:len (v )- 1 ]+ "%" )
402
404
} else {
403
- getSql += " " + k + fmt .Sprintf (" = $%d " , index )
404
- countSql += " " + k + fmt .Sprintf (" = $%d " , index )
405
+ getSql += " " + k + fmt .Sprintf (" = $%d " , idx )
406
+ countSql += " " + k + fmt .Sprintf (" = $%d " , idx )
405
407
args = append (args , v )
406
408
}
407
409
} else if k == OwnerAttribute {
408
- getSql += fmt .Sprintf (" (id = $%d OR owner = $%d) " , index , index + 1 )
409
- countSql += fmt .Sprintf (" (id = $%d OR owner = $%d) " , index , index + 1 )
410
- index += 1
410
+ getSql += fmt .Sprintf (" (id = $%d OR owner = $%d) " , idx , idx + 1 )
411
+ countSql += fmt .Sprintf (" (id = $%d OR owner = $%d) " , idx , idx + 1 )
412
+ idx += 2
411
413
args = append (args , v , v )
412
414
continue
413
415
} else {
414
- getSql += " " + k + fmt .Sprintf (" = $%d " , index )
415
- countSql += " " + k + fmt .Sprintf (" = $%d " , index )
416
+ getSql += " " + k + fmt .Sprintf (" = $%d " , idx )
417
+ countSql += " " + k + fmt .Sprintf (" = $%d " , idx )
416
418
args = append (args , v )
417
419
}
418
- index ++
420
+ idx ++
419
421
}
420
422
}
421
423
@@ -424,7 +426,7 @@ func (u *userStore) listUsers(filters map[string]string, offset uint32, limit ui
424
426
return 0 , nil , store .Error (err )
425
427
}
426
428
427
- getSql += fmt .Sprintf (" ORDER BY mtime LIMIT $%d OFFSET $%d" , index , index + 1 )
429
+ getSql += fmt .Sprintf (" ORDER BY mtime LIMIT $%d OFFSET $%d" , idx , idx + 1 )
428
430
getArgs := append (args , limit , offset )
429
431
430
432
users , err := u .collectUsers (u .master .Query , getSql , getArgs )
@@ -456,7 +458,7 @@ func (u *userStore) listGroupUsers(filters map[string]string, offset uint32, lim
456
458
querySql += " AND u.user_type != 0 "
457
459
}
458
460
459
- var index = 1
461
+ var idx = 1
460
462
461
463
for k , v := range filters {
462
464
if newK , ok := userLinkGroupAttributeMapping [k ]; ok {
@@ -468,24 +470,24 @@ func (u *userStore) listGroupUsers(filters map[string]string, offset uint32, lim
468
470
}
469
471
470
472
if utils .IsPrefixWildName (v ) {
471
- querySql += " AND " + k + fmt .Sprintf (" like $%d" , index )
472
- countSql += " AND " + k + fmt .Sprintf (" like $%d" , index )
473
+ querySql += " AND " + k + fmt .Sprintf (" like $%d" , idx )
474
+ countSql += " AND " + k + fmt .Sprintf (" like $%d" , idx )
473
475
args = append (args , v [:len (v )- 1 ]+ "%" )
474
476
} else {
475
- querySql += " AND " + k + fmt .Sprintf (" = $%d" , index )
476
- countSql += " AND " + k + fmt .Sprintf (" = $%d" , index )
477
+ querySql += " AND " + k + fmt .Sprintf (" = $%d" , idx )
478
+ countSql += " AND " + k + fmt .Sprintf (" = $%d" , idx )
477
479
args = append (args , v )
478
480
}
479
481
480
- index ++
482
+ idx ++
481
483
}
482
484
483
485
count , err := queryEntryCount (u .slave , countSql , args )
484
486
if err != nil {
485
487
return 0 , nil , err
486
488
}
487
489
488
- querySql += fmt .Sprintf (" ORDER BY u.mtime LIMIT $%d OFFSET $%d" , index , index + 1 )
490
+ querySql += fmt .Sprintf (" ORDER BY u.mtime LIMIT $%d OFFSET $%d" , idx , idx + 1 )
489
491
args = append (args , limit , offset )
490
492
491
493
users , err := u .collectUsers (u .master .Query , querySql , args )
0 commit comments