Skip to content

Commit

Permalink
Fixing issue with \raw metacommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Shaw committed May 29, 2018
1 parent c732266 commit eb21f27
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
35 changes: 29 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,45 @@ module github.com/xo/usql
require (
github.com/SAP/go-hdb v0.12.0
github.com/VoltDB/voltdb-client-go v1.0.0
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38
github.com/alecthomas/chroma v0.4.0
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721
github.com/alecthomas/repr v0.0.0-20180318094337-07932d32eb40
github.com/alexbrainman/odbc v0.0.0-20180328073627-14913e72bfde
github.com/alexflint/go-arg v0.0.0-20180516182405-f7c0423bd11e
github.com/alexflint/go-scalar v0.0.0-20170216020425-e80c3b7ed292
github.com/apache/calcite-avatica-go v0.0.0-20180422234931-273c53f62206
github.com/apache/calcite-avatica-go v0.0.0-20180514001606-b38c3987934b
github.com/chzyer/logex v1.1.10
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1
github.com/cockroachdb/apd v1.0.0
github.com/couchbase/go-couchbase v0.0.0-20180501122049-16db1f1fe037
github.com/couchbase/go_n1ql v0.0.0-20160215142504-6cf4e348b127
github.com/couchbase/gomemcached v0.0.0-20180502221210-0da75df14530
github.com/couchbase/goutils v0.0.0-20180425170317-f98adca8eb36
github.com/cznic/b v0.0.0-20180115125044-35e9bbe41f07
github.com/cznic/fileutil v0.0.0-20180108211300-6a051e75936f
github.com/cznic/internal v0.0.0-20160905094039-cef02a853c3a
github.com/cznic/internal v0.0.0-20170905175358-4747030f7cf2
github.com/cznic/lldb v1.1.0
github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369
github.com/cznic/ql v1.1.0
github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65
github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186
github.com/cznic/zappy v0.0.0-20160723133515-2533cb5b45cc
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
github.com/davecgh/go-spew v1.1.0
github.com/denisenkom/go-mssqldb v0.0.0-20180521163914-c4e5513e46d4
github.com/dlclark/regexp2 v1.1.6
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712
github.com/go-ole/go-ole v1.2.1
github.com/go-sql-driver/mysql v1.3.0
github.com/gohxs/readline v0.0.0-20171011095936-a780388e6e7c
github.com/golang/protobuf v1.1.0
github.com/jackc/pgx v0.0.0-20180115174807-da3231b0b66e
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db
github.com/hashicorp/go-uuid v0.0.0-20180228145832-27454136f036
github.com/hashicorp/go-version v0.0.0-20180322230233-23480c066577
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733
github.com/jackc/pgx v0.0.0-20180517214546-870744921917
github.com/jcmturner/gofork v0.0.0-20180107083740-2aebee971930
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1
github.com/knq/snaker v0.0.0-20180306023312-d9ad1e7f342a
github.com/kshvakov/clickhouse v1.3.3
Expand All @@ -38,22 +50,33 @@ require (
github.com/mattn/go-isatty v0.0.3
github.com/mattn/go-runewidth v0.0.2
github.com/mattn/go-sqlite3 v1.7.0
github.com/nakagami/firebirdsql v0.0.0-20180227015550-cece140468a1
github.com/nakagami/firebirdsql v0.0.0-20180528223306-650dae8a3484
github.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b
github.com/olekukonko/tablewriter v0.0.0-20180506121414-d4647c9c7a84
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0
github.com/prestodb/presto-go-client v0.0.0-20180419180745-74a3fc50f09d
github.com/spaolacci/murmur3 v0.0.0-20170819071325-9f5d223c6079
github.com/satori/go.uuid v1.2.0
github.com/sergi/go-diff v1.0.0
github.com/shopspring/decimal v0.0.0-20180319170823-2df3e6ddaf6e
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
github.com/stretchr/objx v0.0.0-20180528122724-d1e4838ff99b
github.com/stretchr/testify v1.2.1
github.com/xinsnake/go-http-digest-auth-client v0.4.0
github.com/xo/dburl v0.0.0-20180409172314-6a21934dd3de
github.com/xo/terminfo v0.0.0-20180401022757-20ea4ff360f0
github.com/xo/xoutil v0.0.0-20171112033149-46189f4026a5
github.com/zaf/temp v0.0.0-20170209143821-94e385923345
github.com/ziutek/mymysql v1.5.4
golang.org/x/crypto v0.0.0-20180525160159-a3beeb748656
golang.org/x/crypto v0.0.0-20180527072434-ab813273cd59
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43
golang.org/x/text v0.3.0
gopkg.in/check.v1 v1.0.0-20161208181325-20d25e280405
gopkg.in/jcmturner/aescts.v1 v1.0.1
gopkg.in/jcmturner/dnsutils.v1 v1.0.1
gopkg.in/jcmturner/goidentity.v1 v1.0.0
gopkg.in/jcmturner/gokrb5.v4 v4.1.2
gopkg.in/rana/ora.v4 v4.1.15
)
16 changes: 12 additions & 4 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ type Handler struct {
slm bool

// query statement buffer
buf *stmt.Stmt
lastPrefix string
buf *stmt.Stmt

// last statement
last string
lastPrefix string
lastRaw string

// connection
u *dburl.URL
Expand Down Expand Up @@ -267,7 +270,7 @@ func (h *Handler) Run() error {
// execute buf
if execute || h.buf.Ready() || res.Exec != metacmd.ExecNone {
if h.buf.Len != 0 {
h.lastPrefix, h.last = h.buf.Prefix, h.buf.String()
h.last, h.lastPrefix, h.lastRaw = h.buf.String(), h.buf.Prefix, h.buf.RawString()
h.buf.Reset(nil)
}

Expand Down Expand Up @@ -324,7 +327,7 @@ func (h *Handler) CommandRunner(cmds []string) func() error {
// Reset resets the handler's query statement buffer.
func (h *Handler) Reset(r []rune) {
h.buf.Reset(r)
h.last, h.lastPrefix = "", ""
h.last, h.lastPrefix, h.lastRaw = "", "", ""
}

// Prompt creates the prompt text.
Expand Down Expand Up @@ -375,6 +378,11 @@ func (h *Handler) Last() string {
return h.last
}

// LastRaw returns the last raw (non-interpolated) executed statement.
func (h *Handler) LastRaw() string {
return h.lastRaw
}

// Buf returns the current query statement buffer.
func (h *Handler) Buf() *stmt.Stmt {
return h.buf
Expand Down
10 changes: 9 additions & 1 deletion metacmd/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ func init() {
},
Process: func(p *Params) error {
// get last statement
s, buf := p.H.Last(), p.H.Buf()
var s string
if p.N == "raw" {
s = p.H.LastRaw()
} else {
s = p.H.Last()
}

// use current statement buf if not empty
buf := p.H.Buf()
switch {
case buf.Len != 0 && p.N == "raw":
s = buf.RawString()
Expand Down
3 changes: 3 additions & 0 deletions metacmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Handler interface {
// Last returns the last executed query.
Last() string

// LastRaw returns the last raw (non-interpolated) query.
LastRaw() string

// Buf returns the current query buffer.
Buf() *stmt.Stmt

Expand Down

0 comments on commit eb21f27

Please sign in to comment.