From: nishi Date: Tue, 25 Jun 2024 16:05:12 +0000 (+0000) Subject: trying to add insert X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=864aa7fb021594179cac11e20c60a9ea708b9029;p=dataworks.git trying to add insert git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@437 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- diff --git a/Library/database.c b/Library/database.c index 83f26c2..2ee5c7a 100644 --- a/Library/database.c +++ b/Library/database.c @@ -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; } diff --git a/Library/dataworks.c b/Library/dataworks.c index 6258ae0..9d0d5bd 100644 --- a/Library/dataworks.c +++ b/Library/dataworks.c @@ -36,7 +36,7 @@ #include #include -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" diff --git a/Library/dw_database.h b/Library/dw_database.h index 6dba8d8..8effb4f 100644 --- a/Library/dw_database.h +++ b/Library/dw_database.h @@ -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 diff --git a/Library/exec.c b/Library/exec.c index ae44b87..12a1afa 100644 --- a/Library/exec.c +++ b/Library/exec.c @@ -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; } diff --git a/Package/PKGBUILD b/Package/PKGBUILD index 43609f8..815f3ed 100644 --- a/Package/PKGBUILD +++ b/Package/PKGBUILD @@ -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() { diff --git a/Package/increment-PKGBUILD b/Package/increment-PKGBUILD index d00491f..00750ed 100644 --- a/Package/increment-PKGBUILD +++ b/Package/increment-PKGBUILD @@ -1 +1 @@ -1 +3