mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix gen dao oracle entity bug (#2219)
Co-authored-by: John Guo <john@johng.cn>
This commit is contained in:
@ -220,11 +220,12 @@ func (d *Driver) TableFields(
|
||||
useSchema = gutil.GetOrDefaultStr(d.GetSchema(), schema...)
|
||||
structureSql = fmt.Sprintf(`
|
||||
SELECT
|
||||
COLUMN_NAME AS FIELD,
|
||||
CASE DATA_TYPE
|
||||
WHEN 'NUMBER' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
WHEN 'FLOAT' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
ELSE DATA_TYPE||'('||DATA_LENGTH||')' END AS TYPE,NULLABLE
|
||||
COLUMN_NAME AS FIELD,
|
||||
CASE
|
||||
WHEN (DATA_TYPE='NUMBER' AND NVL(DATA_SCALE,0)=0) THEN 'INT'||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
WHEN (DATA_TYPE='NUMBER' AND NVL(DATA_SCALE,0)>0) THEN 'FLOAT'||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
WHEN DATA_TYPE='FLOAT' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')'
|
||||
ELSE DATA_TYPE||'('||DATA_LENGTH||')' END AS TYPE,NULLABLE
|
||||
FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '%s' ORDER BY COLUMN_ID`,
|
||||
strings.ToUpper(table),
|
||||
)
|
||||
|
||||
@ -119,6 +119,7 @@ func createTable(table ...string) (name string) {
|
||||
PASSWORD CHAR(32) NOT NULL,
|
||||
NICKNAME VARCHAR(45) NOT NULL,
|
||||
CREATE_TIME varchar(45),
|
||||
SALARY NUMBER(18,2),
|
||||
PRIMARY KEY (ID))
|
||||
`, name)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
@ -158,7 +159,7 @@ func dropTable(table string) {
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil {
|
||||
if _, err = db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ package oracle_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -62,10 +63,11 @@ func TestTableFields(t *testing.T) {
|
||||
createTable("t_user")
|
||||
defer dropTable("t_user")
|
||||
var expect = map[string][]interface{}{
|
||||
"ID": {"NUMBER(10,0)", false},
|
||||
"ID": {"INT(10,0)", false},
|
||||
"PASSPORT": {"VARCHAR2(45)", false},
|
||||
"PASSWORD": {"CHAR(32)", false},
|
||||
"NICKNAME": {"VARCHAR2(45)", false},
|
||||
"SALARY": {"FLOAT(18,2)", true},
|
||||
"CREATE_TIME": {"VARCHAR2(45)", true},
|
||||
}
|
||||
|
||||
@ -114,6 +116,7 @@ func TestDoInsert(t *testing.T) {
|
||||
"PASSPORT": fmt.Sprintf(`t%d`, i),
|
||||
"PASSWORD": fmt.Sprintf(`p%d`, i),
|
||||
"NICKNAME": fmt.Sprintf(`T%d`, i),
|
||||
"SALARY": gconv.Float64(i * 500),
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
}
|
||||
_, err := db.Insert(ctx, "t_user", data)
|
||||
@ -131,6 +134,7 @@ func TestDoInsert(t *testing.T) {
|
||||
"PASSPORT": fmt.Sprintf(`t%d`, i),
|
||||
"PASSWORD": fmt.Sprintf(`p%d`, i),
|
||||
"NICKNAME": fmt.Sprintf(`T%d`, i),
|
||||
"SALARY": gconv.Float64(i * 450),
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
}
|
||||
_, err := db.Save(ctx, "t_user", data, 10)
|
||||
@ -186,6 +190,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"PASSPORT": "t1",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "T1",
|
||||
"SALARY": 2551.15,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -196,6 +201,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"SALARY": "2552.25",
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -204,11 +210,12 @@ func Test_DB_Insert(t *testing.T) {
|
||||
|
||||
// struct
|
||||
type User struct {
|
||||
Id int `gconv:"ID"`
|
||||
Passport string `json:"PASSPORT"`
|
||||
Password string `gconv:"PASSWORD"`
|
||||
Nickname string `gconv:"NICKNAME"`
|
||||
CreateTime string `json:"CREATE_TIME"`
|
||||
Id int `gconv:"ID"`
|
||||
Passport string `json:"PASSPORT"`
|
||||
Password string `gconv:"PASSWORD"`
|
||||
Nickname string `gconv:"NICKNAME"`
|
||||
Salary float64 `gconv:"SALARY"`
|
||||
CreateTime string `json:"CREATE_TIME"`
|
||||
}
|
||||
timeStr := gtime.Now().String()
|
||||
result, err = db.Insert(ctx, table, User{
|
||||
@ -216,6 +223,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
Passport: "user_3",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_3",
|
||||
Salary: 2553.35,
|
||||
CreateTime: timeStr,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -229,6 +237,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), "user_3")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "name_3")
|
||||
t.Assert(one["SALARY"].Float64(), 2553.35)
|
||||
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
|
||||
|
||||
// *struct
|
||||
@ -238,6 +247,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
Passport: "t4",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_4",
|
||||
Salary: 2554.35,
|
||||
CreateTime: timeStr,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -250,6 +260,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), "t4")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "name_4")
|
||||
t.Assert(one["SALARY"].Float64(), 2554.35)
|
||||
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
|
||||
|
||||
// batch with Insert
|
||||
@ -260,6 +271,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"PASSPORT": "t200",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d71qw07ad",
|
||||
"NICKNAME": "T200",
|
||||
"SALARY": 2556.35,
|
||||
"CREATE_TIME": timeStr,
|
||||
},
|
||||
g.Map{
|
||||
@ -267,6 +279,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"PASSPORT": "t300",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "T300",
|
||||
"SALARY": 2557.35,
|
||||
"CREATE_TIME": timeStr,
|
||||
},
|
||||
})
|
||||
@ -280,6 +293,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), "t200")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d71qw07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "T200")
|
||||
t.Assert(one["SALARY"].Float64(), 2556.35)
|
||||
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
|
||||
})
|
||||
}
|
||||
@ -294,6 +308,7 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"SALARY": 2652.35,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
{
|
||||
@ -301,6 +316,7 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
"PASSPORT": "user_3",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_3",
|
||||
"SALARY": 2653.35,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
}, 1)
|
||||
@ -320,6 +336,7 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"SALARY": 2652.35,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
g.Map{
|
||||
@ -327,6 +344,7 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
"PASSPORT": "user_3",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_3",
|
||||
"SALARY": 2653.35,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
}, 1)
|
||||
@ -344,6 +362,7 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
"PASSPORT": "t1",
|
||||
"PASSWORD": "p1",
|
||||
"NICKNAME": "T1",
|
||||
"SALARY": 2765.35,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -363,6 +382,7 @@ func Test_DB_BatchInsert_Struct(t *testing.T) {
|
||||
Passport string `c:"PASSPORT"`
|
||||
Password string `c:"PASSWORD"`
|
||||
NickName string `c:"NICKNAME"`
|
||||
Salary float64 `c:"SALARY"`
|
||||
CreateTime *gtime.Time `c:"CREATE_TIME"`
|
||||
}
|
||||
user := &User{
|
||||
@ -370,6 +390,7 @@ func Test_DB_BatchInsert_Struct(t *testing.T) {
|
||||
Passport: "t1",
|
||||
Password: "p1",
|
||||
NickName: "T1",
|
||||
Salary: 2761.35,
|
||||
CreateTime: gtime.Now(),
|
||||
}
|
||||
result, err := db.Insert(ctx, table, user)
|
||||
@ -386,6 +407,9 @@ func Test_DB_Update(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Update(ctx, table, "password='987654321'", "id=3")
|
||||
t.AssertNil(err)
|
||||
|
||||
result, err = db.Update(ctx, table, "salary=2675.13", "id=3")
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
@ -395,6 +419,7 @@ func Test_DB_Update(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), "user_3")
|
||||
t.Assert(strings.TrimSpace(one["PASSWORD"].String()), "987654321")
|
||||
t.Assert(one["NICKNAME"].String(), "name_3")
|
||||
t.Assert(one["SALARY"].String(), "2675.13")
|
||||
})
|
||||
}
|
||||
|
||||
@ -487,6 +512,7 @@ func Test_DB_GetStruct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -500,6 +526,7 @@ func Test_DB_GetStruct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -518,6 +545,7 @@ func Test_DB_GetStructs(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var users []User
|
||||
@ -538,6 +566,7 @@ func Test_DB_GetStructs(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var users []User
|
||||
@ -562,6 +591,7 @@ func Test_DB_GetScan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -575,6 +605,7 @@ func Test_DB_GetScan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var user *User
|
||||
@ -588,6 +619,7 @@ func Test_DB_GetScan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -602,6 +634,7 @@ func Test_DB_GetScan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var users []User
|
||||
@ -622,6 +655,7 @@ func Test_DB_GetScan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var users []User
|
||||
|
||||
@ -171,6 +171,7 @@ func Test_Model_Insert(t *testing.T) {
|
||||
"PASSPORT": "t1",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_1",
|
||||
"SALARY": 2675.11,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
}).Insert()
|
||||
t.AssertNil(err)
|
||||
@ -181,6 +182,7 @@ func Test_Model_Insert(t *testing.T) {
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"SALARY": 2675.12,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
}).Insert()
|
||||
t.AssertNil(err)
|
||||
@ -191,6 +193,7 @@ func Test_Model_Insert(t *testing.T) {
|
||||
Passport string `json:"PASSPORT"`
|
||||
Password string `gconv:"PASSWORD"`
|
||||
Nickname string `gconv:"NICKNAME"`
|
||||
Salary float64 `gconv:"SALARY"`
|
||||
CreateTime *gtime.Time `json:"CREATE_TIME"`
|
||||
}
|
||||
// Model inserting.
|
||||
@ -200,6 +203,7 @@ func Test_Model_Insert(t *testing.T) {
|
||||
Passport: "t3",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_3",
|
||||
Salary: 2675.13,
|
||||
CreateTime: gtime.Now(),
|
||||
}).Insert()
|
||||
t.AssertNil(err)
|
||||
@ -214,6 +218,7 @@ func Test_Model_Insert(t *testing.T) {
|
||||
Passport: "t4",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "T4",
|
||||
Salary: 2675.14,
|
||||
CreateTime: gtime.Now(),
|
||||
}).Insert()
|
||||
t.AssertNil(err)
|
||||
@ -238,6 +243,7 @@ func Test_Model_Insert_Time(t *testing.T) {
|
||||
"PASSPORT": "t1",
|
||||
"PASSWORD": "p1",
|
||||
"NICKNAME": "n1",
|
||||
"SALARY": 2675.11,
|
||||
"CREATE_TIME": "2020-10-10 20:09:18",
|
||||
}
|
||||
_, err := db.Model(table).Data(data).Insert()
|
||||
@ -248,6 +254,7 @@ func Test_Model_Insert_Time(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), data["PASSPORT"])
|
||||
t.Assert(one["CREATE_TIME"].String(), "2020-10-10 20:09:18")
|
||||
t.Assert(one["NICKNAME"].String(), data["NICKNAME"])
|
||||
t.Assert(one["SALARY"].Float64(), data["SALARY"])
|
||||
})
|
||||
}
|
||||
|
||||
@ -263,6 +270,7 @@ func Test_Model_Batch(t *testing.T) {
|
||||
"PASSPORT": "t2",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_2",
|
||||
"SALARY": 2675.12,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
{
|
||||
@ -271,6 +279,7 @@ func Test_Model_Batch(t *testing.T) {
|
||||
"PASSPORT": "t3",
|
||||
"PASSWORD": "25d55ad283aa400af464c76d713c07ad",
|
||||
"NICKNAME": "name_3",
|
||||
"SALARY": 2675.13,
|
||||
"CREATE_TIME": gtime.Now().String(),
|
||||
},
|
||||
}).Batch(1).Insert()
|
||||
@ -439,6 +448,7 @@ func Test_Model_Select(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -458,6 +468,7 @@ func Test_Model_Struct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -471,6 +482,7 @@ func Test_Model_Struct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -485,6 +497,7 @@ func Test_Model_Struct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := (*User)(nil)
|
||||
@ -499,6 +512,7 @@ func Test_Model_Struct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := (*User)(nil)
|
||||
@ -515,6 +529,7 @@ func Test_Model_Struct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -527,6 +542,7 @@ func Test_Model_Struct(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var user *User
|
||||
@ -545,6 +561,7 @@ func Test_Model_Scan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -558,6 +575,7 @@ func Test_Model_Scan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
user := new(User)
|
||||
@ -571,6 +589,7 @@ func Test_Model_Scan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
var users []User
|
||||
@ -590,6 +609,7 @@ func Test_Model_Scan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var users []*User
|
||||
@ -610,6 +630,7 @@ func Test_Model_Scan(t *testing.T) {
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
Salary float64
|
||||
CreateTime *gtime.Time
|
||||
}
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user