good morning!!!!

Skip to content
Snippets Groups Projects
Commit 8f7868b4 authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

Adding test for select star.

parent 85b21dee
No related branches found
No related tags found
No related merge requests found
...@@ -9,13 +9,16 @@ type Columns struct { ...@@ -9,13 +9,16 @@ type Columns struct {
} }
func (self Columns) String() string { func (self Columns) String() string {
out := make([]string, len(self.v)) if len(self.v) > 0 {
out := make([]string, len(self.v))
for i := range self.v { for i := range self.v {
out[i] = self.v[i].String() out[i] = self.v[i].String()
} }
return strings.Join(out, sqlColumnComma) return strings.Join(out, sqlColumnComma)
}
return ""
} }
func (self Columns) Len() int { func (self Columns) Len() int {
......
...@@ -18,7 +18,13 @@ const ( ...@@ -18,7 +18,13 @@ const (
{{end}} {{end}}
` `
sqlSelectLayout = ` sqlSelectLayout = `
SELECT {{.Columns}} SELECT
{{if .Columns}}
{{.Columns}}
{{else}}
*
{{end}}
FROM {{.Source}} FROM {{.Source}}
...@@ -80,18 +86,14 @@ const ( ...@@ -80,18 +86,14 @@ const (
DROP TABLE {{.Source}} DROP TABLE {{.Source}}
` `
sqlTautology = `1 = 1`
sqlAllFields = `*`
sqlAndKeyword = `AND` sqlAndKeyword = `AND`
sqlOrKeyword = `OR` sqlOrKeyword = `OR`
sqlDefaultOperator = `=`
sqlDescKeyword = `DESC` sqlDescKeyword = `DESC`
sqlAscKeyword = `ASC` sqlAscKeyword = `ASC`
sqlDefaultOperator = `=`
sqlConditionGroup = `({{.}})` sqlConditionGroup = `({{.}})`
sqlColumnValue = `{{.Column}} {{.Operator}} {{.Value}}` sqlColumnValue = `{{.Column}} {{.Operator}} {{.Value}}`
sqlFunction = `{{.Function}}({{.Value}})`
) )
type Type uint type Type uint
......
...@@ -103,6 +103,23 @@ func TestSelectCountWhere(t *testing.T) { ...@@ -103,6 +103,23 @@ func TestSelectCountWhere(t *testing.T) {
} }
} }
func TestSelectStarFrom(t *testing.T) {
var s, e string
var stmt Statement
stmt = Statement{
Type: SqlSelect,
Source: Source{"source name"},
}
s = trim(stmt.Compile())
e = `SELECT * FROM "source name"`
if s != e {
t.Fatalf("Got: %s, Expecting: %s", s, e)
}
}
func TestSelectFieldsFrom(t *testing.T) { func TestSelectFieldsFrom(t *testing.T) {
var s, e string var s, e string
var stmt Statement var stmt Statement
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment