Skip to content

Commit

Permalink
Adding usql_trim to adodb driver
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Jan 17, 2024
1 parent 1e4c47f commit c42881b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/adodb/adodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@ package adodb

import (
"database/sql"
"regexp"
"strings"

_ "github.com/mattn/go-adodb" // DRIVER
"github.com/xo/dburl"
"github.com/xo/usql/drivers"
)

func init() {
endRE := regexp.MustCompile(`;?\s*$`)
endAnchorRE := regexp.MustCompile(`(?i)\send\s*;\s*$`)
drivers.Register("adodb", drivers.Driver{
AllowMultilineComments: true,
AllowCComments: true,
Process: func(u *dburl.URL, prefix string, sqlstr string) (string, string, bool, error) {
// trim last ; but only when not END;
if s := strings.ToLower(u.Query().Get("usql_trim")); s != "" && s != "off" && s != "0" && s != "false" {
if !endAnchorRE.MatchString(sqlstr) {
sqlstr = endRE.ReplaceAllString(sqlstr, "")
}
}
typ, q := drivers.QueryExecType(prefix, sqlstr)
return typ, sqlstr, q, nil
},
RowsAffected: func(res sql.Result) (int64, error) {
return 0, nil
},
Expand Down

0 comments on commit c42881b

Please sign in to comment.