]> Nishi Git Mirror - dataworks.git/commitdiff
trying to add insert
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Tue, 25 Jun 2024 16:05:12 +0000 (16:05 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Tue, 25 Jun 2024 16:05:12 +0000 (16:05 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@437 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Library/database.c
Library/dataworks.c
Library/dw_database.h
Library/exec.c
Package/PKGBUILD
Package/increment-PKGBUILD

index 83f26c2ad51944682fafc6957b7621a1a8322543..2ee5c7a276519acb36caab659ee71ff8348cd011 100644 (file)
@@ -41,7 +41,7 @@
 
 const char sig[3] = {0x7f, 'D', 'W'};
 
-const char* dw_errors[] = {"Success", "Used already", "File open fail", "Invalid signature", "Invalid version", "Parser returned NULL", "Cannot call non-method", "Unknown method", "Insufficient arguments", "Too many arguments", "Not used", "Too many tables", "Database not selected", "Parser fail"};
+const char* dw_errors[] = {"Success", "Used already", "File open fail", "Invalid signature", "Invalid version", "Parser returned NULL", "Cannot call non-method", "Unknown method", "Insufficient arguments", "Too many arguments", "Not used", "Too many tables", "Database not selected", "Parser fail", "Type mismatch"};
 
 #ifdef M_I86
 #define BUFSIZE 128
@@ -185,3 +185,5 @@ int dataworks_database_use_table(struct dataworks_db* db, const char* table) {
        }
        return errnum;
 }
+
+char* dataworks_database_get_using_table(struct dataworks_db* db) { return db->name; }
index 6258ae0f3f3ef19b9d60be8520bbcd762743022a..9d0d5bd9f91c39f013d17fc0f90c6d398f40cd04 100644 (file)
@@ -36,7 +36,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-const char* dataworks_version = "0.1.1";
+const char* dataworks_version = "0.1.2";
 const char* dataworks_compile_date = __DATE__;
 const char* dataworks_copyright = "Copyright (c) Crabware 2024\n"
                                  "              pnsk-lab 2024\n"
index 6dba8d8468b6ada476753dee0c9564300a271250..8effb4f7c4a7c17a139bf3935e5b98c9f2c4e13a 100644 (file)
@@ -173,6 +173,13 @@ enum DW_ERRORS {
         *
         */
        DW_ERR_PARSER_FAIL,
+
+       /**
+        * @~english
+        * @brief Type mispatch
+        *
+        */
+       DW_ERR_EXEC_TYPE_MISMATCH,
 };
 
 /**
@@ -645,6 +652,14 @@ uint64_t dataworks_database_get_table_count(struct dataworks_db* db, const char*
  */
 void dataworks_database_set_table_count(struct dataworks_db* db, const char* table, uint64_t count);
 
+/**
+ * @~english
+ * @brief Get the using table name.
+ * @param db Database
+ *
+ */
+char* dataworks_database_get_using_table(struct dataworks_db* db);
+
 #ifdef __cplusplus
 }
 #endif
index ae44b8796d252081e5c92ce3f62b6ba066d4edc8..12a1afa6a0f637f7d02545f0cf892e767f5ad8db 100644 (file)
@@ -59,7 +59,7 @@ struct Node* parser_process(struct dataworks_db* db, struct Node* node, bool dol
                        newnode->string = __dw_strdup(dataworks_get_version());
                        used = true;
                }
-               if(node->nodes != NULL) {
+               if(node->nodes != NULL && !__dw_strcaseequ(node->ident, "insert")) {
                        for(i = 0; node->nodes[i] != NULL; i++) {
                                struct Node* r = parser_process(db, node->nodes[i], false);
                                if(r->errnum != DW_ERR_SUCCESS) {
@@ -181,6 +181,32 @@ 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++)
+                               ;
+
+                       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);
+
+                       if(i < count) {
+                               newnode->errnum = DW_ERR_EXEC_INSUFFICIENT_ARGUMENTS;
+                       } else if(i > count) {
+                               newnode->errnum = DW_ERR_EXEC_TOO_MANY_ARGUMENTS;
+                       } else {
+                               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);
+                                       arr[i] = r;
+                               }
+                               arr[i] = NULL;
+
+                               for(i = 0; arr[i] != NULL; i++) {
+                                       __dw_free_node(arr[i]);
+                               }
+                               free(arr);
+                       }
                } else if(!used) {
                        newnode->errnum = DW_ERR_EXEC_UNKNOWN_METHOD;
                }
index 43609f8e34eabc857ec26f56a1e2ad76ee75d92e..815f3edc2ae4374e3ec78cff010374401b388cb1 100644 (file)
@@ -1,13 +1,13 @@
 # $Id$
 
 pkgname='dataworks'
-pkgver='0.1.1'
+pkgver='0.1.2'
 pkgdesc='Database System'
 arch=('i686' 'x86_64')
 license=('BSD')
-pkgrel='40'
+pkgrel='2'
 makedepends=('byacc')
-source=('dataworks::svn+http://sw.nishi.boats/svn/nishi-dataworks/trunk#revision=418')
+source=('dataworks::svn+http://sw.nishi.boats/svn/nishi-dataworks/trunk#revision=437')
 sha256sums=('SKIP')
 
 build() {
index d00491fd7e5bb6fa28c517a0bb32b8b506539d4d..00750edc07d6415dcc07ae0351e9397b0222b7ba 100644 (file)
@@ -1 +1 @@
-1
+3