Go Down

Topic: AGHW-Database handling-EDB library (Read 2 times) previous topic - next topic


I am looking in the edb lib... very interesting...!

With edb we can open a edb table from the EEPROM... How can we make sure that the opened edb object holds the correct data (for the corresponding record structure)?

I mean how can I confirm that the already opened data structure (EEPROM) and the EDB object (opened) use the absolute same record structure?

I think that something is missing here...



(took some time to think this over...)

Never used the EDB lib in a sketch so I am not influenced by any form of knowledge ;)

If you want to be (99%) sure, the database must store metadata about the tables just like a real database. The eeprom is just the carrier of the bit with its specific properties like being fast etc.

In a real database there are (system)tables that describe the database, the users and their access rights and all kind of meta information (logging, performance monitoring data etc). Furthermore these system-tables describe which user-tables are in the database.

The edb doesnot log metadata in its database it just allocates a memory block. So to be sure you have the right table the creation of the table should at least write the name/type of record and optional its structure to some sort of systemtable. Such a systemtable could make life quite easier for the programmer.

proposal: edb++ lib
Suppose one has a system-table with the following record structure

{ char name[17], uint8_t recordsize,  uint8_t, maxrecords, uint8_t #records, uint8_t startaddress } *

The first record in this table would be { "system",  20,  20, 1, 0 }     
// this implies there is room in this database for 20 tables and this systemtable allocates 400 bytes.

The user could call
createTable("mytable", 40, sizeOf(struct xxx));  // name, max records, sizeof record

this would create an new entry in the systemtable  // assume xxx uses 10 bytes
{ "mytable", 10, 40, 0, 400 } 

Then the user could call
addRecord("myTable", currentrecord);

The user does not need to do the address administration as the lib has all the information to do so

Another function could be
boolean existTable(string); to test if the table you want to use exist in this eeprom. This call would solve your problem for 99%.

Other functions on this systemlevel would be: (not complete, just a braindump)
boolean createDatebase(#tables);  // creates the system table --
boolean clearEEPROM();     // clears whole eeprom

boolean createTable(Tablename, maxRecords, recordSize);
boolean existTable(Tablename);
boolean wipeTable(TableName);      // clears all entries (overwrites it);
boolean deleteTable(TableName);    // removes entry from systemTable
int getRecordCount(TableName);                       // use "system" to get systemtable
int getMaxRecordCount(TableName);
int getRecordSize(TableName);

boolean renameTable(TableName, newTablename);
boolean resizeTable(TableName, size);   // optional as this one is

boolean addRecord(tablename, & var);  // no need to add the address in eeprom or the size of the var as these are known!
boolean getRecord(tablename, index , &var);
boolean updateRecord(tablename, index, &var);
boolean deleteRecord(tablename, index);

The complexity of the functions above are not very high - especially if one allows fragmented memory. The added value is that if an Arduino would load a different sketch it could fetch only its tables from EEPROM without touching the others. Note that a table could also just have one record if one wants to store a config struct.

sofar my 2 cents

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


I guess that this is the fix you are looking for.


Issue 1 attachment: fix_open_function.patch (327 bytes)
Index: EDB.cpp
--- EDB.cpp   (revision 7)
+++ EDB.cpp   (working copy)
@@ -81,6 +81,7 @@
  EDB_Status EDB::open(unsigned long head_ptr)
  {    EDB_head_ptr = head_ptr;
       EDB_table_ptr = sizeof(EDB_Header) + EDB_head_ptr;      << add this line
       return EDB_OK;

Go Up