@@ -78,23 +78,57 @@ func TestSkipQuoteIdentifiers(t *testing.T) {
78
78
t .Errorf ("Failed to get column: name" )
79
79
}
80
80
81
+ student := Student {ID : 1 , Name : "John" }
82
+ if err := db .Model (& Student {}).Create (& student ).Error ; err != nil {
83
+ t .Errorf ("Failed to insert student, got %v" , err )
84
+ }
85
+
86
+ var result Student
87
+ if err := db .First (& result ).Error ; err != nil {
88
+ t .Errorf ("Failed to query first student, got %v" , err )
89
+ }
90
+
91
+ if result .ID != student .ID {
92
+ t .Errorf ("id should be %v, but got %v" , student .ID , result .ID )
93
+ }
94
+
95
+ if result .Name != student .Name {
96
+ t .Errorf ("name should be %v, but got %v" , student .Name , result .Name )
97
+ }
98
+ }
99
+
100
+ func TestSkipQuoteIdentifiersSQL (t * testing.T ) {
101
+ db , err := openTestDBWithOptions (
102
+ & oracle.Config {SkipQuoteIdentifiers : true },
103
+ & gorm.Config {Logger : newLogger })
104
+ if err != nil {
105
+ t .Fatalf ("failed to connect database, got error %v" , err )
106
+ }
81
107
dryrunDB := db .Session (& gorm.Session {DryRun : true })
82
108
83
- result := dryrunDB .Model (& Student {}).Create (& Student {ID : 1 , Name : "John" })
109
+ insertedStudent := Student {ID : 1 , Name : "John" }
110
+ result := dryrunDB .Model (& Student {}).Create (& insertedStudent )
111
+
84
112
if ! regexp .MustCompile (`^INSERT INTO STUDENTS \(name,id\) VALUES \(:1,:2\)$` ).MatchString (result .Statement .SQL .String ()) {
85
113
t .Errorf ("invalid insert SQL, got %v" , result .Statement .SQL .String ())
86
114
}
87
115
88
- result = dryrunDB .First (& Student {})
116
+ // Test First
117
+ var firstStudent Student
118
+ result = dryrunDB .First (& firstStudent )
119
+
89
120
if ! regexp .MustCompile (`^SELECT \* FROM STUDENTS ORDER BY STUDENTS\.id FETCH NEXT 1 ROW ONLY$` ).MatchString (result .Statement .SQL .String ()) {
90
121
t .Fatalf ("SQL should include selected names, but got %v" , result .Statement .SQL .String ())
91
122
}
92
123
93
- result = dryrunDB .Find (& Student {ID : 1 , Name : "John" })
94
- if ! regexp .MustCompile (`^SELECT \* FROM STUDENTS WHERE STUDENTS\.id = :1$` ).MatchString (result .Statement .SQL .String ()) {
124
+ // Test Find
125
+ var foundStudent Student
126
+ result = dryrunDB .Find (foundStudent , "id = ?" , insertedStudent .ID )
127
+ if ! regexp .MustCompile (`^SELECT \* FROM STUDENTS WHERE id = :1$` ).MatchString (result .Statement .SQL .String ()) {
95
128
t .Fatalf ("SQL should include selected names, but got %v" , result .Statement .SQL .String ())
96
129
}
97
130
131
+ // Test Save
98
132
result = dryrunDB .Save (& Student {ID : 2 , Name : "Mary" })
99
133
if ! regexp .MustCompile (`^UPDATE STUDENTS SET name=:1 WHERE id = :2$` ).MatchString (result .Statement .SQL .String ()) {
100
134
t .Fatalf ("SQL should include selected names, but got %v" , result .Statement .SQL .String ())
0 commit comments