Added auto-increment ID column
This commit is contained in:
@@ -28,3 +28,5 @@ TYPE_STRING <- bitwShiftL(1, 11)
|
||||
TYPE_BLOB <- bitwShiftL(1, 12)
|
||||
#' @export
|
||||
TYPE_TIMESTAMP <- bitwShiftL(1, 13)
|
||||
#' @export
|
||||
TYPE_ID <- bitwShiftL(1, 14)
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -43,6 +44,7 @@ struct column_data_t {
|
||||
uint8_t isNullable :1;
|
||||
uint8_t isBlob :1;
|
||||
uint8_t isTimestamp :1;
|
||||
uint8_t isAutoIncrement :1;
|
||||
|
||||
union {
|
||||
void *vptr;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user