__dw_unlockfile(db);
}
-struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db* db, void** fields, const char* prop) {
+struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db* db, void** fields) {
struct dataworks_db_result* r = malloc(sizeof(*r));
r->error = false;
int i;
}
free(dbi);
char* types = dataworks_database_get_table_field_types(db, db->name);
- for(i = 0; prop[i] != 0; i++)
- ;
- if(strlen(types) != i) {
- r->error = true;
- r->errnum = DW_ERR_EXEC_INSUFFICIENT_ARGUMENTS;
- return r;
- }
__dw_lockfile(db);
uint64_t count = dataworks_database_get_table_count(db, db->name);
- for(i = 0; prop[i] != 0; i++) {
+ for(i = 0; fields[i] != NULL; i++) {
uint64_t entsize = 0;
if(types[i] == DW_RECORD_STRING) {
entsize = strlen(fields[i]);
} else if(types[i] == DW_RECORD_HELP) {
entsize = strlen(fields[i]);
}
- __dw_add_record(db, count, dbindex, i, fields[i], entsize, prop[i] == 'S');
+ __dw_add_record(db, count, dbindex, i, fields[i], entsize, 1);
}
dataworks_database_set_table_count(db, db->name, count + 1);
__dw_unlockfile(db);
* @brief String
*
*/
- DW_RECORD_STRING = 'C',
+ DW_RECORD_STRING = 'S',
/**
* @~english
* @~english
* @brief Inserts the record.
* @param db Database
- * @param records Records
- * @param prop List which contains character `U` or `S`
- * - `U` indicates the field is unset
- * - `S` indicates the field is set
+ * @param fields Fields
* @return Result
*
*/
-struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db* db, void** records, const char* prop);
+struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db* db, void** records);
/**
* @~english
void __dw_free_node(struct Node* node);
void __dw_free_node2(struct Node* node, bool top);
bool __dw_print_node(struct Node* node, bool top);
+char __dw_get_node_type(struct Node* node);
#ifdef __cplusplus
}
} else if(i > count) {
newnode->errnum = DW_ERR_EXEC_TOO_MANY_ARGUMENTS;
} else {
+ char* typ = dataworks_database_get_table_field_types(db, dataworks_database_get_using_table(db));
struct Node** arr = malloc(sizeof(*arr) * (i + 1));
for(i = 0; node->nodes[i] != NULL; i++) {
struct Node* r = parser_process(db, node->nodes[i], false);
+ char t = __dw_get_node_type(r);
+ if(!(
+ (typ[i] == 'F' || typ[i] == 'I') && t == 'N'
+ || typ[i] == t
+ )){
+ newnode->errnum = DW_ERR_EXEC_TYPE_MISMATCH;
+ }
arr[i] = r;
}
arr[i] = NULL;
+ if(newnode->errnum == DW_ERR_SUCCESS){
+ void** fields = malloc(sizeof(*fields) * (i + 1));
+ fields[i] = NULL;
+ int k;
+ for(k = 0; k < i; k++){
+ if(typ[k] == DW_RECORD_STRING){
+ fields[k] = __dw_strdup(arr[k]->string);
+ }else if(typ[k] == DW_RECORD_LOGICAL){
+ fields[k] = malloc(1);
+ *(char*)fields[k] = arr[k]->logical;
+ }else if(typ[k] == DW_RECORD_FLOATING){
+ fields[k] = malloc(sizeof(double));
+ *(double*)fields[k] = arr[k]->number;
+ }else if(typ[k] == DW_RECORD_INTEGER){
+ fields[k] = malloc(8);
+ *(uint64_t*)fields[k] = arr[k]->number;
+ }
+ }
+ struct dataworks_db_result* insr = dataworks_database_insert_record(db, fields);
+
+ free(fields);
+ }
+
for(i = 0; arr[i] != NULL; i++) {
__dw_free_node(arr[i]);
}
+ free(typ);
free(arr);
}
} else if(!used) {
if(!top) free(node);
}
+char __dw_get_node_type(struct Node* node){
+ if(node->type == 'N' || node->type == 'L'){
+ return node->type;
+ }else if(node->string != NULL){
+ return 'S';
+ }
+ return 0;
+}
+
bool __dw_print_node(struct Node* node, bool top) {
if(node->type == 'N') {
printf("%f", node->number);