]> Nishi Git Mirror - dataworks.git/commitdiff
insert works
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 26 Jun 2024 02:42:12 +0000 (02:42 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Wed, 26 Jun 2024 02:42:12 +0000 (02:42 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@438 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Library/database_record.c
Library/dw_database.h
Library/dw_parser.h
Library/exec.c
Library/parser.c

index 22efac4a7ed7db4b4cccffe45173e70d03dce42c..bfe775afd5561549d8fc4a7f382197b62f1500c8 100644 (file)
@@ -96,7 +96,7 @@ void __dw_add_record(struct dataworks_db* db, uint64_t count, uint64_t dbindex,
        __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;
@@ -112,16 +112,9 @@ struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db
        }
        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]);
@@ -134,7 +127,7 @@ struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db
                } 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);
index 8effb4f7c4a7c17a139bf3935e5b98c9f2c4e13a..101b1640676879545b22880b60639df725b3e766 100644 (file)
@@ -193,7 +193,7 @@ enum DW_RECORD_TYPES {
         * @brief String
         *
         */
-       DW_RECORD_STRING = 'C',
+       DW_RECORD_STRING = 'S',
 
        /**
         * @~english
@@ -613,14 +613,11 @@ void dataworks_database_free_result(struct dataworks_db_result* result);
  * @~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
index 462137dae07882eff10a381c67957c3f1ca06e42..421fbc440eb593dc3af966f15e9f952c5ea8083c 100644 (file)
@@ -52,6 +52,7 @@ struct Node* __dw_duplicate_node(struct Node* node);
 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
 }
index 12a1afa6a0f637f7d02545f0cf892e767f5ad8db..d3281008370b269e3b67adc917be34ecec7af739 100644 (file)
@@ -195,16 +195,48 @@ struct Node* parser_process(struct dataworks_db* db, struct Node* node, bool dol
                        } 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) {
index 1b9bfc61794d8623744881362debaa7932c9df29..3444f199249e3cdc42bba6896c097012f9bd715b 100644 (file)
@@ -102,6 +102,15 @@ void __dw_free_node2(struct Node* node, bool top) {
        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);