From 86beb3b026508e86c9d57e25d5ae9f3ba371c0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= <jose.carlos@menteslibres.net> Date: Sun, 8 Jun 2014 15:29:48 -0500 Subject: [PATCH] Fixing case for information_schema.tables. --- util/sqlgen/main_test.go | 17 +++++++++++++++++ util/sqlgen/table.go | 10 ++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/util/sqlgen/main_test.go b/util/sqlgen/main_test.go index 7bdaeebb..b2a85733 100644 --- a/util/sqlgen/main_test.go +++ b/util/sqlgen/main_test.go @@ -73,6 +73,23 @@ func TestSelectCount(t *testing.T) { } } +func TestSelectCountRelation(t *testing.T) { + var s, e string + var stmt Statement + + stmt = Statement{ + Type: SqlSelectCount, + Table: Table{"information_schema.tables"}, + } + + s = trim(stmt.Compile()) + e = `SELECT COUNT(1) AS _t FROM "information_schema"."tables"` + + if s != e { + t.Fatalf("Got: %s, Expecting: %s", s, e) + } +} + func TestSelectCountWhere(t *testing.T) { var s, e string var stmt Statement diff --git a/util/sqlgen/table.go b/util/sqlgen/table.go index d8093472..71e540af 100644 --- a/util/sqlgen/table.go +++ b/util/sqlgen/table.go @@ -1,7 +1,7 @@ package sqlgen import ( - "fmt" + "strings" ) type Table struct { @@ -9,5 +9,11 @@ type Table struct { } func (self Table) String() string { - return mustParse(Layout.IdentifierQuote, Raw{fmt.Sprintf(`%v`, self.Value)}) + chunks := strings.Split(self.Value, Layout.ColumnSeparator) + + for i := range chunks { + chunks[i] = mustParse(Layout.IdentifierQuote, Raw{chunks[i]}) + } + + return strings.Join(chunks, Layout.ColumnSeparator) } -- GitLab