]> Nishi Git Mirror - dataworks.git/commitdiff
can get fields now
authornishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Sat, 25 May 2024 16:44:23 +0000 (16:44 +0000)
committernishi <nishi@d4a5a174-5a4a-5b4b-b672-37683c10d7d5>
Sat, 25 May 2024 16:44:23 +0000 (16:44 +0000)
git-svn-id: file:///raid/svn-main/nishi-dataworks/trunk@112 d4a5a174-5a4a-5b4b-b672-37683c10d7d5

Library/database_record.c
Library/database_table.c
Library/dw_database.h

index e629b7e3ae7ca92a4f23b7af9aadc43380608df1..6ade2f55024b13bde758a1860dca9915389ebd79 100644 (file)
@@ -26,4 +26,4 @@
 /* -------------------------------------------------------------------------- */
 /* --- END LICENSE --- */
 
-#include "dw_database.h"
\ No newline at end of file
+#include "dw_database.h"
index e8f19c6f240a811d6ffa70f5bb33530a6c694040..eb69d4ed274a1639421340dc29f046c147504a81 100644 (file)
@@ -148,3 +148,56 @@ char** dataworks_database_get_table_list(struct dataworks_db* db) {
                return list;
        }
 }
+
+char** dataworks_database_get_table_fields(struct dataworks_db* db, const char* table) {
+       if(db->version == 1) {
+               __dw_lockfile(db->fp);
+               fseek(db->fp, 3 + 10, SEEK_SET);
+               int i;
+               struct dataworks_db_v1_indexentry index;
+               char* buf = malloc(1 + 8 + 1 + 256 + 4096);
+               int c = 0;
+               for(i = 0; i < 256; i++) {
+                       fread(buf, 1, 1 + 8 + 1 + 256 + 4096, db->fp);
+                       __dw_buffer_to_db_v1_indexentry(buf, index);
+                       if(index.flag & DATAWORKS_V1_INDEXENTRY_USED) {
+                               char* dbname = malloc(index.dbname_len + 1);
+                               memcpy(dbname, index.dbname, index.dbname_len);
+                               dbname[index.dbname_len] = 0;
+                               if(strcmp(dbname, table) == 0) {
+                                       char** list = malloc(sizeof(*list));
+                                       list[0] = NULL;
+                                       int j;
+                                       int start = 1;
+                                       for(j = 1;; j++) {
+                                               if(index.fields[j] == 0) {
+                                                       char* nam = malloc(j - start + 1);
+                                                       nam[start - j] = 0;
+                                                       memcpy(nam, index.fields + start, j - start);
+                                                       int k;
+                                                       for(k = 0; list[k] != NULL; k++)
+                                                               ;
+                                                       char** newlist = malloc(sizeof(*newlist) * (k + 2));
+                                                       for(k = 0; list[k] != NULL; k++) newlist[k] = list[k];
+                                                       newlist[k] = nam;
+                                                       newlist[k + 1] = NULL;
+                                                       free(list);
+                                                       list = newlist;
+                                                       j++;
+                                                       start = j + 1;
+                                                       if(index.fields[j] == 0) break;
+                                               }
+                                       }
+                                       free(dbname);
+                                       free(buf);
+                                       __dw_unlockfile(db->fp);
+                                       return list;
+                               }
+                               free(dbname);
+                       }
+               }
+               free(buf);
+               __dw_unlockfile(db->fp);
+       }
+       return NULL;
+}
index b475546f126080a41f8387388cde4ad14d1aeaf0..244d01f13ab4fc5f690184af6b91d678cbc6c427 100644 (file)
@@ -140,7 +140,7 @@ enum DW_ERRORS {
 /**
  * @~english
  * @brief Type enum
- * 
+ *
  */
 enum DW_RECORD_TYPES {
        /**
@@ -160,21 +160,21 @@ enum DW_RECORD_TYPES {
        /**
         * @~english
         * @brief Double
-        * 
+        *
         */
        DW_RECORD_DOUBLE = 'D',
 
        /**
         * @~english
         * @brief Logical
-        * 
+        *
         */
        DW_RECORD_LOGICAL = 'L',
 
        /**
         * @~english
         * @brief HELP
-        * 
+        *
         */
        DW_RECORD_HELP = '?',
 };
@@ -245,7 +245,7 @@ struct dataworks_db_record {
        /**
         * @~english
         * @brief Type. See enum DW_RECORD_TYPES.
-        * 
+        *
         */
        char type;
 };
@@ -385,6 +385,16 @@ uint64_t dataworks_database_get_mtime(struct dataworks_db* db);
  */
 char** dataworks_database_get_table_list(struct dataworks_db* db);
 
+/**
+ * @~english
+ * @brief Get the fields of the table of the database.
+ * @param db Database
+ * @param table Table name
+ * @return Fields of the table
+ *
+ */
+char** dataworks_database_get_table_fields(struct dataworks_db* db, const char* table);
+
 /**
  * @~english
  * @brief Creates a table.