Open aleksandergabriel opened 6 years ago
Update: I am able to delete record that was created with wgdb tool.
If you're able to delete it using the wgdb tool, then your code should be able to do the same. The wgdb tool as far as I know doesn't perform a whole lot of magic, but simply uses the library in an easy but predictable manner.
What I'm trying to say is that there's likely a bug in the code you've worked your way to.
I took a quick look at the code, and the only codepath for the function wg_delete_record
that returns -1
is here:
https://github.com/priitj/whitedb/blob/668a39cb85e1a9c3c63382a009c0706b67f99763/Db/dbdata.c#L218
/** Delete record from database
* returns 0 on success
* returns -1 if the record is referenced by others and cannot be deleted.
* returns -2 on general error
* returns -3 on fatal error
*
* XXX: when USE_BACKLINKING is off, this function should be used
* with extreme care.
*/
Thanks! Yes, -1 means that a field inside another record points to this record. The python wrapper raises the error so that there is a text message also, but this doesn't happen in the db library.
Should we write something to stderr if this happens? I'm not particularly committed to spamming stderr as the user side code frequently runs in loops, and sometimes the errors are non-fatal from the point of view of the application, resulting in producing long streams of vague messages.
I guess one thing that is obvious here is that we need to review the more commonly used API functions and add the return codes to the user manual where missing.
(Edited for clarity)
Ok note to myself, check comments before opening issue on git. Thank you for clarifying that, now I know what to change in my code in order for it to work. In my opinion adding description of return codes would be sufficient in most if not all cases. Great feature on the other hand would be to be possibility to turn on or off stderr messages. So when you are developing you can quickly see what is wrong, but later when your code is in operation you dont spam output. But you probably have many more important developing tasks right now. Thank you again for really fast response.
I am unable to delete record from database, regardless of method used in any database created. I am working on Ubuntu 16.04, White database was installed from release from http://whitedb.org/download.html. So far every other functionality I was able to test works as expected. I create database using c api and add some records. Using wgdb command line tool I can confirm both that records were created and any changes I tried to make to records were actually made. The problem arrives when I use:
wg_delete_record(DB, rec)
where DB is global pointer to database used everywhere else successfully and rec is pointer to record. Function returns -1, which refers to some error in database, but I am not able to understand what that error is and how to fix it. -1 is returned from dbdata.c from functiongint wg_delete_record(void* db, void *rec)
, where in line 217 `#ifdef USE_BACKLINKING if(((gint ) rec + RECORD_BACKLINKS_POS)) return -1;endif
` returns -1. I also tried to use wgdb tool to remove record, but while I get confirmation that rows were deleted, query shows deleted rows still being in the database. Could you please explain to me why I get -1 back and how to fix it.