Skip to content

Commit

Permalink
Moved to shouldPrepare func
Browse files Browse the repository at this point in the history
  • Loading branch information
skoikovs committed Mar 14, 2014
1 parent 79258bb commit 5b6f183
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,31 @@ func (c *Conn) prepareStatement(stmt string, trace Tracer) (*queryInfo, error) {
return flight.info, flight.err
}

func (c *Conn) executeQuery(qry *Query) *Iter {
op := &queryFrame{
Stmt: strings.TrimSpace(qry.stmt),
Cons: qry.cons,
PageSize: qry.pageSize,
PageState: qry.pageState,
}
func shouldPrepare(stmt string) bool {
var stmtType string
if n := strings.IndexFunc(op.Stmt, unicode.IsSpace); n >= 0 {
stmtType = strings.ToLower(op.Stmt[:n])
if n := strings.IndexFunc(stmt, unicode.IsSpace); n >= 0 {
stmtType = strings.ToLower(stmt[:n])
}
if stmtType == "begin" {
if n := strings.LastIndexFunc(op.Stmt, unicode.IsSpace); n >= 0 {
stmtType = strings.ToLower(op.Stmt[n+1:])
if n := strings.LastIndexFunc(stmt, unicode.IsSpace); n >= 0 {
stmtType = strings.ToLower(stmt[n+1:])
}
}
switch stmtType {
case "select", "insert", "update", "delete", "batch":
return true
}
return false
}

func (c *Conn) executeQuery(qry *Query) *Iter {
op := &queryFrame{
Stmt: strings.TrimSpace(qry.stmt),
Cons: qry.cons,
PageSize: qry.pageSize,
PageState: qry.pageState,
}
if shouldPrepare(op.Stmt) {
// Prepare all DML queries. Other queries can not be prepared.
info, err := c.prepareStatement(qry.stmt, qry.trace)
if err != nil {
Expand Down

0 comments on commit 5b6f183

Please sign in to comment.