From 23c8a2f109f47aa97bfb760331196f63ea6ece31 Mon Sep 17 00:00:00 2001 From: nishi Date: Tue, 2 Jul 2024 11:46:48 +0000 Subject: [PATCH] fix insert error git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@449 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- Library/exec.c | 94 ++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/Library/exec.c b/Library/exec.c index d07b919..66c46f6 100644 --- a/Library/exec.c +++ b/Library/exec.c @@ -200,60 +200,64 @@ struct Node* parser_process(struct dataworks_db* db, struct Node* node, bool dol newnode->errnum = DW_ERR_EXEC_INSUFFICIENT_ARGUMENTS; } } else if(__dw_strcaseequ(node->ident, "insert")) { - for(i = 0; node->nodes[i] != NULL; i++) - ; + if(dataworks_database_get_using_table(db) == NULL) { + newnode->errnum = DW_ERR_DATABASE_NOT_SELECTED; + } else { + for(i = 0; node->nodes[i] != NULL; i++) + ; - char** list = dataworks_database_get_table_fields(db, dataworks_database_get_using_table(db)); + char** list = dataworks_database_get_table_fields(db, dataworks_database_get_using_table(db)); - int count; - for(count = 0; list[count] != NULL; count++) free(list[count]); - free(list); + int count; + for(count = 0; list[count] != NULL; count++) free(list[count]); + free(list); - if(i < count) { - newnode->errnum = DW_ERR_EXEC_INSUFFICIENT_ARGUMENTS; - } 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; + if(i < count) { + newnode->errnum = DW_ERR_EXEC_INSUFFICIENT_ARGUMENTS; + } 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] = r; - } - arr[i] = NULL; + 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; + 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); + struct dataworks_db_result* insr = dataworks_database_insert_record(db, fields); - free(fields); - } + free(fields); + } - for(i = 0; arr[i] != NULL; i++) { - __dw_free_node(arr[i]); + for(i = 0; arr[i] != NULL; i++) { + __dw_free_node(arr[i]); + } + free(typ); + free(arr); } - free(typ); - free(arr); } } else if(!used) { newnode->errnum = DW_ERR_EXEC_UNKNOWN_METHOD; -- 2.43.0