Skip to content

Commit

Permalink
db.mysql: fix the support for TIMESTAMP columns (#18704)
Browse files Browse the repository at this point in the history
  • Loading branch information
walkingdevel committed Jun 29, 2023
1 parent f0fb86f commit 7ee2584
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions vlib/db/mysql/orm.v
Expand Up @@ -39,7 +39,7 @@ pub fn (db DB) @select(config orm.SelectConfig, data orm.QueryData, where orm.Qu
.type_longlong, .type_double {
data_pointers << unsafe { malloc(8) }
}
.type_time, .type_date, .type_datetime, .type_time2, .type_datetime2 {
.type_time, .type_date, .type_datetime, .type_time2, .type_datetime2, .type_timestamp {
data_pointers << unsafe { malloc(sizeof(C.MYSQL_TIME)) }
}
.type_string, .type_var_string, .type_blob, .type_tiny_blob, .type_medium_blob,
Expand Down Expand Up @@ -80,7 +80,7 @@ pub fn (db DB) @select(config orm.SelectConfig, data orm.QueryData, where orm.Qu
.type_long {
mysql_bind.buffer_type = C.MYSQL_TYPE_LONG
}
.type_time, .type_date, .type_datetime {
.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()
Expand Down Expand Up @@ -303,7 +303,7 @@ fn data_pointers_to_primitives(data_pointers []&u8, types []int, field_types []F
timestamp := *(unsafe { &int(data) })
primitive = time.unix(timestamp)
}
.type_datetime {
.type_datetime, .type_timestamp {
string_time := unsafe { cstring_to_vstring(&char(data)) }
primitive = time.parse(string_time)!
}
Expand Down Expand Up @@ -366,7 +366,7 @@ fn (db DB) convert_query_data_to_primitives(table string, data orm.QueryData) ![

for i, field in data.fields {
if data.data[i].type_name() == 'time.Time' {
if column_type_map[field] == 'datetime' {
if column_type_map[field] in ['datetime', 'timestamp'] {
converted_data << orm.Primitive((data.data[i] as time.Time).str())
} else {
converted_data << data.data[i]
Expand Down

0 comments on commit 7ee2584

Please sign in to comment.