From 0dd3951636d8f84963530de304ed13977518f31c Mon Sep 17 00:00:00 2001 From: Nash Tsai Date: Thu, 26 Dec 2013 18:31:04 +0800 Subject: [PATCH 1/3] make Import() call Db.Exec() directly --- engine.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/engine.go b/engine.go index 65d2f095..9800954b 100644 --- a/engine.go +++ b/engine.go @@ -972,18 +972,22 @@ func (engine *Engine) Import(ddlPath string) ([]sql.Result, error) { scanner.Split(semiColSpliter) session := engine.NewSession() - session.IsAutoClose = false + defer session.Close() + err = session.newDb() + if err != nil { + return results, err + } + for scanner.Scan() { query := scanner.Text() query = strings.Trim(query, " \t") if len(query) > 0 { - result, err := session.Exec(query) + result, err := session.Db.Exec(query) results = append(results, result) if err != nil { lastError = err } } } - session.Close() return results, lastError } From d38aa33645fe3f49304f3e23653c030bd5c2f59b Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 31 Dec 2013 10:03:30 +0800 Subject: [PATCH 2/3] add Contributing.md --- CONTRIBUTING.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..c7fde071 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,33 @@ +## Contributing to xorm + +`xorm` has a backlog of pull requests, but contributions are still very +much welcome. You can help with patch review, submitting bug reports, +or adding new functionality. There is no formal style guide, but +please conform to the style of existing code and general Go formatting +conventions when submitting patches. + +### Patch review + +Help review existing open pull requests by commenting on the code or +proposed functionality. + +### Bug reports + +We appreciate any bug reports, but especially ones with self-contained +(doesn't depend on code outside of pq), minimal (can't be simplified +further) test cases. It's especially helpful if you can submit a pull +request with just the failing test case (you'll probably want to +pattern it after the tests in +[base_test.go](https://github.com/lunny/xorm/blob/master/base_test.go) AND +[benchmark_base_test.go](https://github.com/lunny/xorm/blob/master/benchmark_base_test.go). + +If you implements a new database interface, you maybe need to add a _test.go file. +For example, [mysql_test.go](https://github.com/lunny/xorm/blob/master/mysql_test.go) + +### New functionality + +There are a number of pending patches for new functionality, so +additional feature patches will take a while to merge. Still, patches +are generally reviewed based on usefulness and complexity in addition +to time-in-queue, so if you have a knockout idea, take a shot. Feel +free to open an issue discussion your proposed patch beforehand. From 2c1722ff1d293d542d49ec1e8081dd50892faa00 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 31 Dec 2013 12:22:36 +0800 Subject: [PATCH 3/3] resolved #36 --- engine.go | 1 + mysql.go | 19 ++++++++++++++++++- statement.go | 8 ++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/engine.go b/engine.go index c1e69b6d..b5fd317f 100644 --- a/engine.go +++ b/engine.go @@ -28,6 +28,7 @@ const ( // a dialect is a driver's wrapper type dialect interface { Init(DriverName, DataSourceName string) error + URI() *uri DBType() string SqlType(t *Column) string SupportInsertMany() bool diff --git a/mysql.go b/mysql.go index 6e51780b..4dcde839 100644 --- a/mysql.go +++ b/mysql.go @@ -33,7 +33,6 @@ type mysqlParser struct { } func (p *mysqlParser) parse(driverName, dataSourceName string) (*uri, error) { - //cfg.params = make(map[string]string) dsnPattern := regexp.MustCompile( `^(?:(?P.*?)(?::(?P.*))?@)?` + // [user[:password]@] `(?:(?P[^\(]*)(?:\((?P[^\)]*)\))?)?` + // [net[(addr)]] @@ -49,6 +48,20 @@ func (p *mysqlParser) parse(driverName, dataSourceName string) (*uri, error) { switch names[i] { case "dbname": uri.dbName = match + case "params": + if len(match) > 0 { + kvs := strings.Split(match, "&") + for _, kv := range kvs { + splits := strings.Split(kv, "=") + if len(splits) == 2 { + switch splits[0] { + case "charset": + uri.charset = splits[1] + } + } + } + } + } } return uri, nil @@ -68,6 +81,10 @@ func (b *base) init(parser parser, drivername, dataSourceName string) (err error return } +func (b *base) URI() *uri { + return b.uri +} + func (b *base) DBType() string { return b.uri.dbType } diff --git a/statement.go b/statement.go index f87c0c5d..ab6ecd62 100644 --- a/statement.go +++ b/statement.go @@ -638,8 +638,12 @@ func (statement *Statement) genCreateTableSQL() string { if statement.Engine.dialect.SupportEngine() && statement.StoreEngine != "" { sql += " ENGINE=" + statement.StoreEngine } - if statement.Engine.dialect.SupportCharset() && statement.Charset != "" { - sql += " DEFAULT CHARSET " + statement.Charset + if statement.Engine.dialect.SupportCharset() { + if statement.Charset != "" { + sql += " DEFAULT CHARSET " + statement.Charset + } else if statement.Engine.dialect.URI().charset != "" { + sql += " DEFAULT CHARSET " + statement.Engine.dialect.URI().charset + } } sql += ";" return sql