Fix batch insert

This commit is contained in:
Lunny Xiao 2020-03-09 17:37:13 +08:00
parent 75405e50d2
commit 75f02eca0f
5 changed files with 16 additions and 8 deletions

View File

@ -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()
} }

View File

@ -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
} }

View File

@ -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")
} }

View File

@ -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)

View File

@ -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
} }
args = append(args, val) if session.engine.dialect.URI().DBType == schemas.ORACLE {
args = append(args, t)
} else {
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{}) {