From 34e79e0d636a6fa0ebe56f7124413a30ba9bda2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=86=E8=AE=AF=E5=9C=A8=E7=BA=BF?= Date: Sun, 24 Aug 2014 21:15:16 +0800 Subject: [PATCH] fix bugs https://github.com/go-xorm/cmd/issues/3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 商讯在线 --- engine.go | 4 +++- mssql_dialect.go | 2 +- mysql_dialect.go | 6 +++--- oracle_dialect.go | 2 +- postgres_dialect.go | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/engine.go b/engine.go index 51d750aa..045cef53 100644 --- a/engine.go +++ b/engine.go @@ -373,12 +373,14 @@ func (engine *Engine) DumpAll(w io.Writer) error { } else if col.SQLType.IsText() || col.SQLType.IsTime() { var v = fmt.Sprintf("%s", d) temp += ", '" + strings.Replace(v, "'", "''", -1) + "'" - } else if col.SQLType.IsBlob() /**/ { + } else if col.SQLType.IsBlob() { if reflect.TypeOf(d).Kind() == reflect.Slice { temp += fmt.Sprintf(", %s", engine.dialect.FormatBytes(d.([]byte))) } else if reflect.TypeOf(d).Kind() == reflect.String { temp += fmt.Sprintf(", '%s'", d.(string)) } + } else if col.SQLType.IsNumeric() { + temp += fmt.Sprintf(", %s", string(d.([]byte))) } else { s := fmt.Sprintf("%v", d) if strings.Contains(s, ":") || strings.Contains(s, "-") { diff --git a/mssql_dialect.go b/mssql_dialect.go index 5cd2f52b..eee50795 100644 --- a/mssql_dialect.go +++ b/mssql_dialect.go @@ -168,7 +168,7 @@ where a.object_id=object_id('` + tableName + `')` } } - if col.SQLType.IsText() { + if col.SQLType.IsText() || col.SQLType.IsTime() { if col.Default != "" { col.Default = "'" + col.Default + "'" } else { diff --git a/mysql_dialect.go b/mysql_dialect.go index 479e6347..6bebf5af 100644 --- a/mysql_dialect.go +++ b/mysql_dialect.go @@ -60,7 +60,7 @@ func (db *mysql) SqlType(c *core.Column) string { for v, _ := range c.EnumOptions { opts += fmt.Sprintf(",'%v'", v) } - res += strings.TrimLeft(opts,",") + res += strings.TrimLeft(opts, ",") res += ")" case core.Set: //mysql set res = core.Set @@ -69,7 +69,7 @@ func (db *mysql) SqlType(c *core.Column) string { for v, _ := range c.SetOptions { opts += fmt.Sprintf(",'%v'", v) } - res += strings.TrimLeft(opts,",") + res += strings.TrimLeft(opts, ",") res += ")" default: res = t @@ -223,7 +223,7 @@ func (db *mysql) GetColumns(tableName string) ([]string, map[string]*core.Column col.IsAutoIncrement = true } - if col.SQLType.IsText() { + if col.SQLType.IsText() || col.SQLType.IsTime() { if col.Default != "" { col.Default = "'" + col.Default + "'" } else { diff --git a/oracle_dialect.go b/oracle_dialect.go index e23ab297..57da2c50 100644 --- a/oracle_dialect.go +++ b/oracle_dialect.go @@ -158,7 +158,7 @@ func (db *oracle) GetColumns(tableName string) ([]string, map[string]*core.Colum col.Length = dataLen - if col.SQLType.IsText() { + if col.SQLType.IsText() || col.SQLType.IsTime() { if col.Default != "" { col.Default = "'" + col.Default + "'" } else { diff --git a/postgres_dialect.go b/postgres_dialect.go index 61d4f1e2..6819323e 100644 --- a/postgres_dialect.go +++ b/postgres_dialect.go @@ -220,7 +220,7 @@ WHERE c.relkind = 'r'::char AND c.relname = $1 AND f.attnum > 0 ORDER BY f.attnu col.Length = maxLen - if col.SQLType.IsText() { + if col.SQLType.IsText() || col.SQLType.IsTime() { if col.Default != "" { col.Default = "'" + col.Default + "'" } else {