Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T885 Add prepared statements support to sqlparser #303

Merged
15 changes: 15 additions & 0 deletions sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const (
StmtOther
StmtUnknown
StmtComment
StmtDeallocatePrepare
StmtPrepare
StmtExecute
)

// Preview analyzes the beginning of the query using a simpler and faster
Expand Down Expand Up @@ -73,6 +76,10 @@ func Preview(sql string) int {
return StmtUpdate
case "delete":
return StmtDelete
case "prepare":
return StmtPrepare
case "execute":
return StmtExecute
}
// For the following statements it is not sufficient to rely
// on loweredFirstWord. This is because they are not statements
Expand All @@ -87,6 +94,8 @@ func Preview(sql string) int {
return StmtCommit
case "rollback":
return StmtRollback
case "deallocate prepare":
return StmtDeallocatePrepare
}
switch loweredFirstWord {
case "create", "alter", "rename", "drop", "truncate":
Expand Down Expand Up @@ -137,6 +146,12 @@ func StmtType(stmtType int) string {
return "USE"
case StmtOther:
return "OTHER"
case StmtDeallocatePrepare:
return "DEALLOCATE PREPARE"
case StmtPrepare:
return "PREPARE"
case StmtExecute:
return "EXECUTE"
default:
return "UNKNOWN"
}
Expand Down
3 changes: 3 additions & 0 deletions sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func TestPreview(t *testing.T) {
{"optimize", StmtOther},
{"truncate", StmtDDL},
{"unknown", StmtUnknown},
{"deallocate prepare", StmtDeallocatePrepare},
{"prepare", StmtPrepare},
{"execute", StmtExecute},

{"/* leading comment */ select ...", StmtSelect},
{"/* leading comment */ (select ...", StmtSelect},
Expand Down
Loading