Fix insert
This commit is contained in:
parent
561191a079
commit
572e277b42
|
@ -10,6 +10,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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) {
|
func parseOracle(driverName, dataSourceName string) (*URI, error) {
|
||||||
var connStr = dataSourceName
|
var connStr = dataSourceName
|
||||||
if !strings.HasPrefix(connStr, "oracle://") {
|
if !strings.HasPrefix(connStr, "oracle://") {
|
||||||
connStr = fmt.Sprintf("oracle://%s", connStr)
|
return parseNoProtocol(driverName, dataSourceName)
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(connStr)
|
u, err := url.Parse(connStr)
|
||||||
|
|
|
@ -44,6 +44,7 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasInsertColumns = len(colNames) > 0
|
var hasInsertColumns = len(colNames) > 0
|
||||||
|
<<<<<<< HEAD
|
||||||
var needSeq = len(table.AutoIncrement) > 0 && (statement.dialect.URI().DBType == schemas.ORACLE || statement.dialect.URI().DBType == schemas.DAMENG)
|
var needSeq = len(table.AutoIncrement) > 0 && (statement.dialect.URI().DBType == schemas.ORACLE || statement.dialect.URI().DBType == schemas.DAMENG)
|
||||||
if needSeq {
|
if needSeq {
|
||||||
for _, col := range colNames {
|
for _, col := range colNames {
|
||||||
|
@ -56,6 +57,10 @@ func (statement *Statement) GenInsertSQL(colNames []string, args []interface{})
|
||||||
|
|
||||||
if !hasInsertColumns && statement.dialect.URI().DBType != schemas.ORACLE &&
|
if !hasInsertColumns && statement.dialect.URI().DBType != schemas.ORACLE &&
|
||||||
statement.dialect.URI().DBType != schemas.DAMENG {
|
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 statement.dialect.URI().DBType == schemas.MYSQL {
|
||||||
if _, err := buf.WriteString(" VALUES ()"); err != nil {
|
if _, err := buf.WriteString(" VALUES ()"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue