@@ -136,6 +136,43 @@ func TestQueryContextInitialization(t *testing.T) {
136
136
require .NoError (t , conn .Close ())
137
137
}
138
138
139
+ // TestTypes asserts that various MySQL types are returned as the expected Go type by the driver.
140
+ func TestTypes (t * testing.T ) {
141
+ conn , cleanupFunc := initializeTestDatabaseConnection (t , false )
142
+ defer cleanupFunc ()
143
+
144
+ ctx := context .Background ()
145
+ _ , err := conn .ExecContext (ctx , `
146
+ create table testtable (
147
+ enum_col ENUM('a', 'b', 'c'),
148
+ set_col SET('a', 'b', 'c'),
149
+ json_col JSON,
150
+ blob_col BLOB,
151
+ text_col TEXT,
152
+ geom_col POINT,
153
+ date_col DATETIME
154
+ );
155
+
156
+ insert into testtable values ('b', 'a,c', '{"key": 42}', 'data', 'text', Point(5, -5), NOW());
157
+ ` )
158
+ require .NoError (t , err )
159
+
160
+ row := conn .QueryRowContext (ctx , "select * from testtable" )
161
+ vals := make ([]any , 7 )
162
+ ptrs := make ([]any , 7 )
163
+ for i := range vals {
164
+ ptrs [i ] = & vals [i ]
165
+ }
166
+ require .NoError (t , row .Scan (ptrs ... ))
167
+ require .Equal (t , "b" , vals [0 ])
168
+ require .Equal (t , "a,c" , vals [1 ])
169
+ require .Equal (t , `{"key": 42}` , vals [2 ])
170
+ require .Equal (t , []byte (`data` ), vals [3 ])
171
+ require .Equal (t , "text" , vals [4 ])
172
+ require .IsType (t , []byte (nil ), vals [5 ])
173
+ require .IsType (t , time.Time {}, vals [6 ])
174
+ }
175
+
139
176
// initializeTestDatabaseConnection create a test database called testdb and initialize a database/sql connection
140
177
// using the Dolt driver. The connection, |conn|, is returned, and |cleanupFunc| is a function that the test function
141
178
// should defer in order to properly dispose of test resources.
0 commit comments