@@ -1158,29 +1158,52 @@ func uniqueHepTable(hepSlice []model.HepTable) []model.HepTable {
11581158 }
11591159}
11601160
1161- // this method create new user in the database
1162- // it doesn't check internally whether all the validation are applied or not
11631161func (ss * SearchService ) GetTransactionData (table string , fieldKey string , dataWhere []interface {}, timeFrom ,
11641162 timeTo time.Time , nodes []string , userGroup string , likeSearch bool , whitelist []string ) ([]model.HepTable , error ) {
11651163
11661164 searchData := []model.HepTable {}
1167- query := "create_date between ? AND ? "
11681165
1169- query += fmt .Sprintf ("AND %s %s ANY(ARRAY[?])" , fieldKey , heputils .GetSQLEqualityOperator (likeSearch ))
1166+ // Start with base query conditions
1167+ baseQuery := "create_date between ? AND ?"
1168+ params := []interface {}{
1169+ timeFrom .Format (time .RFC3339 ),
1170+ timeTo .Format (time .RFC3339 ),
1171+ }
1172+
1173+ // Handle the ANY condition differently - we'll construct it based on length of dataWhere
1174+ anyPlaceholders := make ([]string , len (dataWhere ))
1175+ for i := range anyPlaceholders {
1176+ anyPlaceholders [i ] = "?"
1177+ }
1178+
1179+ anyQueryPart := fmt .Sprintf ("AND %s %s ANY(ARRAY[%s])" ,
1180+ fieldKey ,
1181+ heputils .GetSQLEqualityOperator (likeSearch ),
1182+ strings .Join (anyPlaceholders , "," ))
1183+
1184+ query := baseQuery + " " + anyQueryPart
1185+ params = append (params , dataWhere ... )
11701186
1187+ logger .Debug ("GetTransactionData: " , table , fieldKey , dataWhere , timeFrom , timeTo , nodes , userGroup , likeSearch , whitelist )
11711188 logger .Debug ("ISOLATEGROUP " , config .Setting .MAIN_SETTINGS .IsolateGroup )
11721189 logger .Debug ("USERGROUP " , userGroup )
11731190
1191+ // Add isolation group condition if needed
11741192 if config .Setting .MAIN_SETTINGS .IsolateGroup != "" && config .Setting .MAIN_SETTINGS .IsolateGroup == userGroup {
11751193 query = query + " AND " + config .Setting .MAIN_SETTINGS .IsolateQuery
11761194 }
11771195
1178- var whitelistParams [] interface {}
1196+ // Add whitelist conditions
11791197 for _ , ip := range whitelist {
1180- query = query + " AND (protocol_header->>'srcIp' != ? AND protocol_header->>'dstIp' != ? ) "
1181- whitelistParams = append (whitelistParams , ip , ip )
1198+ query = query + " AND (protocol_header->>'srcIp' != ? AND protocol_header->>'dstIp' != ?) "
1199+ params = append (params , ip , ip )
11821200 }
11831201
1202+ // Debug the final query and parameters
1203+ logger .Debug ("Final query: " , query )
1204+ logger .Debug ("Params count: " , len (params ))
1205+ logger .Debug ("Params: " , params )
1206+
11841207 for session := range ss .Session {
11851208 /* if node doesnt exists - continue */
11861209 if ! heputils .ElementExists (nodes , session ) {
@@ -1190,15 +1213,15 @@ func (ss *SearchService) GetTransactionData(table string, fieldKey string, dataW
11901213 searchTmp := []model.HepTable {}
11911214 if err := ss .Session [session ].Debug ().
11921215 Table (table ).
1193- Where (query , append ([] interface {}{ timeFrom . Format ( time . RFC3339 ), timeTo . Format ( time . RFC3339 )}, append ( dataWhere , whitelistParams ... ) ... ) ... ).
1216+ Where (query , params ... ).
11941217 Find (& searchTmp ).Error ; err != nil {
11951218 logger .Error ("GetTransactionData: We have got error: " , err )
1219+ return nil , err
11961220 }
11971221
11981222 logger .Debug ("GetTransactionData: Len: " , len (searchTmp ))
11991223
12001224 if len (searchTmp ) > 0 {
1201-
12021225 profileName := strings .TrimPrefix (table , "hep_proto_" )
12031226
12041227 for val := range searchTmp {
@@ -1210,7 +1233,6 @@ func (ss *SearchService) GetTransactionData(table string, fieldKey string, dataW
12101233 }
12111234 }
12121235
1213- //response, _ := json.Marshal(searchData)
12141236 return searchData , nil
12151237}
12161238
0 commit comments