good morning!!!!

Skip to content
Snippets Groups Projects
Commit 87d3d55d authored by José Carlos's avatar José Carlos Committed by GitHub
Browse files

Merge pull request #211 from upper/issue-210

Fix cache bug with raw statements. Closes #210
parents 357ca122 85269fee
No related branches found
No related tags found
No related merge requests found
......@@ -81,3 +81,39 @@ func TestStringAndInt64Array(t *testing.T) {
assert.NotZero(t, itemCheck.Strings)
}
}
func TestIssue210(t *testing.T) {
list := []string{
`DROP TABLE IF EXISTS testing123`,
`DROP TABLE IF EXISTS hello`,
`CREATE TABLE IF NOT EXISTS testing123 (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL
)
`,
`CREATE TABLE IF NOT EXISTS hello (
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL
)`,
}
sess := mustOpen()
defer sess.Close()
tx, err := sess.NewTransaction()
assert.NoError(t, err)
for i := range list {
_, err = tx.Exec(list[i])
assert.NoError(t, err)
}
err = tx.Commit()
assert.NoError(t, err)
_, err = sess.Collection("testing123").Find().Count()
assert.NoError(t, err)
_, err = sess.Collection("hello").Find().Count()
assert.NoError(t, err)
}
......@@ -23,7 +23,7 @@ type Statement struct {
Limit
Offset
rawSQL string
SQL string
hash hash
}
......@@ -64,9 +64,9 @@ func (s *Statement) Hash() string {
// Compile transforms the Statement into an equivalent SQL query.
func (s *Statement) Compile(layout *Template) (compiled string) {
if s.Type == rawSQL {
if s.Type == SQL {
// No need to hit the cache.
return s.rawSQL
return s.SQL
}
if z, ok := layout.Read(s); ok {
......@@ -117,7 +117,7 @@ func (s *Statement) Compile(layout *Template) (compiled string) {
// RawSQL represents a raw SQL statement.
func RawSQL(s string) *Statement {
return &Statement{
Type: rawSQL,
rawSQL: s,
Type: SQL,
SQL: s,
}
}
......@@ -20,7 +20,7 @@ const (
Select
Update
Delete
rawSQL
SQL
)
type (
......
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