Conversation
fe102bc to
10f3b4d
Compare
| if _, err = tx.Exec(ctx, "SELECT pg_advisory_xact_lock(1573678846307946494)"); err != nil { | ||
| return err | ||
| } | ||
| sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s ( |
There was a problem hiding this comment.
rather than string-assemble this can you use arguments to Exec (throughout) -- this protects against sql injection attacks.
There was a problem hiding this comment.
IMO, according to https://www.postgresql.org/docs/current/xfunc-sql.html#XFUNC-SQL-FUNCTION-ARGUMENTS: SQL function arguments can only be used as data values, not as identifiers. replacing the table name with $1 does not seem to work.
There was a problem hiding this comment.
I think Travis maybe means that you shouldn't Sprintf into package sql calls like Exec, but rather use the args of each method, e.g. look at the example at https://pkg.go.dev/database/sql#example-Conn.ExecContext
result, err := conn.ExecContext(ctx,UPDATE balances SET balance = balance + 10 WHERE user_id = ?;, id)
See how id is passed into the SQL query?
There was a problem hiding this comment.
I think I may be getting it, but it seems difficult to do this if we wants to keep the table name as a parameter create table ? or create table $1 will both report an error, and I have to use the Sprint function and do Sanitize() when the user passes in the table name.
Or, we can fix the table name to be a constant and unchangeable.
Everywhere else, $1 is used to replace the parameter.
|
Please add/include an example showing usage. |
279e046 to
18c19d2
Compare
Should I refer to the |
| if _, err = tx.Exec(ctx, "SELECT pg_advisory_xact_lock(1573678846307946494)"); err != nil { | ||
| return err | ||
| } | ||
| sql := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS %s ( |
There was a problem hiding this comment.
I think Travis maybe means that you shouldn't Sprintf into package sql calls like Exec, but rather use the args of each method, e.g. look at the example at https://pkg.go.dev/database/sql#example-Conn.ExecContext
result, err := conn.ExecContext(ctx,UPDATE balances SET balance = balance + 10 WHERE user_id = ?;, id)
See how id is passed into the SQL query?
d9641b0 to
f6493ae
Compare
Signed-off-by: Abirdcfly <[email protected]>
That would work, I'd love to see more ollama examples but you can you openai, up to you. |
PR Checklist
memory: add interfaces for X, Yorutil: add whizzbang helpers).Fixes #123).golangci-lintchecks.