Browse Source

build: Updated to Debian Buster, removed vendor

master
Patrick Gaskin 11 months ago
parent
commit
6e97765599
Signed by: geek1011 <patrick@pgaskin.net> GPG Key ID: A2FD79F68A2AB707
100 changed files with 2 additions and 247688 deletions
  1. +2
    -6
      .drone.yml
  2. +0
    -22
      vendor/github.com/dinedal/textql/LICENSE
  3. +0
    -140
      vendor/github.com/dinedal/textql/inputs/csv.go
  4. +0
    -18
      vendor/github.com/dinedal/textql/inputs/input.go
  5. +0
    -9
      vendor/github.com/dinedal/textql/sqlparser/Makefile
  6. +0
    -121
      vendor/github.com/dinedal/textql/sqlparser/analyzer.go
  7. +0
    -996
      vendor/github.com/dinedal/textql/sqlparser/ast.go
  8. +0
    -180
      vendor/github.com/dinedal/textql/sqlparser/parsed_query.go
  9. +0
    -1813
      vendor/github.com/dinedal/textql/sqlparser/sql.go
  10. +0
    -1058
      vendor/github.com/dinedal/textql/sqlparser/sql.y
  11. +0
    -59
      vendor/github.com/dinedal/textql/sqlparser/sql_mod.go
  12. +0
    -378
      vendor/github.com/dinedal/textql/sqlparser/sqltypes/sqltypes.go
  13. +0
    -454
      vendor/github.com/dinedal/textql/sqlparser/token.go
  14. +0
    -107
      vendor/github.com/dinedal/textql/sqlparser/tracked_buffer.go
  15. +0
    -4395
      vendor/github.com/dinedal/textql/sqlparser/y.output
  16. +0
    -251
      vendor/github.com/dinedal/textql/storage/sqlite.go
  17. +0
    -26
      vendor/github.com/dinedal/textql/storage/storage.go
  18. +0
    -24
      vendor/github.com/jmoiron/sqlx/.gitignore
  19. +0
    -27
      vendor/github.com/jmoiron/sqlx/.travis.yml
  20. +0
    -23
      vendor/github.com/jmoiron/sqlx/LICENSE
  21. +0
    -187
      vendor/github.com/jmoiron/sqlx/README.md
  22. +0
    -217
      vendor/github.com/jmoiron/sqlx/bind.go
  23. +0
    -12
      vendor/github.com/jmoiron/sqlx/doc.go
  24. +0
    -7
      vendor/github.com/jmoiron/sqlx/go.mod
  25. +0
    -6
      vendor/github.com/jmoiron/sqlx/go.sum
  26. +0
    -356
      vendor/github.com/jmoiron/sqlx/named.go
  27. +0
    -132
      vendor/github.com/jmoiron/sqlx/named_context.go
  28. +0
    -17
      vendor/github.com/jmoiron/sqlx/reflectx/README.md
  29. +0
    -439
      vendor/github.com/jmoiron/sqlx/reflectx/reflect.go
  30. +0
    -1045
      vendor/github.com/jmoiron/sqlx/sqlx.go
  31. +0
    -346
      vendor/github.com/jmoiron/sqlx/sqlx_context.go
  32. +0
    -17
      vendor/github.com/julienschmidt/httprouter/.travis.yml
  33. +0
    -24
      vendor/github.com/julienschmidt/httprouter/LICENSE
  34. +0
    -266
      vendor/github.com/julienschmidt/httprouter/README.md
  35. +0
    -123
      vendor/github.com/julienschmidt/httprouter/path.go
  36. +0
    -411
      vendor/github.com/julienschmidt/httprouter/router.go
  37. +0
    -656
      vendor/github.com/julienschmidt/httprouter/tree.go
  38. +0
    -14
      vendor/github.com/mattn/go-sqlite3/.gitignore
  39. +0
    -41
      vendor/github.com/mattn/go-sqlite3/.travis.yml
  40. +0
    -21
      vendor/github.com/mattn/go-sqlite3/LICENSE
  41. +0
    -518
      vendor/github.com/mattn/go-sqlite3/README.md
  42. +0
    -85
      vendor/github.com/mattn/go-sqlite3/backup.go
  43. +0
    -374
      vendor/github.com/mattn/go-sqlite3/callback.go
  44. +0
    -112
      vendor/github.com/mattn/go-sqlite3/doc.go
  45. +0
    -135
      vendor/github.com/mattn/go-sqlite3/error.go
  46. +0
    -212224
      vendor/github.com/mattn/go-sqlite3/sqlite3-binding.c
  47. +0
    -11535
      vendor/github.com/mattn/go-sqlite3/sqlite3-binding.h
  48. +0
    -1979
      vendor/github.com/mattn/go-sqlite3/sqlite3.go
  49. +0
    -103
      vendor/github.com/mattn/go-sqlite3/sqlite3_context.go
  50. +0
    -120
      vendor/github.com/mattn/go-sqlite3/sqlite3_func_crypt.go
  51. +0
    -70
      vendor/github.com/mattn/go-sqlite3/sqlite3_go18.go
  52. +0
    -17
      vendor/github.com/mattn/go-sqlite3/sqlite3_libsqlite3.go
  53. +0
    -70
      vendor/github.com/mattn/go-sqlite3/sqlite3_load_extension.go
  54. +0
    -24
      vendor/github.com/mattn/go-sqlite3/sqlite3_load_extension_omit.go
  55. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_allow_uri_authority.go
  56. +0
    -16
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_app_armor.go
  57. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_foreign_keys.go
  58. +0
    -14
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_fts5.go
  59. +0
    -17
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_icu.go
  60. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_introspect.go
  61. +0
    -13
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_json1.go
  62. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_secure_delete.go
  63. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_secure_delete_fast.go
  64. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_stat4.go
  65. +0
    -289
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_userauth.go
  66. +0
    -152
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_userauth_omit.go
  67. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_vacuum_full.go
  68. +0
    -15
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_vacuum_incr.go
  69. +0
    -650
      vendor/github.com/mattn/go-sqlite3/sqlite3_opt_vtable.go
  70. +0
    -14
      vendor/github.com/mattn/go-sqlite3/sqlite3_other.go
  71. +0
    -14
      vendor/github.com/mattn/go-sqlite3/sqlite3_solaris.go
  72. +0
    -288
      vendor/github.com/mattn/go-sqlite3/sqlite3_trace.go
  73. +0
    -57
      vendor/github.com/mattn/go-sqlite3/sqlite3_type.go
  74. +0
    -39
      vendor/github.com/mattn/go-sqlite3/sqlite3_usleep_windows.go
  75. +0
    -18
      vendor/github.com/mattn/go-sqlite3/sqlite3_windows.go
  76. +0
    -620
      vendor/github.com/mattn/go-sqlite3/sqlite3ext.h
  77. +0
    -21
      vendor/github.com/mattn/go-sqlite3/static_mock.go
  78. +0
    -2
      vendor/github.com/spf13/pflag/.gitignore
  79. +0
    -22
      vendor/github.com/spf13/pflag/.travis.yml
  80. +0
    -28
      vendor/github.com/spf13/pflag/LICENSE
  81. +0
    -296
      vendor/github.com/spf13/pflag/README.md
  82. +0
    -94
      vendor/github.com/spf13/pflag/bool.go
  83. +0
    -147
      vendor/github.com/spf13/pflag/bool_slice.go
  84. +0
    -209
      vendor/github.com/spf13/pflag/bytes.go
  85. +0
    -96
      vendor/github.com/spf13/pflag/count.go
  86. +0
    -86
      vendor/github.com/spf13/pflag/duration.go
  87. +0
    -128
      vendor/github.com/spf13/pflag/duration_slice.go
  88. +0
    -1227
      vendor/github.com/spf13/pflag/flag.go
  89. +0
    -88
      vendor/github.com/spf13/pflag/float32.go
  90. +0
    -84
      vendor/github.com/spf13/pflag/float64.go
  91. +0
    -105
      vendor/github.com/spf13/pflag/golangflag.go
  92. +0
    -84
      vendor/github.com/spf13/pflag/int.go
  93. +0
    -88
      vendor/github.com/spf13/pflag/int16.go
  94. +0
    -88
      vendor/github.com/spf13/pflag/int32.go
  95. +0
    -84
      vendor/github.com/spf13/pflag/int64.go
  96. +0
    -88
      vendor/github.com/spf13/pflag/int8.go
  97. +0
    -128
      vendor/github.com/spf13/pflag/int_slice.go
  98. +0
    -94
      vendor/github.com/spf13/pflag/ip.go
  99. +0
    -148
      vendor/github.com/spf13/pflag/ip_slice.go
  100. +0
    -122
      vendor/github.com/spf13/pflag/ipmask.go

+ 2
- 6
.drone.yml View File

@@ -1,17 +1,13 @@
kind: pipeline
name: default

workspace:
base: /go
path: src/git.geek1011.net/geek1011/drtapi

steps:
- name: test
image: golang:1.12-stretch
image: golang:1.12-buster
commands:
- go test -v ./...
- name: build
image: golang:1.12-stretch
image: golang:1.12-buster
commands:
- mkdir -p build
- go build -ldflags "-X main.gitShortSHA=$(shell git rev-parse --short HEAD)" -o "build/drtapi"

+ 0
- 22
vendor/github.com/dinedal/textql/LICENSE View File

@@ -1,22 +0,0 @@
MIT License
-----------

Copyright (c) 2014, Paul Bergeron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

+ 0
- 140
vendor/github.com/dinedal/textql/inputs/csv.go View File

@@ -1,140 +0,0 @@
package inputs

import (
"encoding/csv"
"io"
"log"
"os"
"path"
"strconv"
)

// CSVInput represents a record producing input from a CSV formatted file or pipe.
type CSVInput struct {
options *CSVInputOptions
reader *csv.Reader
firstRow []string
header []string
minOutputLength int
name string
}

// CSVInputOptions options are passed to the underlying encoding/csv reader.
type CSVInputOptions struct {
// HasHeader when true, will treat the first row as a header row.
HasHeader bool
// Separator is the rune that fields are delimited by.
Separator rune
// ReadFrom is where the data will be read from.
ReadFrom io.Reader
}

// NewCSVInput sets up a new CSVInput, the first row is read when this is run.
// If there is a problem with reading the first row, the error is returned.
// Otherwise, the returned csvInput can be reliably consumed with ReadRecord()
// until ReadRecord() returns nil.
func NewCSVInput(opts *CSVInputOptions) (*CSVInput, error) {
csvInput := &CSVInput{
options: opts,
reader: csv.NewReader(opts.ReadFrom),
}
csvInput.firstRow = nil

csvInput.reader.FieldsPerRecord = -1
csvInput.reader.Comma = csvInput.options.Separator
csvInput.reader.LazyQuotes = true

headerErr := csvInput.readHeader()

if headerErr != nil {
return nil, headerErr
}

if asFile, ok := csvInput.options.ReadFrom.(*os.File); ok {
csvInput.name = path.Base(asFile.Name())
} else {
csvInput.name = "pipe"
}

return csvInput, nil
}

// Name returns the name of the CSV being read.
// By default, either the base filename or 'pipe' if it is a unix pipe
func (csvInput *CSVInput) Name() string {
return csvInput.name
}

// SetName overrides the name of the CSV
func (csvInput *CSVInput) SetName(name string) {
csvInput.name = name
}

// ReadRecord reads a single record from the CSV. Always returns successfully.
// If the record is empty, an empty []string is returned.
// Record expand to match the current row size, adding blank fields as needed.
// Records never return less then the number of fields in the first row.
// Returns nil on EOF
// In the event of a parse error due to an invalid record, it is logged, and
// an empty []string is returned with the number of fields in the first row,
// as if the record were empty.
//
// In general, this is a very tolerant of problems CSV reader.
func (csvInput *CSVInput) ReadRecord() []string {
var row []string
var fileErr error

if csvInput.firstRow != nil {
row = csvInput.firstRow
csvInput.firstRow = nil
return row
}

row, fileErr = csvInput.reader.Read()
emptysToAppend := csvInput.minOutputLength - len(row)
if fileErr == io.EOF {
return nil
} else if parseErr, ok := fileErr.(*csv.ParseError); ok {
log.Println(parseErr)
emptysToAppend = csvInput.minOutputLength
}

if emptysToAppend > 0 {
for counter := 0; counter < emptysToAppend; counter++ {
row = append(row, "")
}
}

return row
}

func (csvInput *CSVInput) readHeader() error {
var readErr error

csvInput.firstRow, readErr = csvInput.reader.Read()

if readErr != nil {
log.Fatalln(readErr)
return readErr
}

csvInput.minOutputLength = len(csvInput.firstRow)

if csvInput.options.HasHeader {
csvInput.header = csvInput.firstRow
csvInput.firstRow = nil
} else {
csvInput.header = make([]string, csvInput.minOutputLength)
for i := 0; i < len(csvInput.firstRow); i++ {
csvInput.header[i] = "c" + strconv.Itoa(i)
}
}

return nil
}

// Header returns the header of the csvInput. Either the first row if a header
// set in the options, or c#, where # is the column number, starting with 0.
func (csvInput *CSVInput) Header() []string {
return csvInput.header
}

+ 0
- 18
vendor/github.com/dinedal/textql/inputs/input.go View File

@@ -1,18 +0,0 @@
package inputs

// Input is how TextQL reads from data sources.
// To be an input, an implementor must return tabular data.
// How data is manipulated into the tabular structure is left to the implementor.
// Inputs are expected to return in a row by row fashion.
type Input interface {
// ReadRecord should return nil on the end of data, or a single record.
// Recoverable errors should represent themselves as empty sets.
// Unrecoverable errors should return nil.
ReadRecord() []string
// Header should return metadata naming the columns in the table.
Header() []string
// Name should return a reasonable name for the data set, prehaps the file name.
Name() string
// SetName allows users of the dataset to supply their own name if needed.
SetName(string)
}

+ 0
- 9
vendor/github.com/dinedal/textql/sqlparser/Makefile View File

@@ -1,9 +0,0 @@

MAKEFLAGS = -s

sql.go: sql.y
go tool yacc -o sql.go sql.y
gofmt -w sql.go

clean:
rm -f y.output sql.go

+ 0
- 121
vendor/github.com/dinedal/textql/sqlparser/analyzer.go View File

@@ -1,121 +0,0 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sqlparser

// analyzer.go contains utility analysis functions.

import (
"fmt"

"github.com/dinedal/textql/sqlparser/sqltypes"
)

// GetTableName returns the table name from the SimpleTableExpr
// only if it's a simple expression. Otherwise, it returns "".
func GetTableName(node SimpleTableExpr) string {
if n, ok := node.(*TableName); ok && n.Qualifier == nil {
return string(n.Name)
}
// sub-select or '.' expression
return ""
}

// GetColName returns the column name, only if
// it's a simple expression. Otherwise, it returns "".
func GetColName(node Expr) string {
if n, ok := node.(*ColName); ok {
return string(n.Name)
}
return ""
}

// IsColName returns true if the ValExpr is a *ColName.
func IsColName(node ValExpr) bool {
_, ok := node.(*ColName)
return ok
}

// IsValue returns true if the ValExpr is a string, number or value arg.
// NULL is not considered to be a value.
func IsValue(node ValExpr) bool {
switch node.(type) {
case StrVal, NumVal, ValArg:
return true
}
return false
}

// HasINCaluse returns true if any of the conditions has an IN clause.
func HasINClause(conditions []BoolExpr) bool {
for _, node := range conditions {
if c, ok := node.(*ComparisonExpr); ok && c.Operator == AST_IN {
return true
}
}
return false
}

// IsSimpleTuple returns true if the ValExpr is a ValTuple that
// contains simple values or if it's a list arg.
func IsSimpleTuple(node ValExpr) bool {
switch vals := node.(type) {
case ValTuple:
for _, n := range vals {
if !IsValue(n) {
return false
}
}
return true
case ListArg:
return true
}
// It's a subquery
return false
}

// AsInterface converts the ValExpr to an interface. It converts
// ValTuple to []interface{}, ValArg to string, StrVal to sqltypes.String,
// NumVal to sqltypes.Numeric, NullVal to nil.
// Otherwise, it returns an error.
func AsInterface(node ValExpr) (interface{}, error) {
switch node := node.(type) {
case ValTuple:
vals := make([]interface{}, 0, len(node))
for _, val := range node {
v, err := AsInterface(val)
if err != nil {
return nil, err
}
vals = append(vals, v)
}
return vals, nil
case ValArg:
return string(node), nil
case ListArg:
return string(node), nil
case StrVal:
return sqltypes.MakeString(node), nil
case NumVal:
n, err := sqltypes.BuildNumeric(string(node))
if err != nil {
return nil, fmt.Errorf("type mismatch: %s", err)
}
return n, nil
case *NullVal:
return nil, nil
}
return nil, fmt.Errorf("unexpected node %v", node)
}

// StringIn is a convenience function that returns
// true if str matches any of the values.
func StringIn(str string, values ...string) bool {
for _, val := range values {
if str == val {
return true
}
}
return false
}

+ 0
- 996
vendor/github.com/dinedal/textql/sqlparser/ast.go View File

@@ -1,996 +0,0 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sqlparser

import (
"errors"
"fmt"
"strconv"

"github.com/dinedal/textql/sqlparser/sqltypes"
)

// Instructions for creating new types: If a type
// needs to satisfy an interface, declare that function
// along with that interface. This will help users
// identify the list of types to which they can assert
// those interfaces.
// If the member of a type has a string with a predefined
// list of values, declare those values as const following
// the type.
// For interfaces that define dummy functions to consolidate
// a set of types, define the function as ITypeName.
// This will help avoid name collisions.

// Parse parses the sql and returns a Statement, which
// is the AST representation of the query.
func Parse(sql string) (Statement, error) {
tokenizer := NewStringTokenizer(sql)
if yyParse(tokenizer) != 0 {
return nil, errors.New(tokenizer.LastError)
}
return tokenizer.ParseTree, nil
}

// SQLNode defines the interface for all nodes
// generated by the parser.
type SQLNode interface {
Format(buf *TrackedBuffer)
}

// String returns a string representation of an SQLNode.
func String(node SQLNode) string {
buf := NewTrackedBuffer(nil)
buf.Myprintf("%v", node)
return buf.String()
}

// Statement represents a statement.
type Statement interface {
IStatement()
SQLNode
}

func (*Union) IStatement() {}
func (*Select) IStatement() {}
func (*Insert) IStatement() {}
func (*Update) IStatement() {}
func (*Delete) IStatement() {}
func (*Set) IStatement() {}
func (*DDL) IStatement() {}
func (*Other) IStatement() {}

// SelectStatement any SELECT statement.
type SelectStatement interface {
ISelectStatement()
IStatement()
IInsertRows()
SQLNode
}

func (*Select) ISelectStatement() {}
func (*Union) ISelectStatement() {}

// Select represents a SELECT statement.
type Select struct {
Comments Comments
Distinct string
SelectExprs SelectExprs
From *From
Where *Where
GroupBy GroupBy
Having *Where
OrderBy OrderBy
Limit *Limit
Lock string
}

// Select.Distinct
const (
AST_DISTINCT = "distinct "
)

// Select.Lock
const (
AST_FOR_UPDATE = " for update"
AST_SHARE_MODE = " lock in share mode"
)

func (node *Select) Format(buf *TrackedBuffer) {
buf.Myprintf("select %v%s%v from %v%v%v%v%v%v%s",
node.Comments, node.Distinct, node.SelectExprs,
node.From, node.Where,
node.GroupBy, node.Having, node.OrderBy,
node.Limit, node.Lock)
}

// Union represents a UNION statement.
type Union struct {
Type string
Left, Right SelectStatement
}

// Union.Type
const (
AST_UNION = "union"
AST_UNION_ALL = "union all"
AST_SET_MINUS = "minus"
AST_EXCEPT = "except"
AST_INTERSECT = "intersect"
)

func (node *Union) Format(buf *TrackedBuffer) {
buf.Myprintf("%v %s %v", node.Left, node.Type, node.Right)
}

// Insert represents an INSERT statement.
type Insert struct {
Comments Comments
Table *TableName
Columns Columns
Rows InsertRows
OnDup OnDup
}

func (node *Insert) Format(buf *TrackedBuffer) {
buf.Myprintf("insert %vinto %v%v %v%v",
node.Comments,
node.Table, node.Columns, node.Rows, node.OnDup)
}

// InsertRows represents the rows for an INSERT statement.
type InsertRows interface {
IInsertRows()
SQLNode
}

func (*Select) IInsertRows() {}
func (*Union) IInsertRows() {}
func (Values) IInsertRows() {}

// Update represents an UPDATE statement.
type Update struct {
Comments Comments
Table *TableName
Exprs UpdateExprs
Where *Where
OrderBy OrderBy
Limit *Limit
}

func (node *Update) Format(buf *TrackedBuffer) {
buf.Myprintf("update %v%v set %v%v%v%v",
node.Comments, node.Table,
node.Exprs, node.Where, node.OrderBy, node.Limit)
}

// Delete represents a DELETE statement.
type Delete struct {
Comments Comments
Table *TableName
Where *Where
OrderBy OrderBy
Limit *Limit
}

func (node *Delete) Format(buf *TrackedBuffer) {
buf.Myprintf("delete %vfrom %v%v%v%v",
node.Comments,
node.Table, node.Where, node.OrderBy, node.Limit)
}

// Set represents a SET statement.
type Set struct {
Comments Comments
Exprs UpdateExprs
}

func (node *Set) Format(buf *TrackedBuffer) {
buf.Myprintf("set %v%v", node.Comments, node.Exprs)
}

// DDL represents a CREATE, ALTER, DROP or RENAME statement.
// Table is set for AST_ALTER, AST_DROP, AST_RENAME.
// NewName is set for AST_ALTER, AST_CREATE, AST_RENAME.
type DDL struct {
Action string
Table []byte
NewName []byte
}

const (
AST_CREATE = "create"
AST_ALTER = "alter"
AST_DROP = "drop"
AST_RENAME = "rename"
)

func (node *DDL) Format(buf *TrackedBuffer) {
switch node.Action {
case AST_CREATE:
buf.Myprintf("%s table %s", node.Action, node.NewName)
case AST_RENAME:
buf.Myprintf("%s table %s %s", node.Action, node.Table, node.NewName)
default:
buf.Myprintf("%s table %s", node.Action, node.Table)
}
}

// Other represents a SHOW, DESCRIBE, or EXPLAIN statement.
// It should be used only as an indicator. It does not contain
// the full AST for the statement.
type Other struct{}

func (node *Other) Format(buf *TrackedBuffer) {
buf.WriteString("other")
}

// Comments represents a list of comments.
type Comments [][]byte

func (node Comments) Format(buf *TrackedBuffer) {
for _, c := range node {
buf.Myprintf("%s ", c)
}
}

// SelectExprs represents SELECT expressions.
type SelectExprs []SelectExpr

func (node SelectExprs) Format(buf *TrackedBuffer) {
var prefix string
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// SelectExpr represents a SELECT expression.
type SelectExpr interface {
ISelectExpr()
SQLNode
}

func (*StarExpr) ISelectExpr() {}
func (*NonStarExpr) ISelectExpr() {}

// StarExpr defines a '*' or 'table.*' expression.
type StarExpr struct {
TableName []byte
}

func (node *StarExpr) Format(buf *TrackedBuffer) {
if node.TableName != nil {
buf.Myprintf("%s.", node.TableName)
}
buf.Myprintf("*")
}

// NonStarExpr defines a non-'*' select expr.
type NonStarExpr struct {
Expr Expr
As []byte
}

func (node *NonStarExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v", node.Expr)
if node.As != nil {
buf.Myprintf(" as %s", node.As)
}
}

// Columns represents an insert column list.
// The syntax for Columns is a subset of SelectExprs.
// So, it's castable to a SelectExprs and can be analyzed
// as such.
type Columns []SelectExpr

func (node Columns) Format(buf *TrackedBuffer) {
if node == nil {
return
}
buf.Myprintf("(%v)", SelectExprs(node))
}

// TableExprs represents a list of table expressions.
type TableExprs []TableExpr

func (node TableExprs) Format(buf *TrackedBuffer) {
var prefix string
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// TableExpr represents a table expression.
type TableExpr interface {
ITableExpr()
SQLNode
}

func (*AliasedTableExpr) ITableExpr() {}
func (*ParenTableExpr) ITableExpr() {}
func (*JoinTableExpr) ITableExpr() {}

// AliasedTableExpr represents a table expression
// coupled with an optional alias or index hint.
type AliasedTableExpr struct {
Expr SimpleTableExpr
As []byte
Hints *IndexHints
}

func (node *AliasedTableExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v", node.Expr)
if node.As != nil {
buf.Myprintf(" as %s", node.As)
}
if node.Hints != nil {
// Hint node provides the space padding.
buf.Myprintf("%v", node.Hints)
}
}

// SimpleTableExpr represents a simple table expression.
type SimpleTableExpr interface {
ISimpleTableExpr()
SQLNode
}

func (*TableName) ISimpleTableExpr() {}
func (*Subquery) ISimpleTableExpr() {}

// TableName represents a table name.
type TableName struct {
Name, Qualifier []byte
}

func (node *TableName) Format(buf *TrackedBuffer) {
if node.Qualifier != nil {
escape(buf, node.Qualifier)
buf.Myprintf(".")
}
escape(buf, node.Name)
}

// ParenTableExpr represents a parenthesized TableExpr.
type ParenTableExpr struct {
Expr TableExpr
}

func (node *ParenTableExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("(%v)", node.Expr)
}

// JoinTableExpr represents a TableExpr that's a JOIN operation.
type JoinTableExpr struct {
LeftExpr TableExpr
Join string
RightExpr TableExpr
On BoolExpr
}

// JoinTableExpr.Join
const (
AST_JOIN = "join"
AST_STRAIGHT_JOIN = "straight_join"
AST_LEFT_JOIN = "left join"
AST_RIGHT_JOIN = "right join"
AST_CROSS_JOIN = "cross join"
AST_NATURAL_JOIN = "natural join"
)

func (node *JoinTableExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v %s %v", node.LeftExpr, node.Join, node.RightExpr)
if node.On != nil {
buf.Myprintf(" on %v", node.On)
}
}

// IndexHints represents a list of index hints.
type IndexHints struct {
Type string
Indexes [][]byte
}

const (
AST_USE = "use"
AST_IGNORE = "ignore"
AST_FORCE = "force"
)

func (node *IndexHints) Format(buf *TrackedBuffer) {
buf.Myprintf(" %s index ", node.Type)
prefix := "("
for _, n := range node.Indexes {
buf.Myprintf("%s%s", prefix, n)
prefix = ", "
}
buf.Myprintf(")")
}

// Where represents a WHERE or HAVING clause.
type Where struct {
Type string
Expr BoolExpr
}

// Where.Type
const (
AST_WHERE = "where"
AST_HAVING = "having"
)

// NewWhere creates a WHERE or HAVING clause out
// of a BoolExpr. If the expression is nil, it returns nil.
func NewWhere(typ string, expr BoolExpr) *Where {
if expr == nil {
return nil
}
return &Where{Type: typ, Expr: expr}
}

func (node *Where) Format(buf *TrackedBuffer) {
if node == nil || node.Expr == nil {
return
}
buf.Myprintf(" %s %v", node.Type, node.Expr)
}

// From represents a FROM clause
type From struct {
Type string
Expr TableExprs
}

// From.Type
const (
AST_FROM = "from"
)

// NewFrom creates a FROM clause
// of a table list expression. If the expression is nil, it returns nil.
func NewFrom(typ string, expr TableExprs) *From {
if expr == nil {
return nil
}
return &From{Type: typ, Expr: expr}
}

func (node *From) Format(buf *TrackedBuffer) {
if node == nil || node.Expr == nil {
return
}
buf.Myprintf("%v", node.Expr)
}

// Expr represents an expression.
type Expr interface {
IExpr()
SQLNode
}

func (*AndExpr) IExpr() {}
func (*OrExpr) IExpr() {}
func (*NotExpr) IExpr() {}
func (*ParenBoolExpr) IExpr() {}
func (*ComparisonExpr) IExpr() {}
func (*RangeCond) IExpr() {}
func (*NullCheck) IExpr() {}
func (*ExistsExpr) IExpr() {}
func (*KeyrangeExpr) IExpr() {}
func (StrVal) IExpr() {}
func (NumVal) IExpr() {}
func (ValArg) IExpr() {}
func (*NullVal) IExpr() {}
func (*ColName) IExpr() {}
func (ValTuple) IExpr() {}
func (*Subquery) IExpr() {}
func (ListArg) IExpr() {}
func (*BinaryExpr) IExpr() {}
func (*UnaryExpr) IExpr() {}
func (*FuncExpr) IExpr() {}
func (*CaseExpr) IExpr() {}

// BoolExpr represents a boolean expression.
type BoolExpr interface {
IBoolExpr()
Expr
}

func (*AndExpr) IBoolExpr() {}
func (*OrExpr) IBoolExpr() {}
func (*NotExpr) IBoolExpr() {}
func (*ParenBoolExpr) IBoolExpr() {}
func (*ComparisonExpr) IBoolExpr() {}
func (*RangeCond) IBoolExpr() {}
func (*NullCheck) IBoolExpr() {}
func (*ExistsExpr) IBoolExpr() {}
func (*KeyrangeExpr) IBoolExpr() {}

// AndExpr represents an AND expression.
type AndExpr struct {
Left, Right BoolExpr
}

func (node *AndExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v and %v", node.Left, node.Right)
}

// OrExpr represents an OR expression.
type OrExpr struct {
Left, Right BoolExpr
}

func (node *OrExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v or %v", node.Left, node.Right)
}

// NotExpr represents a NOT expression.
type NotExpr struct {
Expr BoolExpr
}

func (node *NotExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("not %v", node.Expr)
}

// ParenBoolExpr represents a parenthesized boolean expression.
type ParenBoolExpr struct {
Expr BoolExpr
}

func (node *ParenBoolExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("(%v)", node.Expr)
}

// ComparisonExpr represents a two-value comparison expression.
type ComparisonExpr struct {
Operator string
Left, Right ValExpr
}

// ComparisonExpr.Operator
const (
AST_EQ = "="
AST_LT = "<"
AST_GT = ">"
AST_LE = "<="
AST_GE = ">="
AST_NE = "!="
AST_NSE = "<=>"
AST_IN = "in"
AST_NOT_IN = "not in"
AST_LIKE = "like"
AST_NOT_LIKE = "not like"
)

func (node *ComparisonExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v %s %v", node.Left, node.Operator, node.Right)
}

// RangeCond represents a BETWEEN or a NOT BETWEEN expression.
type RangeCond struct {
Operator string
Left ValExpr
From, To ValExpr
}

// RangeCond.Operator
const (
AST_BETWEEN = "between"
AST_NOT_BETWEEN = "not between"
)

func (node *RangeCond) Format(buf *TrackedBuffer) {
buf.Myprintf("%v %s %v and %v", node.Left, node.Operator, node.From, node.To)
}

// NullCheck represents an IS NULL or an IS NOT NULL expression.
type NullCheck struct {
Operator string
Expr ValExpr
}

// NullCheck.Operator
const (
AST_IS_NULL = "is null"
AST_IS_NOT_NULL = "is not null"
)

func (node *NullCheck) Format(buf *TrackedBuffer) {
buf.Myprintf("%v %s", node.Expr, node.Operator)
}

// ExistsExpr represents an EXISTS expression.
type ExistsExpr struct {
Subquery *Subquery
}

func (node *ExistsExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("exists %v", node.Subquery)
}

// KeyrangeExpr represents a KEYRANGE expression.
type KeyrangeExpr struct {
Start, End ValExpr
}

func (node *KeyrangeExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("keyrange(%v, %v)", node.Start, node.End)
}

// ValExpr represents a value expression.
type ValExpr interface {
IValExpr()
Expr
}

func (StrVal) IValExpr() {}
func (NumVal) IValExpr() {}
func (ValArg) IValExpr() {}
func (*NullVal) IValExpr() {}
func (*ColName) IValExpr() {}
func (ValTuple) IValExpr() {}
func (*Subquery) IValExpr() {}
func (ListArg) IValExpr() {}
func (*BinaryExpr) IValExpr() {}
func (*UnaryExpr) IValExpr() {}
func (*FuncExpr) IValExpr() {}
func (*CaseExpr) IValExpr() {}

// StrVal represents a string value.
type StrVal []byte

func (node StrVal) Format(buf *TrackedBuffer) {
s := sqltypes.MakeString([]byte(node))
s.EncodeSql(buf)
}

// NumVal represents a number.
type NumVal []byte

func (node NumVal) Format(buf *TrackedBuffer) {
buf.Myprintf("%s", []byte(node))
}

// ValArg represents a named bind var argument.
type ValArg []byte

func (node ValArg) Format(buf *TrackedBuffer) {
buf.WriteArg(string(node))
}

// NullVal represents a NULL value.
type NullVal struct{}

func (node *NullVal) Format(buf *TrackedBuffer) {
buf.Myprintf("null")
}

// ColName represents a column name.
type ColName struct {
Name, Qualifier []byte
}

func (node *ColName) Format(buf *TrackedBuffer) {
if node.Qualifier != nil {
escape(buf, node.Qualifier)
buf.Myprintf(".")
}
escape(buf, node.Name)
}

func escape(buf *TrackedBuffer, name []byte) {
if _, ok := keywords[string(name)]; ok {
buf.Myprintf("`%s`", name)
} else {
buf.Myprintf("%s", name)
}
}

// ColTuple represents a list of column values.
// It can be ValTuple, Subquery, ListArg.
type ColTuple interface {
IColTuple()
ValExpr
}

func (ValTuple) IColTuple() {}
func (*Subquery) IColTuple() {}
func (ListArg) IColTuple() {}

// ValTuple represents a tuple of actual values.
type ValTuple ValExprs

func (node ValTuple) Format(buf *TrackedBuffer) {
buf.Myprintf("(%v)", ValExprs(node))
}

// ValExprs represents a list of value expressions.
// It's not a valid expression because it's not parenthesized.
type ValExprs []ValExpr

func (node ValExprs) Format(buf *TrackedBuffer) {
var prefix string
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// Subquery represents a subquery.
type Subquery struct {
Select SelectStatement
}

func (node *Subquery) Format(buf *TrackedBuffer) {
buf.Myprintf("(%v)", node.Select)
}

// ListArg represents a named list argument.
type ListArg []byte

func (node ListArg) Format(buf *TrackedBuffer) {
buf.WriteArg(string(node))
}

// BinaryExpr represents a binary value expression.
type BinaryExpr struct {
Operator byte
Left, Right Expr
}

// BinaryExpr.Operator
const (
AST_BITAND = '&'
AST_BITOR = '|'
AST_BITXOR = '^'
AST_PLUS = '+'
AST_MINUS = '-'
AST_MULT = '*'
AST_DIV = '/'
AST_MOD = '%'
)

func (node *BinaryExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v%c%v", node.Left, node.Operator, node.Right)
}

// UnaryExpr represents a unary value expression.
type UnaryExpr struct {
Operator byte
Expr Expr
}

// UnaryExpr.Operator
const (
AST_UPLUS = '+'
AST_UMINUS = '-'
AST_TILDA = '~'
)

func (node *UnaryExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%c%v", node.Operator, node.Expr)
}

// FuncExpr represents a function call.
type FuncExpr struct {
Name []byte
Distinct bool
Exprs SelectExprs
}

func (node *FuncExpr) Format(buf *TrackedBuffer) {
var distinct string
if node.Distinct {
distinct = "distinct "
}
buf.Myprintf("%s(%s%v)", node.Name, distinct, node.Exprs)
}

// Aggregates is a map of all aggregate functions.
var Aggregates = map[string]bool{
"avg": true,
"bit_and": true,
"bit_or": true,
"bit_xor": true,
"count": true,
"group_concat": true,
"max": true,
"min": true,
"std": true,
"stddev_pop": true,
"stddev_samp": true,
"stddev": true,
"sum": true,
"var_pop": true,
"var_samp": true,
"variance": true,
}

func (node *FuncExpr) IsAggregate() bool {
return Aggregates[string(node.Name)]
}

// CaseExpr represents a CASE expression.
type CaseExpr struct {
Expr ValExpr
Whens []*When
Else ValExpr
}

func (node *CaseExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("case ")
if node.Expr != nil {
buf.Myprintf("%v ", node.Expr)
}
for _, when := range node.Whens {
buf.Myprintf("%v ", when)
}
if node.Else != nil {
buf.Myprintf("else %v ", node.Else)
}
buf.Myprintf("end")
}

// When represents a WHEN sub-expression.
type When struct {
Cond BoolExpr
Val ValExpr
}

func (node *When) Format(buf *TrackedBuffer) {
buf.Myprintf("when %v then %v", node.Cond, node.Val)
}

// GroupBy represents a GROUP BY clause.
type GroupBy []ValExpr

func (node GroupBy) Format(buf *TrackedBuffer) {
prefix := " group by "
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// OrderBy represents an ORDER By clause.
type OrderBy []*Order

func (node OrderBy) Format(buf *TrackedBuffer) {
prefix := " order by "
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// Order represents an ordering expression.
type Order struct {
Expr ValExpr
Direction string
}

// Order.Direction
const (
AST_ASC = "asc"
AST_DESC = "desc"
)

func (node *Order) Format(buf *TrackedBuffer) {
buf.Myprintf("%v %s", node.Expr, node.Direction)
}

// Limit represents a LIMIT clause.
type Limit struct {
Offset, Rowcount ValExpr
}

func (node *Limit) Format(buf *TrackedBuffer) {
if node == nil {
return
}
buf.Myprintf(" limit ")
if node.Offset != nil {
buf.Myprintf("%v, ", node.Offset)
}
buf.Myprintf("%v", node.Rowcount)
}

// Limits returns the values of the LIMIT clause as interfaces.
// The returned values can be nil for absent field, string for
// bind variable names, or int64 for an actual number.
// Otherwise, it's an error.
func (node *Limit) Limits() (offset, rowcount interface{}, err error) {
if node == nil {
return nil, nil, nil
}
switch v := node.Offset.(type) {
case NumVal:
o, err := strconv.ParseInt(string(v), 0, 64)
if err != nil {
return nil, nil, err
}
if o < 0 {
return nil, nil, fmt.Errorf("negative offset: %d", o)
}
offset = o
case ValArg:
offset = string(v)
case nil:
// pass
default:
return nil, nil, fmt.Errorf("unexpected node for offset: %+v", v)
}
switch v := node.Rowcount.(type) {
case NumVal:
rc, err := strconv.ParseInt(string(v), 0, 64)
if err != nil {
return nil, nil, err
}
if rc < 0 {
return nil, nil, fmt.Errorf("negative limit: %d", rc)
}
rowcount = rc
case ValArg:
rowcount = string(v)
default:
return nil, nil, fmt.Errorf("unexpected node for rowcount: %+v", v)
}
return offset, rowcount, nil
}

// Values represents a VALUES clause.
type Values []RowTuple

func (node Values) Format(buf *TrackedBuffer) {
prefix := "values "
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// RowTuple represents a row of values. It can be ValTuple, Subquery.
type RowTuple interface {
IRowTuple()
ValExpr
}

func (ValTuple) IRowTuple() {}
func (*Subquery) IRowTuple() {}

// UpdateExprs represents a list of update expressions.
type UpdateExprs []*UpdateExpr

func (node UpdateExprs) Format(buf *TrackedBuffer) {
var prefix string
for _, n := range node {
buf.Myprintf("%s%v", prefix, n)
prefix = ", "
}
}

// UpdateExpr represents an update expression.
type UpdateExpr struct {
Name *ColName
Expr ValExpr
}

func (node *UpdateExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%v = %v", node.Name, node.Expr)
}

// OnDup represents an ON DUPLICATE KEY clause.
type OnDup UpdateExprs

func (node OnDup) Format(buf *TrackedBuffer) {
if node == nil {
return
}
buf.Myprintf(" on duplicate key update %v", UpdateExprs(node))
}

+ 0
- 180
vendor/github.com/dinedal/textql/sqlparser/parsed_query.go View File

@@ -1,180 +0,0 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sqlparser

import (
"bytes"
"encoding/json"
"errors"
"fmt"

"github.com/dinedal/textql/sqlparser/sqltypes"
)

type bindLocation struct {
offset, length int
}

type ParsedQuery struct {
Query string
bindLocations []bindLocation
}

type EncoderFunc func(value interface{}) ([]byte, error)

func (pq *ParsedQuery) GenerateQuery(bindVariables map[string]interface{}) ([]byte, error) {
if len(pq.bindLocations) == 0 {
return []byte(pq.Query), nil
}
buf := bytes.NewBuffer(make([]byte, 0, len(pq.Query)))
current := 0
for _, loc := range pq.bindLocations {
buf.WriteString(pq.Query[current:loc.offset])
name := pq.Query[loc.offset : loc.offset+loc.length]
supplied, _, err := FetchBindVar(name, bindVariables)
if err != nil {
return nil, err
}
if err := EncodeValue(buf, supplied); err != nil {
return nil, err
}
current = loc.offset + loc.length
}
buf.WriteString(pq.Query[current:])
return buf.Bytes(), nil
}

func (pq *ParsedQuery) MarshalJSON() ([]byte, error) {
return json.Marshal(pq.Query)
}

func EncodeValue(buf *bytes.Buffer, value interface{}) error {
switch bindVal := value.(type) {
case nil:
buf.WriteString("null")
case []sqltypes.Value:
for i := 0; i < len(bindVal); i++ {
if i != 0 {
buf.WriteString(", ")
}
if err := EncodeValue(buf, bindVal[i]); err != nil {
return err
}
}
case [][]sqltypes.Value:
for i := 0; i < len(bindVal); i++ {
if i != 0 {
buf.WriteString(", ")
}
buf.WriteByte('(')
if err := EncodeValue(buf, bindVal[i]); err != nil {
return err
}
buf.WriteByte(')')
}
case []interface{}:
buf.WriteByte('(')
for i, v := range bindVal {
if i != 0 {
buf.WriteString(", ")
}
if err := EncodeValue(buf, v); err != nil {
return err
}
}
buf.WriteByte(')')
case TupleEqualityList:
if err := bindVal.Encode(buf); err != nil {
return err
}
default:
v, err := sqltypes.BuildValue(bindVal)
if err != nil {
return err
}
v.EncodeSql(buf)
}
return nil
}

type TupleEqualityList struct {
Columns []string
Rows [][]sqltypes.Value
}

func (tpl *TupleEqualityList) Encode(buf *bytes.Buffer) error {
if len(tpl.Rows) == 0 {
return errors.New("cannot encode with 0 rows")
}
if len(tpl.Columns) == 1 {
return tpl.encodeAsIN(buf)
}
return tpl.encodeAsEquality(buf)
}

func (tpl *TupleEqualityList) encodeAsIN(buf *bytes.Buffer) error {
buf.WriteString(tpl.Columns[0])
buf.WriteString(" in (")
for i, r := range tpl.Rows {
if len(r) != 1 {
return errors.New("values don't match column count")
}
if i != 0 {
buf.WriteString(", ")
}
if err := EncodeValue(buf, r); err != nil {
return err
}
}
buf.WriteByte(')')
return nil
}

func (tpl *TupleEqualityList) encodeAsEquality(buf *bytes.Buffer) error {
for i, r := range tpl.Rows {
if i != 0 {
buf.WriteString(" or ")
}
buf.WriteString("(")
for j, c := range tpl.Columns {
if j != 0 {
buf.WriteString(" and ")
}
buf.WriteString(c)
buf.WriteString(" = ")
if err := EncodeValue(buf, r[j]); err != nil {
return err
}
}
buf.WriteByte(')')
}
return nil
}

func FetchBindVar(name string, bindVariables map[string]interface{}) (val interface{}, isList bool, err error) {
name = name[1:]
if name[0] == ':' {
name = name[1:]
isList = true
}
supplied, ok := bindVariables[name]
if !ok {
return nil, false, fmt.Errorf("missing bind var %s", name)
}
list, gotList := supplied.([]interface{})
if isList {
if !gotList {
return nil, false, fmt.Errorf("unexpected list arg type %T for key %s", supplied, name)
}
if len(list) == 0 {
return nil, false, fmt.Errorf("empty list supplied for %s", name)
}
return list, true, nil
}
if gotList {
return nil, false, fmt.Errorf("unexpected arg type %T for key %s", supplied, name)
}
return supplied, false, nil
}

+ 0
- 1813
vendor/github.com/dinedal/textql/sqlparser/sql.go
File diff suppressed because it is too large
View File


+ 0
- 1058
vendor/github.com/dinedal/textql/sqlparser/sql.y
File diff suppressed because it is too large
View File


+ 0
- 59
vendor/github.com/dinedal/textql/sqlparser/sql_mod.go View File

@@ -1,59 +0,0 @@
package sqlparser

// Magicify runs the SQL passed in, and a table name, throught a customized
// TextQL SQL Parser. This provides the following functionality:
// - Queries that do not start with SELECT are implictly mapped to SELECT statements
// - Queries that are missing a FROM, have the FROM inserted with tableName
func Magicify(sql string, tableName string) string {
if tableName == "" {
return sql
}

statement, err := Parse(sql)

if err != nil {
return sql
}

switch statement := statement.(type) {
case *Select:
replaceFromInSelect(statement, tableName)
return generateQuery(statement)
default:
return sql
}
}

func replaceFromInSelect(statement *Select, tableName string) {
if statement.From == nil {
tableName := &TableName{[]byte(tableName), nil}
aliasedTableExpr := AliasedTableExpr{tableName, nil, nil}
tableExprs := TableExprs{&aliasedTableExpr}
statement.From = &From{Type: AST_FROM, Expr: tableExprs}
} else {
for _, expr := range statement.From.Expr {
switch expr := expr.(type) {
case *AliasedTableExpr:
switch subQuery := expr.Expr.(type) {
case *Subquery:
switch selectSubQuery := subQuery.Select.(type) {
case *Select:
replaceFromInSelect(selectSubQuery, tableName)
default:
return
}
default:
return
}
default:
return
}
}
}
}

func generateQuery(statement Statement) string {
buf := NewTrackedBuffer(nil)
statement.Format(buf)
return buf.String()
}

+ 0
- 378
vendor/github.com/dinedal/textql/sqlparser/sqltypes/sqltypes.go View File

@@ -1,378 +0,0 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package sqltypes implements interfaces and types that represent SQL values.
package sqltypes

import (
"encoding/base64"
"encoding/gob"
"encoding/json"
"fmt"
"reflect"
"strconv"
"time"
"unsafe"
)

var (
NULL = Value{}
DONTESCAPE = byte(255)
nullstr = []byte("null")
)

// BinWriter interface is used for encoding values.
// Types like bytes.Buffer conform to this interface.
// We expect the writer objects to be in-memory buffers.
// So, we don't expect the write operations to fail.
type BinWriter interface {
Write([]byte) (int, error)
WriteByte(byte) error
}

// Value can store any SQL value. NULL is stored as nil.
type Value struct {
Inner InnerValue
}

// Numeric represents non-fractional SQL number.
type Numeric []byte

// Fractional represents fractional types like float and decimal
// It's functionally equivalent to Numeric other than how it's constructed
type Fractional []byte

// String represents any SQL type that needs to be represented using quotes.
type String []byte

// MakeNumeric makes a Numeric from a []byte without validation.
func MakeNumeric(b []byte) Value {
return Value{Numeric(b)}
}

// MakeFractional makes a Fractional value from a []byte without validation.
func MakeFractional(b []byte) Value {
return Value{Fractional(b)}
}

// MakeString makes a String value from a []byte.
func MakeString(b []byte) Value {
return Value{String(b)}
}

// Raw returns the raw bytes. All types are currently implemented as []byte.
func (v Value) Raw() []byte {
if v.Inner == nil {
return nil
}
return v.Inner.raw()
}

// String returns the raw value as a string
func (v Value) String() string {
if v.Inner == nil {
return ""
}
return toString(v.Inner.raw())
}

// String force casts a []byte to a string.
// USE AT YOUR OWN RISK
func toString(b []byte) (s string) {
if len(b) == 0 {
return ""
}
pbytes := (*reflect.SliceHeader)(unsafe.Pointer(&b))
pstring := (*reflect.StringHeader)(unsafe.Pointer(&s))
pstring.Data = pbytes.Data
pstring.Len = pbytes.Len
return
}

// ParseInt64 will parse a Numeric value into an int64
func (v Value) ParseInt64() (val int64, err error) {
if v.Inner == nil {
return 0, fmt.Errorf("value is null")
}
n, ok := v.Inner.(Numeric)
if !ok {
return 0, fmt.Errorf("value is not Numeric")
}
return strconv.ParseInt(string(n.raw()), 10, 64)
}

// ParseUint64 will parse a Numeric value into a uint64
func (v Value) ParseUint64() (val uint64, err error) {
if v.Inner == nil {
return 0, fmt.Errorf("value is null")
}
n, ok := v.Inner.(Numeric)
if !ok {
return 0, fmt.Errorf("value is not Numeric")
}
return strconv.ParseUint(string(n.raw()), 10, 64)
}

// ParseFloat64 will parse a Fractional value into an float64
func (v Value) ParseFloat64() (val float64, err error) {
if v.Inner == nil {
return 0, fmt.Errorf("value is null")
}
n, ok := v.Inner.(Fractional)
if !ok {
return 0, fmt.Errorf("value is not Fractional")
}
return strconv.ParseFloat(string(n.raw()), 64)
}

// EncodeSql encodes the value into an SQL statement. Can be binary.
func (v Value) EncodeSql(b BinWriter) {
if v.Inner == nil {
if _, err := b.Write(nullstr); err != nil {
panic(err)
}
} else {
v.Inner.encodeSql(b)
}
}

// EncodeAscii encodes the value using 7-bit clean ascii bytes.
func (v Value) EncodeAscii(b BinWriter) {
if v.Inner == nil {
if _, err := b.Write(nullstr); err != nil {
panic(err)
}
} else {
v.Inner.encodeAscii(b)
}
}

func (v Value) IsNull() bool {
return v.Inner == nil
}

func (v Value) IsNumeric() (ok bool) {
if v.Inner != nil {
_, ok = v.Inner.(Numeric)
}
return ok
}

func (v Value) IsFractional() (ok bool) {
if v.Inner != nil {
_, ok = v.Inner.(Fractional)
}
return ok
}

func (v Value) IsString() (ok bool) {
if v.Inner != nil {
_, ok = v.Inner.(String)
}
return ok
}

// MarshalJSON should only be used for testing.
// It's not a complete implementation.
func (v Value) MarshalJSON() ([]byte, error) {
return json.Marshal(v.Inner)
}

// UnmarshalJSON should only be used for testing.
// It's not a complete implementation.
func (v *Value) UnmarshalJSON(b []byte) error {
if len(b) == 0 {
return fmt.Errorf("error unmarshaling empty bytes")
}
var val interface{}
var err error
switch b[0] {
case '-':
var ival int64
err = json.Unmarshal(b, &ival)
val = ival
case '"':
var bval []byte
err = json.Unmarshal(b, &bval)
val = bval
case 'n': // null
err = json.Unmarshal(b, &val)
default:
var uval uint64
err = json.Unmarshal(b, &uval)
val = uval
}
if err != nil {
return err
}
*v, err = BuildValue(val)
return err
}

// InnerValue defines methods that need to be supported by all non-null value types.
type InnerValue interface {
raw() []byte
encodeSql(BinWriter)
encodeAscii(BinWriter)
}

func BuildValue(goval interface{}) (v Value, err error) {
switch bindVal := goval.(type) {
case nil:
// no op
case int:
v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
case int32:
v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
case int64:
v = Value{Numeric(strconv.AppendInt(nil, int64(bindVal), 10))}
case uint:
v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
case uint32:
v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
case uint64:
v = Value{Numeric(strconv.AppendUint(nil, uint64(bindVal), 10))}
case float64:
v = Value{Fractional(strconv.AppendFloat(nil, bindVal, 'f', -1, 64))}
case string:
v = Value{String([]byte(bindVal))}
case []byte:
v = Value{String(bindVal)}
case time.Time:
v = Value{String([]byte(bindVal.Format("2006-01-02 15:04:05")))}
case Numeric, Fractional, String:
v = Value{bindVal.(InnerValue)}
case Value:
v = bindVal
default:
return Value{}, fmt.Errorf("unsupported bind variable type %T: %v", goval, goval)
}
return v, nil
}

// BuildNumeric builds a Numeric type that represents any whole number.
// It normalizes the representation to ensure 1:1 mapping between the
// number and its representation.
func BuildNumeric(val string) (n Value, err error) {
if val[0] == '-' || val[0] == '+' {
signed, err := strconv.ParseInt(val, 0, 64)
if err != nil {
return Value{}, err
}
n = Value{Numeric(strconv.AppendInt(nil, signed, 10))}
} else {
unsigned, err := strconv.ParseUint(val, 0, 64)
if err != nil {
return Value{}, err
}
n = Value{Numeric(strconv.AppendUint(nil, unsigned, 10))}
}
return n, nil
}

func (n Numeric) raw() []byte {
return []byte(n)
}

func (n Numeric) encodeSql(b BinWriter) {
if _, err := b.Write(n.raw()); err != nil {
panic(err)
}
}

func (n Numeric) encodeAscii(b BinWriter) {
if _, err := b.Write(n.raw()); err != nil {
panic(err)
}
}

func (n Numeric) MarshalJSON() ([]byte, error) {
return n.raw(), nil
}

func (f Fractional) raw() []byte {
return []byte(f)
}

func (f Fractional) encodeSql(b BinWriter) {
if _, err := b.Write(f.raw()); err != nil {
panic(err)
}
}

func (f Fractional) encodeAscii(b BinWriter) {
if _, err := b.Write(f.raw()); err != nil {
panic(err)
}
}

func (s String) MarshalJSON() ([]byte, error) {
return json.Marshal(string(s.raw()))
}

func (s String) raw() []byte {
return []byte(s)
}

func (s String) encodeSql(b BinWriter) {
writebyte(b, '\'')
for _, ch := range s.raw() {
if encodedChar := SqlEncodeMap[ch]; encodedChar == DONTESCAPE {
writebyte(b, ch)
} else {
writebyte(b, '\\')
writebyte(b, encodedChar)
}
}
writebyte(b, '\'')
}

func (s String) encodeAscii(b BinWriter) {
writebyte(b, '\'')
encoder := base64.NewEncoder(base64.StdEncoding, b)
encoder.Write(s.raw())
encoder.Close()
writebyte(b, '\'')
}

func writebyte(b BinWriter, c byte) {
if err := b.WriteByte(c); err != nil {
panic(err)
}
}

// SqlEncodeMap specifies how to escape binary data with '\'.
// Complies to http://dev.mysql.com/doc/refman/5.1/en/string-syntax.html
var SqlEncodeMap [256]byte

// SqlDecodeMap is the reverse of SqlEncodeMap
var SqlDecodeMap [256]byte

var encodeRef = map[byte]byte{
'\x00': '0',
'\'': '\'',
'"': '"',
'\b': 'b',
'\n': 'n',
'\r': 'r',
'\t': 't',
26: 'Z', // ctl-Z
'\\': '\\',
}

func init() {
for i := range SqlEncodeMap {
SqlEncodeMap[i] = DONTESCAPE
SqlDecodeMap[i] = DONTESCAPE
}
for i := range SqlEncodeMap {
if to, ok := encodeRef[byte(i)]; ok {
SqlEncodeMap[byte(i)] = to
SqlDecodeMap[to] = byte(i)
}
}
gob.Register(Numeric(nil))
gob.Register(Fractional(nil))
gob.Register(String(nil))
}

+ 0
- 454
vendor/github.com/dinedal/textql/sqlparser/token.go View File

@@ -1,454 +0,0 @@
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package sqlparser

import (
"bytes"
"fmt"
"strings"

"github.com/dinedal/textql/sqlparser/sqltypes"
)

const EOFCHAR = 0x100

// Tokenizer is the struct used to generate SQL
// tokens for the parser.
type Tokenizer struct {
InStream *strings.Reader
AllowComments bool
ForceEOF bool
lastChar uint16
Position int
errorToken []byte
LastError string
posVarIndex int
ParseTree Statement
}

// NewStringTokenizer creates a new Tokenizer for the
// sql string.
func NewStringTokenizer(sql string) *Tokenizer {
return &Tokenizer{InStream: strings.NewReader(sql)}
}

var keywords = map[string]int{
"all": ALL,
"alter": ALTER,
"analyze": ANALYZE,
"and": AND,
"as": AS,
"asc": ASC,
"between": BETWEEN,
"by": BY,
"case": CASE,
"create": CREATE,
"cross": CROSS,
"default": DEFAULT,
"delete": DELETE,
"desc": DESC,
"describe": DESCRIBE,
"distinct": DISTINCT,
"drop": DROP,
"duplicate": DUPLICATE,
"else": ELSE,
"end": END,
"except": EXCEPT,
"exists": EXISTS,
"explain": EXPLAIN,
"for": FOR,
"force": FORCE,
"from": FROM,
"group": GROUP,
"having": HAVING,
"if": IF,
"ignore": IGNORE,
"in": IN,
"index": INDEX,
"inner": INNER,
"insert": INSERT,
"intersect": INTERSECT,
"into": INTO,
"is": IS,
"join": JOIN,
"key": KEY,
"keyrange": KEYRANGE,
"left": LEFT,
"like": LIKE,
"limit": LIMIT,
"lock": LOCK,
"minus": MINUS,
"natural": NATURAL,
"not": NOT,