Fix insert

This commit is contained in:
Lunny Xiao 2020-04-14 15:19:41 +08:00
parent 561191a079
commit 572e277b42
2 changed files with 27 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
@ -916,10 +917,30 @@ func (g *godrorDriver) Features() *DriverFeatures {
}
}
func parseNoProtocol(driverName, dataSourceName string) (*URI, error) {
db := &URI{DBType: schemas.ORACLE}
dsnPattern := regexp.MustCompile(
`^(?P<user>.*)\/(?P<password>.*)@` + // user:password@
`(?P<net>.*)` + // ip:port
`\/(?P<dbname>.*)`) // dbname
matches := dsnPattern.FindStringSubmatch(dataSourceName)
names := dsnPattern.SubexpNames()
for i, match := range matches {
switch names[i] {
case "dbname":
db.DBName = match
}
}
if db.DBName == "" && len(matches) != 0 {
return nil, errors.New("dbname is empty")
}
return db, nil
}
func parseOracle(driverName, dataSourceName string) (*URI, error) {
var connStr = dataSourceName
if !strings.HasPrefix(connStr, "oracle://") {
connStr = fmt.Sprintf("oracle://%s", connStr)
return parseNoProtocol(driverName, dataSourceName)
}
u, err := url.Parse(connStr)

View File

@ -44,6 +44,7 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
}
var hasInsertColumns = len(colNames) > 0
<<<<<<< HEAD
var needSeq = len(table.AutoIncrement) > 0 && (statement.dialect.URI().DBType == schemas.ORACLE || statement.dialect.URI().DBType == schemas.DAMENG)
if needSeq {
for _, col := range colNames {
@ -56,6 +57,10 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
if !hasInsertColumns && statement.dialect.URI().DBType != schemas.ORACLE &&
statement.dialect.URI().DBType != schemas.DAMENG {
=======
if !hasInsertColumns && statement.dialect.URI().DBType != schemas.ORACLE {
>>>>>>> d24e7cb (Fix insert)
if statement.dialect.URI().DBType == schemas.MYSQL {
if _, err := buf.WriteString(" VALUES ()"); err != nil {
return nil, err