Skip to content

Commit 5e20ef5

Browse files
authored
fix: drop unsafe stmt query introspection (#550)
1 parent a2faa67 commit 5e20ef5

File tree

5 files changed

+3
-268
lines changed

5 files changed

+3
-268
lines changed

sql/stmt/context.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

sql/stmt/context_test.go

Lines changed: 0 additions & 115 deletions
This file was deleted.

sql/stmt/stmt.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

sql/stmt/stmt_test.go

Lines changed: 0 additions & 38 deletions
This file was deleted.

statement_handler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/go-juicedev/juice/internal/reflectlite"
3131
"github.com/go-juicedev/juice/session"
3232
"github.com/go-juicedev/juice/sql"
33-
"github.com/go-juicedev/juice/sql/stmt"
3433
)
3534

3635
// StatementHandler defines the interface for executing SQL statements.
@@ -153,6 +152,7 @@ func buildStatementQuery(statement Statement, cfg Configuration, driver driver.D
153152
// When a different query is encountered, it closes the existing statement and creates a new one.
154153
type preparedStatementHandler struct {
155154
stmts *stdsql.Stmt
155+
lastQuery string
156156
middlewares MiddlewareGroup
157157
driver driver.Driver
158158
session session.Session
@@ -162,7 +162,7 @@ type preparedStatementHandler struct {
162162
// getOrPrepare retrieves an existing prepared statement if the query matches,
163163
// otherwise closes the current statement (if any) and creates a new one.
164164
func (s *preparedStatementHandler) getOrPrepare(ctx context.Context, query string) (*stdsql.Stmt, error) {
165-
if s.stmts != nil && stmt.Query(s.stmts) == query {
165+
if s.stmts != nil && s.lastQuery == query {
166166
return s.stmts, nil
167167
}
168168
// it means the prepared statement is not what we want
@@ -174,6 +174,7 @@ func (s *preparedStatementHandler) getOrPrepare(ctx context.Context, query strin
174174
if err != nil {
175175
return nil, fmt.Errorf("prepare statement failed: %w", err)
176176
}
177+
s.lastQuery = query
177178
return s.stmts, nil
178179
}
179180

0 commit comments

Comments
 (0)