Fix batch insert
This commit is contained in:
parent
3c7daece76
commit
095d7b9f3d
|
@ -92,7 +92,6 @@ func BenchmarkOriQuery(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
//fmt.Println(Id, Name, Title, Age, Alias, NickName)
|
||||
}
|
||||
rows.Close()
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package dialects
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
@ -658,6 +659,9 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
var pkName string
|
||||
err := queryer.QueryRowContext(ctx, s, tableName).Scan(&pkName)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -715,8 +719,6 @@ func (db *oracle) GetColumns(queryer core.Queryer, ctx context.Context, tableNam
|
|||
if has {
|
||||
col.IsAutoIncrement = true
|
||||
}
|
||||
|
||||
fmt.Println("-----", pkName, col.Name, col.IsPrimaryKey)
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -888,8 +890,6 @@ func parseOracle(driverName, dataSourceName string) (*URI, error) {
|
|||
db.Passwd, _ = u.User.Password()
|
||||
}
|
||||
|
||||
fmt.Printf("%#v\n", db)
|
||||
|
||||
if db.DBName == "" {
|
||||
return nil, errors.New("dbname is empty")
|
||||
}
|
||||
|
|
|
@ -17,7 +17,11 @@ func FormatTime(dialect Dialect, sqlTypeName string, t time.Time) (v interface{}
|
|||
s := t.Format("2006-01-02 15:04:05") // time.RFC3339
|
||||
v = s[11:19]
|
||||
case schemas.Date:
|
||||
v = t.Format("2006-01-02")
|
||||
if dialect.URI().DBType == schemas.ORACLE {
|
||||
v = t
|
||||
} else {
|
||||
v = t.Format("2006-01-02")
|
||||
}
|
||||
case schemas.DateTime, schemas.TimeStamp, schemas.Varchar: // !DarthPestilane! format time when sqlTypeName is schemas.Varchar.
|
||||
v = t.Format("2006-01-02 15:04:05")
|
||||
case schemas.TimeStampz:
|
||||
|
|
|
@ -150,6 +150,13 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
|
|||
}
|
||||
fieldValue := *ptrFieldValue
|
||||
if col.IsAutoIncrement && utils.IsZero(fieldValue.Interface()) {
|
||||
if session.engine.dialect.URI().DBType == schemas.ORACLE {
|
||||
if i == 0 {
|
||||
colNames = append(colNames, col.Name)
|
||||
cols = append(cols, col)
|
||||
}
|
||||
colPlaces = append(colPlaces, "seq_"+tableName+".nextval")
|
||||
}
|
||||
continue
|
||||
}
|
||||
if col.MapType == schemas.ONLYFROMDB {
|
||||
|
@ -357,7 +364,7 @@ func (session *Session) innerInsert(bean interface{}) (int64, error) {
|
|||
}
|
||||
|
||||
var id int64
|
||||
err = session.queryRow(fmt.Sprintf("select %s.currval from dual", tableName)).Scan(&id)
|
||||
err = session.queryRow(fmt.Sprintf("select seq_%s.currval from dual", tableName)).Scan(&id)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
|
@ -536,10 +543,14 @@ 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
|
||||
val, t := session.engine.nowTime(col)
|
||||
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
|
||||
session.afterClosures = append(session.afterClosures, func(bean interface{}) {
|
||||
|
|
Loading…
Reference in New Issue