db.mysql: use mysql datatype for alloc string_binds_map, not orm's (#24126)

This commit is contained in:
kbkpbot 2025-04-03 22:01:29 +08:00 committed by GitHub
parent 567a7d9d67
commit 01a954310e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 22 deletions

View File

@ -203,10 +203,9 @@ fn test_mysql_orm() {
}!
assert results[0].created_at == model.created_at
// TODO: investigate why these fail with V 0.4.0 11a8a46 , and fix them:
// assert results[0].username == model.username
// assert results[0].updated_at == model.updated_at
// assert results[0].deleted_at == model.deleted_at
assert results[0].username == model.username
assert results[0].updated_at == model.updated_at
assert results[0].deleted_at == model.deleted_at
/** test default attribute
*/

View File

@ -21,7 +21,7 @@ pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.Que
metadata := stmt.gen_metadata()
fields := stmt.fetch_fields(metadata)
num_fields := stmt.get_field_count()
mut data_pointers := []&u8{}
mut data_pointers := []&u8{cap: int(num_fields)}
// Allocate memory for each column.
for i in 0 .. num_fields {
@ -71,25 +71,18 @@ pub fn (db DB) select(config orm.SelectConfig, data orm.QueryData, where orm.Que
field_type := unsafe { FieldType(field.type) }
field_types << field_type
match types[i] {
orm.type_string {
match field_type {
.type_string, .type_var_string, .type_blob, .type_tiny_blob, .type_medium_blob,
.type_long_blob {
string_binds_map[i] = mysql_bind
}
orm.time_ {
match field_type {
.type_long {
mysql_bind.buffer_type = C.MYSQL_TYPE_LONG
}
.type_time, .type_date, .type_datetime, .type_timestamp {
// FIXME: Allocate memory for blobs dynamically.
mysql_bind.buffer_type = C.MYSQL_TYPE_BLOB
mysql_bind.buffer_length = FieldType.type_blob.get_len()
}
.type_string, .type_blob {}
else {
return error('Unknown type ${field.type}')
}
}
.type_long {
mysql_bind.buffer_type = C.MYSQL_TYPE_LONG
}
.type_time, .type_date, .type_datetime, .type_timestamp {
// FIXME: Allocate memory for blobs dynamically.
mysql_bind.buffer_type = C.MYSQL_TYPE_BLOB
mysql_bind.buffer_length = FieldType.type_blob.get_len()
}
else {}
}