diff --git a/create.go b/create.go index 7cb6547..b315433 100644 --- a/create.go +++ b/create.go @@ -1,7 +1,6 @@ package oracle import ( - "database/sql" "reflect" "github.com/sijms/go-ora/v2" @@ -76,9 +75,14 @@ func Create(db *gorm.DB) { if idx > 0 { _ = stmt.WriteByte(',') } - stmt.AddVar(stmt, sql.Out{Dest: reflect.New(field.FieldType).Interface()}) + + outVar := go_ora.Out{Dest: reflect.New(field.FieldType).Interface()} + if field.Size > 0 { + outVar.Size = field.Size + } + stmt.AddVar(stmt, outVar) } - _, _ = stmt.WriteString(" /*-sql.Out{}-*/") + _, _ = stmt.WriteString(" /*-go_ora.Out{}-*/") } } @@ -229,7 +233,7 @@ func getDefaultValues(db *gorm.DB, idx int) { for _, val := range db.Statement.Vars { switch v := val.(type) { - case sql.Out: + case go_ora.Out: switch insertTo.Kind() { case reflect.Slice, reflect.Array: for i := insertTo.Len() - 1; i >= 0; i-- { diff --git a/create_test.go b/create_test.go index 42d137d..c50e161 100644 --- a/create_test.go +++ b/create_test.go @@ -171,3 +171,56 @@ func TestMergeCreateUnique(t *testing.T) { t.Logf("result: %s", dataJsonBytes) }) } + +type testModelOra03146TTC struct { + Id int64 `gorm:"primaryKey;autoIncrement:false;column:SL_ID;type:uint;size:20;default:0;comment:id" json:"SL_ID"` + ApiName string `gorm:"column:SL_API_NAME;type:VARCHAR2;size:100;default:null;comment:接口名称" json:"SL_API_NAME"` + RawReceive string `gorm:"column:SL_RAW_RECEIVE_JSON;type:VARCHAR2;size:4000;default:null;comment:原始请求参数" json:"SL_RAW_RECEIVE_JSON"` + RawSend string `gorm:"column:SL_RAW_SEND_JSON;type:VARCHAR2;size:4000;default:null;comment:原始响应参数" json:"SL_RAW_SEND_JSON"` + DealReceive string `gorm:"column:SL_DEAL_RECEIVE_JSON;type:VARCHAR2;size:4000;default:null;comment:处理请求参数" json:"SL_DEAL_RECEIVE_JSON"` + DealSend string `gorm:"column:SL_DEAL_SEND_JSON;type:VARCHAR2;size:4000;default:null;comment:处理响应参数" json:"SL_DEAL_SEND_JSON"` + Code string `gorm:"column:SL_CODE;type:VARCHAR2;size:16;default:null;comment:http状态" json:"SL_CODE"` + CreatedTime time.Time `gorm:"column:SL_CREATED_TIME;type:date;default:null;comment:创建时间" json:"SL_CREATED_TIME"` +} + +func TestOra03146TTC(t *testing.T) { + db, err := dbNamingCase, dbErrors[0] + if err != nil { + t.Fatal(err) + } + if db == nil { + t.Log("db is nil!") + return + } + + model := testModelOra03146TTC{} + migrator := db.Set("gorm:table_comments", "TTC 字段的缓冲区长度无效问题测试表").Migrator() + if migrator.HasTable(model) { + if err = migrator.DropTable(model); err != nil { + t.Fatalf("DropTable() error = %v", err) + } + } + if err = migrator.AutoMigrate(model); err != nil { + t.Fatalf("AutoMigrate() error = %v", err) + } else { + t.Log("AutoMigrate() success!") + } + + // INSERT INTO "T100_SCPTOAPI_LOG" ("SL_ID","SL_API_NAME","SL_RAW_RECEIVE_JSON","SL_RAW_SEND_JSON","SL_DEAL_RECEIVE_JSON","SL_DEAL_SEND_JSON","SL_CODE","SL_CREATED_TIME") + // VALUES (9578529926701056,'/v1/t100/packingNum','11111','11111','11111','11111','111','2024-08-27 18:21:39.495') + data := testModelOra03146TTC{ + Id: 9578529926701056, + ApiName: "/v1/t100/packingNum", + RawReceive: "11111", + RawSend: "11111", + DealReceive: "11111", + DealSend: "11111", + Code: "111", + CreatedTime: time.Now(), + } + result := db.Create(&data) + if err = result.Error; err != nil { + t.Fatalf("执行失败:%v", err) + } + t.Log("执行成功,影响行数:", result.RowsAffected) +}