Skip to content

Commit

Permalink
Paramaterized property_label queries (#1464)
Browse files Browse the repository at this point in the history
Updated SQL queries in `GetPropertiesHelper` used by v0, v1, and v2
endpoints to use parameterized queries
  • Loading branch information
dwnoble authored Nov 21, 2024
1 parent 4c3275b commit fec804e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions internal/server/node/property_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package node
import (
"context"
"fmt"
"strings"

pb "github.com/datacommonsorg/mixer/internal/proto"
"github.com/datacommonsorg/mixer/internal/store"
Expand Down Expand Up @@ -78,23 +77,22 @@ func GetPropertiesHelper(
}
// Fetch data from SQLite
if store.SQLClient != nil {
nodesStr := "'" + strings.Join(nodes, "', '") + "'"
var query string
if direction == util.DirectionOut {
query = fmt.Sprintf(
"SELECT subject_id AS node, predicate FROM triples "+
"WHERE subject_id IN (%s);",
nodesStr,
util.SQLInParam(len(nodes)),
)
} else {
query = fmt.Sprintf(
"SELECT object_id AS node, predicate FROM triples "+
"WHERE object_id IN (%s);",
nodesStr,
util.SQLInParam(len(nodes)),
)
}
// Execute query
rows, err := store.SQLClient.Query(query)
rows, err := store.SQLClient.Query(query, util.ConvertArgs(nodes)...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit fec804e

Please sign in to comment.