From 94015c2bb775532e6d92700e5ffe7aea13fb3ec6 Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 29 May 2024 02:21:54 +0000 Subject: [PATCH] add record value type git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@132 d4a5a174-5a4a-5b4b-b672-37683c10d7d5 --- FORMATv1.md | 2 +- Library/database_record.c | 2 +- Library/dw_database.h | 70 +++++++++++++++++++++++++++++++++++++-- Library/exec.c | 12 +++---- 4 files changed, 76 insertions(+), 10 deletions(-) diff --git a/FORMATv1.md b/FORMATv1.md index f1f97dc..85a0dfd 100644 --- a/FORMATv1.md +++ b/FORMATv1.md @@ -46,7 +46,7 @@ There are 5 types for `indexentry`: | ---- | --------- | ---- | ---- | | String | `S` | ASCII | | | Integer | `I` | int64\_t | | -| Double | `D` | double | | +| Floating | `F` | double | | | Logical | `L` | uint8\_t | 0 for false, other value for true | | Help | `?` | ASCII | Should be just ignored | diff --git a/Library/database_record.c b/Library/database_record.c index e412110..6efe830 100644 --- a/Library/database_record.c +++ b/Library/database_record.c @@ -124,7 +124,7 @@ struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db entsize = strlen(fields[i]); } else if(types[i] == DW_RECORD_INTEGER) { entsize = 8; - } else if(types[i] == DW_RECORD_DOUBLE) { + } else if(types[i] == DW_RECORD_FLOATING) { entsize = sizeof(double); } else if(types[i] == DW_RECORD_LOGICAL) { entsize = 1; diff --git a/Library/dw_database.h b/Library/dw_database.h index d14d134..52c8b2e 100644 --- a/Library/dw_database.h +++ b/Library/dw_database.h @@ -187,10 +187,10 @@ enum DW_RECORD_TYPES { /** * @~english - * @brief Double + * @brief Floating * */ - DW_RECORD_DOUBLE = 'D', + DW_RECORD_FLOATING = 'F', /** * @~english @@ -373,6 +373,69 @@ struct dataworks_db_infoentry { uint64_t mtime; }; +/** + * @~english + * @brief Record value + * + */ +union dataworks_db_result_value { + /** + * @~english + * @brief Integer + * + */ + int64_t integer; + + /** + * @~english + * @brief Floating + * + */ + double floating; + + /** + * @~english + * @brief String + * + */ + char* string; + + /** + * @~english + * @brief Logical + * + */ + uint8_t logical; + + /** + * @~english + * @brief Help + * + */ + char* help; +}; + +/** + * @~english + * @brief Database Record. + * + */ +struct dataworks_db_record { + /** + * @~english + * @brief Record value + * + */ + union dataworks_db_result_value value; + + /** + * @~english + * @brief Type. See DW_RECORD_TYPES. + * + */ + char type; +}; + /** * @~english * @brief Creates the database. @@ -545,6 +608,7 @@ struct dataworks_db_result* dataworks_database_insert_record(struct dataworks_db /** * @~english + * @brief Select the table. * @param db Database * @param table Table name * @return Result @@ -554,6 +618,7 @@ int dataworks_database_use_table(struct dataworks_db* db, const char* table); /** * @~english + * @brief Get the table count. * @param db Database * @param table Table name * @return Count @@ -563,6 +628,7 @@ uint64_t dataworks_database_get_table_count(struct dataworks_db* db, const char* /** * @~english + * @brief Set the table count. * @param db Database * @param table Table name * @param count Count diff --git a/Library/exec.c b/Library/exec.c index 910ae05..d38fc7f 100644 --- a/Library/exec.c +++ b/Library/exec.c @@ -117,15 +117,15 @@ struct dataworks_db_result* __dataworks_database_execute_code(struct dataworks_d if(val[k] == ':') { val[k] = 0; if(__dw_strcaseequ(val, "string")) { - fieldtypes[argc] = 'S'; + fieldtypes[argc] = DW_RECORD_STRING; } else if(__dw_strcaseequ(val, "integer")) { - fieldtypes[argc] = 'I'; - } else if(__dw_strcaseequ(val, "double")) { - fieldtypes[argc] = 'D'; + fieldtypes[argc] = DW_RECORD_INTEGER; + } else if(__dw_strcaseequ(val, "floating")) { + fieldtypes[argc] = DW_RECORD_FLOATING; } else if(__dw_strcaseequ(val, "logical")) { - fieldtypes[argc] = 'L'; + fieldtypes[argc] = DW_RECORD_LOGICAL; } else if(__dw_strcaseequ(val, "help")) { - fieldtypes[argc] = '?'; + fieldtypes[argc] = DW_RECORD_HELP; } fields[argc] = __dw_strdup(val + k + 1); argc++; -- 2.43.0