Added auto-increment ID column
This commit is contained in:
@@ -27,4 +27,6 @@ TYPE_STRING <- bitwShiftL(1, 11)
|
|||||||
#' @export
|
#' @export
|
||||||
TYPE_BLOB <- bitwShiftL(1, 12)
|
TYPE_BLOB <- bitwShiftL(1, 12)
|
||||||
#' @export
|
#' @export
|
||||||
TYPE_TIMESTAMP <- bitwShiftL(1, 13)
|
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:
|
case TYPE_TIMESTAMP:
|
||||||
return sizeof(uint32_t);
|
return sizeof(uint32_t);
|
||||||
|
|
||||||
|
case TYPE_ID:
|
||||||
|
return sizeof(uint32_t);
|
||||||
|
|
||||||
case TYPE_RAW:
|
case TYPE_RAW:
|
||||||
return sizeof(char *);
|
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->isNullable = nullable > 0;
|
||||||
col->isBlob = type == TYPE_BLOB;
|
col->isBlob = type == TYPE_BLOB;
|
||||||
col->isTimestamp = type == TYPE_TIMESTAMP;
|
col->isTimestamp = type == TYPE_TIMESTAMP;
|
||||||
|
col->isAutoIncrement = type == TYPE_ID;
|
||||||
|
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
@@ -182,6 +186,8 @@ struct column_data_t *columnFromResult(struct stored_conn_t *sconn, MYSQL_RES *r
|
|||||||
field->table,
|
field->table,
|
||||||
field->table_length
|
field->table_length
|
||||||
);
|
);
|
||||||
|
col->isAutoIncrement = (field->flags & AUTO_INCREMENT_FLAG) != 0;
|
||||||
|
col->isTimestamp = (field->flags & TIMESTAMP_FLAG) != 0;
|
||||||
|
|
||||||
if (col == 0 || num_rows == 0) {
|
if (col == 0 || num_rows == 0) {
|
||||||
return col;
|
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);
|
*(col->data.ptr_uint32 + row) = (uint32_t)strtoul(value, NULL, 10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TYPE_ID:
|
||||||
|
{
|
||||||
|
*(col->data.ptr_uint32 + row) = (uint32_t)strtoul(value, NULL, 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
case TYPE_BLOB:
|
case TYPE_BLOB:
|
||||||
case TYPE_RAW:
|
case TYPE_RAW:
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ enum e_column_type_t {
|
|||||||
TYPE_DOUBLE = 1 << 10,
|
TYPE_DOUBLE = 1 << 10,
|
||||||
TYPE_STRING = 1 << 11,
|
TYPE_STRING = 1 << 11,
|
||||||
TYPE_BLOB = 1 << 12,
|
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;
|
typedef enum e_column_type_t e_column_type;
|
||||||
|
|
||||||
@@ -38,11 +39,12 @@ struct column_data_t {
|
|||||||
|
|
||||||
size_t n_values;
|
size_t n_values;
|
||||||
|
|
||||||
uint8_t hasPointers :1;
|
uint8_t hasPointers :1;
|
||||||
uint8_t isUnsigned :1;
|
uint8_t isUnsigned :1;
|
||||||
uint8_t isNullable :1;
|
uint8_t isNullable :1;
|
||||||
uint8_t isBlob :1;
|
uint8_t isBlob :1;
|
||||||
uint8_t isTimestamp :1;
|
uint8_t isTimestamp :1;
|
||||||
|
uint8_t isAutoIncrement :1;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
void *vptr;
|
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);
|
nchar = vsprintf(buf, "%"PRIi32, args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TYPE_ID:
|
||||||
case TYPE_TIMESTAMP:
|
case TYPE_TIMESTAMP:
|
||||||
case TYPE_UINT32:
|
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:
|
default:
|
||||||
{
|
{
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strbld_str(sb, buf, (size_t)nchar);
|
strbld_str(sb, buf, (size_t)nchar);
|
||||||
|
|||||||
@@ -268,6 +268,10 @@ char *createColString(struct column_data_t *col)
|
|||||||
break;
|
break;
|
||||||
case TYPE_TIMESTAMP:
|
case TYPE_TIMESTAMP:
|
||||||
strbld_str(sb, "TIMESTAMP", 8);
|
strbld_str(sb, "TIMESTAMP", 8);
|
||||||
|
break;
|
||||||
|
case TYPE_ID:
|
||||||
|
strbld_str(sb, "INT", 3);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (col->isUnsigned) {
|
if (col->isUnsigned) {
|
||||||
@@ -280,6 +284,10 @@ char *createColString(struct column_data_t *col)
|
|||||||
strbld_str(sb, " NOT NULL", 0);
|
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) {
|
if (strbld_finalize_or_destroy(&sb, &colstr, &colstr_len) != 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user