Skip to content

Commit 01a9543

Browse files
authored
db.mysql: use mysql datatype for alloc string_binds_map, not orm's (#24126)
1 parent 567a7d9 commit 01a9543

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

vlib/db/mysql/mysql_orm_test.v

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ fn test_mysql_orm() {
203203
}!
204204

205205
assert results[0].created_at == model.created_at
206-
// TODO: investigate why these fail with V 0.4.0 11a8a46 , and fix them:
207-
// assert results[0].username == model.username
208-
// assert results[0].updated_at == model.updated_at
209-
// assert results[0].deleted_at == model.deleted_at
206+
assert results[0].username == model.username
207+
assert results[0].updated_at == model.updated_at
208+
assert results[0].deleted_at == model.deleted_at
210209

211210
/** test default attribute
212211
*/

vlib/db/mysql/orm.c.v

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.Que
2121
metadata := stmt.gen_metadata()
2222
fields := stmt.fetch_fields(metadata)
2323
num_fields := stmt.get_field_count()
24-
mut data_pointers := []&u8{}
24+
mut data_pointers := []&u8{cap: int(num_fields)}
2525

2626
// Allocate memory for each column.
2727
for i in 0 .. num_fields {
@@ -71,25 +71,18 @@ pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.Que
7171
field_type := unsafe { FieldType(field.type) }
7272
field_types << field_type
7373

74-
match types[i] {
75-
orm.type_string {
74+
match field_type {
75+
.type_string, .type_var_string, .type_blob, .type_tiny_blob, .type_medium_blob,
76+
.type_long_blob {
7677
string_binds_map[i] = mysql_bind
7778
}
78-
orm.time_ {
79-
match field_type {
80-
.type_long {
81-
mysql_bind.buffer_type = C.MYSQL_TYPE_LONG
82-
}
83-
.type_time, .type_date, .type_datetime, .type_timestamp {
84-
// FIXME: Allocate memory for blobs dynamically.
85-
mysql_bind.buffer_type = C.MYSQL_TYPE_BLOB
86-
mysql_bind.buffer_length = FieldType.type_blob.get_len()
87-
}
88-
.type_string, .type_blob {}
89-
else {
90-
return error('Unknown type ${field.type}')
91-
}
92-
}
79+
.type_long {
80+
mysql_bind.buffer_type = C.MYSQL_TYPE_LONG
81+
}
82+
.type_time, .type_date, .type_datetime, .type_timestamp {
83+
// FIXME: Allocate memory for blobs dynamically.
84+
mysql_bind.buffer_type = C.MYSQL_TYPE_BLOB
85+
mysql_bind.buffer_length = FieldType.type_blob.get_len()
9386
}
9487
else {}
9588
}

0 commit comments

Comments
 (0)