diff --git a/R/Defines.R b/R/Defines.R index cf9b0bd..0164250 100644 --- a/R/Defines.R +++ b/R/Defines.R @@ -27,4 +27,6 @@ TYPE_STRING <- bitwShiftL(1, 11) #' @export TYPE_BLOB <- bitwShiftL(1, 12) #' @export -TYPE_TIMESTAMP <- bitwShiftL(1, 13) \ No newline at end of file +TYPE_TIMESTAMP <- bitwShiftL(1, 13) +#' @export +TYPE_ID <- bitwShiftL(1, 14) \ No newline at end of file diff --git a/src/db_column.c b/src/db_column.c index 57eeca4..160f17a 100644 --- a/src/db_column.c +++ b/src/db_column.c @@ -43,6 +43,9 @@ size_t columnTypeToByteSize(e_column_type type) case TYPE_TIMESTAMP: return sizeof(uint32_t); + case TYPE_ID: + return sizeof(uint32_t); + case TYPE_RAW: return sizeof(char *); } @@ -155,6 +158,7 @@ struct column_data_t *initEmptyColumn(e_column_type type, int nullable, const ch col->isNullable = nullable > 0; col->isBlob = type == TYPE_BLOB; col->isTimestamp = type == TYPE_TIMESTAMP; + col->isAutoIncrement = type == TYPE_ID; return col; } @@ -182,6 +186,8 @@ struct column_data_t *columnFromResult(struct stored_conn_t *sconn, MYSQL_RES *r field->table, field->table_length ); + col->isAutoIncrement = (field->flags & AUTO_INCREMENT_FLAG) != 0; + col->isTimestamp = (field->flags & TIMESTAMP_FLAG) != 0; if (col == 0 || num_rows == 0) { return col; @@ -344,6 +350,13 @@ int setColumnValue(struct column_data_t *col, uint64_t row, const char *value, s *(col->data.ptr_uint32 + row) = (uint32_t)strtoul(value, NULL, 10); break; } + + case TYPE_ID: + { + *(col->data.ptr_uint32 + row) = (uint32_t)strtoul(value, NULL, 10); + break; + } + case TYPE_STRING: case TYPE_BLOB: case TYPE_RAW: diff --git a/src/db_column.h b/src/db_column.h index 54bd8b1..b8d6868 100644 --- a/src/db_column.h +++ b/src/db_column.h @@ -22,7 +22,8 @@ enum e_column_type_t { TYPE_DOUBLE = 1 << 10, TYPE_STRING = 1 << 11, TYPE_BLOB = 1 << 12, - TYPE_TIMESTAMP = 1 << 13 + TYPE_TIMESTAMP = 1 << 13, + TYPE_ID = 1 << 14 }; typedef enum e_column_type_t e_column_type; @@ -38,11 +39,12 @@ struct column_data_t { size_t n_values; - uint8_t hasPointers :1; - uint8_t isUnsigned :1; - uint8_t isNullable :1; - uint8_t isBlob :1; - uint8_t isTimestamp :1; + uint8_t hasPointers :1; + uint8_t isUnsigned :1; + uint8_t isNullable :1; + uint8_t isBlob :1; + uint8_t isTimestamp :1; + uint8_t isAutoIncrement :1; union { void *vptr; diff --git a/src/db_value.c b/src/db_value.c index b867e73..59ca436 100644 --- a/src/db_value.c +++ b/src/db_value.c @@ -139,6 +139,7 @@ void db_value_sbva(str_builder *sb, e_column_type type, uint32_t n_args, va_list nchar = vsprintf(buf, "%"PRIi32, args); break; } + case TYPE_ID: case TYPE_TIMESTAMP: case TYPE_UINT32: { @@ -170,7 +171,7 @@ void db_value_sbva(str_builder *sb, e_column_type type, uint32_t n_args, va_list default: { - break; + return; } } strbld_str(sb, buf, (size_t)nchar); diff --git a/src/modb_manage_p.c b/src/modb_manage_p.c index e647ab9..a93c4ba 100644 --- a/src/modb_manage_p.c +++ b/src/modb_manage_p.c @@ -268,6 +268,10 @@ char *createColString(struct column_data_t *col) break; case TYPE_TIMESTAMP: strbld_str(sb, "TIMESTAMP", 8); + break; + case TYPE_ID: + strbld_str(sb, "INT", 3); + break; } if (col->isUnsigned) { @@ -280,6 +284,10 @@ char *createColString(struct column_data_t *col) strbld_str(sb, " NOT NULL", 0); } + if (col->isAutoIncrement) { + strbld_str(sb, " AUTO_INCREMENT", 0); + } + if (strbld_finalize_or_destroy(&sb, &colstr, &colstr_len) != 0) { return 0; }