Fix batch insert
This commit is contained in:
parent
75405e50d2
commit
75f02eca0f
|
@ -96,7 +96,6 @@ func BenchmarkOriQuery(b *testing.B) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Error(err)
|
b.Error(err)
|
||||||
}
|
}
|
||||||
//fmt.Println(Id, Name, Title, Age, Alias, NickName)
|
|
||||||
}
|
}
|
||||||
rows.Close()
|
rows.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ func (db *Base) DropSequenceSQL(seqName string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DropTableSQL returns drop table SQL
|
// DropTableSQL returns drop table SQL
|
||||||
func (db *Base) DropTableSQL(tableName, autoincrCol string) (string, bool) {
|
func (db *Base) DropTableSQL(tableName, autoincrCol string) ([]string, bool) {
|
||||||
quote := db.dialect.Quoter().Quote
|
quote := db.dialect.Quoter().Quote
|
||||||
return []string{fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName))}, true
|
return []string{fmt.Sprintf("DROP TABLE IF EXISTS %s", quote(tableName))}, true
|
||||||
}
|
}
|
||||||
|
|
|
@ -692,6 +692,9 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
||||||
var pkName string
|
var pkName string
|
||||||
err := queryer.QueryRowContext(ctx, s, tableName).Scan(&pkName)
|
err := queryer.QueryRowContext(ctx, s, tableName).Scan(&pkName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,8 +752,6 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
||||||
if has {
|
if has {
|
||||||
col.IsAutoIncrement = true
|
col.IsAutoIncrement = true
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("-----", pkName, col.Name, col.IsPrimaryKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -938,8 +939,6 @@ func parseOracle(driverName, dataSourceName string) (*URI, error) {
|
||||||
db.Passwd, _ = u.User.Password()
|
db.Passwd, _ = u.User.Password()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("%#v\n", db)
|
|
||||||
|
|
||||||
if db.DBName == "" {
|
if db.DBName == "" {
|
||||||
return nil, errors.New("dbname is empty")
|
return nil, errors.New("dbname is empty")
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.C
|
||||||
|
|
||||||
switch col.SQLType.Name {
|
switch col.SQLType.Name {
|
||||||
case schemas.Date:
|
case schemas.Date:
|
||||||
|
if dialect.URI().DBType == schemas.ORACLE {
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
return t.Format("2006-01-02"), nil
|
return t.Format("2006-01-02"), nil
|
||||||
case schemas.Time:
|
case schemas.Time:
|
||||||
var layout = "15:04:05"
|
var layout = "15:04:05"
|
||||||
|
@ -40,6 +43,9 @@ func FormatColumnTime(dialect Dialect, dbLocation *time.Location, col *schemas.C
|
||||||
}
|
}
|
||||||
return t.Format(layout), nil
|
return t.Format(layout), nil
|
||||||
case schemas.DateTime, schemas.TimeStamp:
|
case schemas.DateTime, schemas.TimeStamp:
|
||||||
|
if dialect.URI().DBType == schemas.ORACLE {
|
||||||
|
return t, nil
|
||||||
|
}
|
||||||
var layout = "2006-01-02 15:04:05"
|
var layout = "2006-01-02 15:04:05"
|
||||||
if col.Length > 0 {
|
if col.Length > 0 {
|
||||||
layout += "." + strings.Repeat("0", col.Length)
|
layout += "." + strings.Repeat("0", col.Length)
|
||||||
|
|
|
@ -504,13 +504,17 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col.IsCreated || col.IsUpdated) && session.statement.UseAutoTime /*&& isZero(fieldValue.Interface())*/ {
|
if (col.IsCreated || col.IsUpdated) && session.statement.UseAutoTime {
|
||||||
// if time is non-empty, then set to auto time
|
// if time is non-empty, then set to auto time
|
||||||
val, t, err := session.engine.nowTime(col)
|
val, t, err := session.engine.nowTime(col)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
if session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||||
|
args = append(args, t)
|
||||||
|
} else {
|
||||||
args = append(args, val)
|
args = append(args, val)
|
||||||
|
}
|
||||||
|
|
||||||
var colName = col.Name
|
var colName = col.Name
|
||||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||||
|
|
Loading…
Reference in New Issue