@@ -52,7 +52,13 @@ func (gfkr GenericForeignKeyReverse) GetValues(
5252 panic (err )
5353 }
5454
55- idFilter := fmt .Sprintf ("%s in (%s)" , gfkr .OwnIDColumn , strings .Join (ids , ", " ))
55+ spots := []string {}
56+ args := []interface {}{}
57+ for index , id := range ids {
58+ spots = append (spots , fmt .Sprintf ("$%d" , index + 2 ))
59+ args = append (args , id )
60+ }
61+ idFilter := fmt .Sprintf ("%s in (%s)" , gfkr .OwnIDColumn , strings .Join (spots , ", " ))
5662 typeFilter := fmt .Sprintf ("%s = $1" , gfkr .OwnTypeColumn )
5763 query := fmt .Sprintf (
5864 `
@@ -70,7 +76,7 @@ func (gfkr GenericForeignKeyReverse) GetValues(
7076 typeFilter ,
7177 order ,
7278 )
73- rows , err := c .Query (query , gfkr .OwnType )
79+ rows , err := c .Query (query , append ([] interface {}{ gfkr .OwnType }, args ... ) ... )
7480 if err != nil {
7581 panic (err )
7682 }
@@ -290,12 +296,14 @@ func (gfkr *GenericForeignKeyReverse) GetInsertQueries(
290296 panic ("Bad pointer set value" )
291297 }
292298
293- var ids []string
294- for _ , pointer := range gfkrVal .Data {
295- ids = append (ids , * pointer .ID )
299+ spots := []string {}
300+ args := []interface {}{}
301+ for index , pointer := range gfkrVal .Data {
302+ spots = append (spots , fmt .Sprintf ("$%d" , index + 3 ))
303+ args = append (args , * pointer .ID )
296304 }
297305
298- if len (ids ) == 0 {
306+ if len (spots ) == 0 {
299307 return []schema.Query {}
300308 }
301309
@@ -305,15 +313,15 @@ func (gfkr *GenericForeignKeyReverse) GetInsertQueries(
305313 gfkr .OwnTypeColumn ,
306314 gfkr .OwnIDColumn ,
307315 gfkr .OtherIDColumn ,
308- strings .Join (ids , ", " ),
316+ strings .Join (spots , ", " ),
309317 )
310318 return []schema.Query {
311319 schema.Query {
312320 Query : query ,
313- Args : []interface {}{
321+ Args : append ( []interface {}{
314322 gfkr .OwnType ,
315323 newId ,
316- },
324+ }, args ... ),
317325 },
318326 }
319327}
@@ -339,16 +347,22 @@ func (gfkr *GenericForeignKeyReverse) GetUpdateQueries(id string, oldVal interfa
339347 }
340348 }
341349 if len (nulling ) > 0 {
350+ spots := []string {}
351+ args := []interface {}{}
352+ for index , id := range nulling {
353+ spots = append (spots , fmt .Sprintf ("$%d" , index + 1 ))
354+ args = append (args , id )
355+ }
342356 queries = append (queries , schema.Query {
343357 Query : fmt .Sprintf (
344358 "update %s set (%s = null, %s = null) where %s in (%s)" ,
345359 gfkr .Table ,
346360 gfkr .OwnIDColumn ,
347361 gfkr .OwnTypeColumn ,
348362 gfkr .OtherIDColumn ,
349- strings .Join (nulling , ", " ),
363+ strings .Join (spots , ", " ),
350364 ),
351- Args : [] interface {}{} ,
365+ Args : args ,
352366 })
353367 }
354368
@@ -361,6 +375,12 @@ func (gfkr *GenericForeignKeyReverse) GetUpdateQueries(id string, oldVal interfa
361375 }
362376 }
363377 if len (adding ) > 0 {
378+ spots := []string {}
379+ args := []interface {}{}
380+ for index , id := range adding {
381+ spots = append (spots , fmt .Sprintf ("$%d" , index + 2 ))
382+ args = append (args , id )
383+ }
364384 queries = append (queries , schema.Query {
365385 Query : fmt .Sprintf (
366386 "update %s set %s = %s, %s = $1 where %s in (%s)" ,
@@ -369,11 +389,11 @@ func (gfkr *GenericForeignKeyReverse) GetUpdateQueries(id string, oldVal interfa
369389 id ,
370390 gfkr .OwnTypeColumn ,
371391 gfkr .OtherIDColumn ,
372- strings .Join (adding , ", " ),
392+ strings .Join (spots , ", " ),
373393 ),
374- Args : []interface {}{
394+ Args : append ( []interface {}{
375395 gfkr .OwnType ,
376- },
396+ }, args ... ),
377397 })
378398 }
379399
0 commit comments