Merge branch 'master' of github.com:lunny/xorm
This commit is contained in:
commit
a13cde97f8
|
@ -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 <databasename>_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.
|
11
engine.go
11
engine.go
|
@ -28,6 +28,7 @@ const (
|
||||||
// a dialect is a driver's wrapper
|
// a dialect is a driver's wrapper
|
||||||
type dialect interface {
|
type dialect interface {
|
||||||
Init(DriverName, DataSourceName string) error
|
Init(DriverName, DataSourceName string) error
|
||||||
|
URI() *uri
|
||||||
DBType() string
|
DBType() string
|
||||||
SqlType(t *Column) string
|
SqlType(t *Column) string
|
||||||
SupportInsertMany() bool
|
SupportInsertMany() bool
|
||||||
|
@ -980,18 +981,22 @@ func (engine *Engine) Import(ddlPath string) ([]sql.Result, error) {
|
||||||
scanner.Split(semiColSpliter)
|
scanner.Split(semiColSpliter)
|
||||||
|
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
session.IsAutoClose = false
|
defer session.Close()
|
||||||
|
err = session.newDb()
|
||||||
|
if err != nil {
|
||||||
|
return results, err
|
||||||
|
}
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
query := scanner.Text()
|
query := scanner.Text()
|
||||||
query = strings.Trim(query, " \t")
|
query = strings.Trim(query, " \t")
|
||||||
if len(query) > 0 {
|
if len(query) > 0 {
|
||||||
result, err := session.Exec(query)
|
result, err := session.Db.Exec(query)
|
||||||
results = append(results, result)
|
results = append(results, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lastError = err
|
lastError = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
session.Close()
|
|
||||||
return results, lastError
|
return results, lastError
|
||||||
}
|
}
|
||||||
|
|
19
mysql.go
19
mysql.go
|
@ -33,7 +33,6 @@ type mysqlParser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mysqlParser) parse(driverName, dataSourceName string) (*uri, error) {
|
func (p *mysqlParser) parse(driverName, dataSourceName string) (*uri, error) {
|
||||||
//cfg.params = make(map[string]string)
|
|
||||||
dsnPattern := regexp.MustCompile(
|
dsnPattern := regexp.MustCompile(
|
||||||
`^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
|
`^(?:(?P<user>.*?)(?::(?P<passwd>.*))?@)?` + // [user[:password]@]
|
||||||
`(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
|
`(?:(?P<net>[^\(]*)(?:\((?P<addr>[^\)]*)\))?)?` + // [net[(addr)]]
|
||||||
|
@ -49,6 +48,20 @@ func (p *mysqlParser) parse(driverName, dataSourceName string) (*uri, error) {
|
||||||
switch names[i] {
|
switch names[i] {
|
||||||
case "dbname":
|
case "dbname":
|
||||||
uri.dbName = match
|
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
|
return uri, nil
|
||||||
|
@ -68,6 +81,10 @@ func (b *base) init(parser parser, drivername, dataSourceName string) (err error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *base) URI() *uri {
|
||||||
|
return b.uri
|
||||||
|
}
|
||||||
|
|
||||||
func (b *base) DBType() string {
|
func (b *base) DBType() string {
|
||||||
return b.uri.dbType
|
return b.uri.dbType
|
||||||
}
|
}
|
||||||
|
|
|
@ -638,8 +638,12 @@ func (statement *Statement) genCreateTableSQL() string {
|
||||||
if statement.Engine.dialect.SupportEngine() && statement.StoreEngine != "" {
|
if statement.Engine.dialect.SupportEngine() && statement.StoreEngine != "" {
|
||||||
sql += " ENGINE=" + statement.StoreEngine
|
sql += " ENGINE=" + statement.StoreEngine
|
||||||
}
|
}
|
||||||
if statement.Engine.dialect.SupportCharset() && statement.Charset != "" {
|
if statement.Engine.dialect.SupportCharset() {
|
||||||
sql += " DEFAULT CHARSET " + statement.Charset
|
if statement.Charset != "" {
|
||||||
|
sql += " DEFAULT CHARSET " + statement.Charset
|
||||||
|
} else if statement.Engine.dialect.URI().charset != "" {
|
||||||
|
sql += " DEFAULT CHARSET " + statement.Engine.dialect.URI().charset
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sql += ";"
|
sql += ";"
|
||||||
return sql
|
return sql
|
||||||
|
|
Loading…
Reference in New Issue