1. proposal EDS functions
- Posted by Salix <salix at freemail.hu> Jun 25, 2007
- 605 views
Hello, I regularly use EDS in my projects for quite a few years now. Whenever I start a new project I found myself rewritting these functions. I suggest to include them in the standard database.e file. Any comment, support, improvment is welcome. I suppose all of us developed some similar rountines...
global function db_startup(sequence dbf) integer err,lock lock=DB_LOCK_NO err=db_open(dbf,lock) if err=DB_OK then return DB_OK elsif err=DB_OPEN_FAIL then return db_create(dbf,lock) elsif err=DB_LOCK_FAIL then for i=1 to 10 by 1 do if db_open(dbf,lock)=DB_OK then return DB_OK else sleep(2) end if end for return DB_LOCK_FAIL else return DB_OPEN_FAIL end if end function global function db_startup_table(sequence t) integer err if db_select_table(t)=DB_OK or db_create_table(t)=DB_OK then return DB_OK end if return DB_OPEN_FAIL end function
Regards, Salix
2. Re: proposal EDS functions
- Posted by Hayden McKay <hmck1 at dodo.com.au> Jun 25, 2007
- 616 views
Salix wrote: > > Hello, > > I regularly use EDS in my projects for quite a few years now. > Whenever I start a new project I found myself rewritting these > functions. I suggest to include them in the standard database.e > file. > > Any comment, support, improvment is welcome. I suppose all of us > developed some similar rountines... > > }}} <eucode> > global function db_startup(sequence dbf) > integer err,lock > lock=DB_LOCK_NO > err=db_open(dbf,lock) > if err=DB_OK then > return DB_OK > elsif err=DB_OPEN_FAIL then > return db_create(dbf,lock) > elsif err=DB_LOCK_FAIL then > for i=1 to 10 by 1 do > if db_open(dbf,lock)=DB_OK then > return DB_OK > else > sleep(2) > end if > end for > return DB_LOCK_FAIL > else > return DB_OPEN_FAIL > end if > end function > > global function db_startup_table(sequence t) > integer err > if db_select_table(t)=DB_OK > or db_create_table(t)=DB_OK > then > return DB_OK > end if > return DB_OPEN_FAIL > end function > </eucode> {{{ > > Regards, > > Salix just to add to this post... here is a database.e "function" only handler that i use alot...
include database.e ------------------ global procedure dbase(sequence s, object x, integer c) x = call_func(routine_id(s),x) if x != DB_OK and x != c -- continue then clear_screen() puts (1,"\ndbase() -> A fatal database failure...\n") -- Todo: display s & x abort(x) end if end procedure
* execution continues if the return error is DB_OK or the allowed condition, else a fatal error is reported...
-- example: -- select a table from the database, execution will countinue if -- DB_OK or DB_OPEN_FAIL dbase("db_select_table",{"my_table"},DB_OPEN_FAIL) -- create a table in the database, execution will continue if -- DB_OK or DB_EXISTS_ALREADY dbase("db_create_table",{"my_table"},DB_EXISTS_ALREADY)
3. Re: proposal EDS functions
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 25, 2007
- 618 views
Salix wrote: > > Hello, > > I regularly use EDS in my projects for quite a few years now. > Whenever I start a new project I found myself rewritting these > functions. I suggest to include them in the standard database.e > file. > > Any comment, support, improvment is welcome. I suppose all of us > developed some similar rountines... > I can see some issues with the below function: > }}} <eucode> > global function db_startup(sequence dbf) > integer err,lock > lock=DB_LOCK_NO > err=db_open(dbf,lock) > if err=DB_OK then > return DB_OK > elsif err=DB_OPEN_FAIL then > return db_create(dbf,lock) > elsif err=DB_LOCK_FAIL then > for i=1 to 10 by 1 do > if db_open(dbf,lock)=DB_OK then > return DB_OK > else > sleep(2) > end if > end for > return DB_LOCK_FAIL > else > return DB_OPEN_FAIL > end if > end function > 1/ I assume lock is an argument to the function, not a local variable as you coded it; 2/ I'd expect the "10" to be adjustable. This would require defining a db_max_retry global variable, some factory default for it and a procedure to reset it to that default. Also, you may wish to have a setter which guards against invalid/undesirably large values. It is ok as long as you are admin of your database; if you are not, you should not even be allowed to set that number. 3/ Same remarks as above regarding the delay between consecutive retries (the "2"). Replace "large" by "small" though. 4/ Additionally, your method is blocking, as you sleep() between retries, even though some systems will enable you to yield immediately and be notified of I/O success or timeout. I think db_startup() should try to use these mechanisms where available. They don't exist under DOS, do under Windows 2K and later. Not sure for NT, not available under 9x I think. For unixes, I have no clue. Also, see the thread about nonblocking I/O in Eu. Btw, I never tried mixing Windows' waitable I/O objects and Eu tasks. No idea whether it works without too much effort. I guess the trick is for the callback to call Eu's scheduler with the id of a suspended task which will act real-time upon notification. > global function db_startup_table(sequence t) > integer err > if db_select_table(t)=DB_OK > or db_create_table(t)=DB_OK > then > return DB_OK > end if > return DB_OPEN_FAIL > end function > </eucode> {{{ > No objection there. However, returning a new DB_CREATED status code when the table didn't exist prior could provide useful information (for instance, do some init job if the table wasn't there before). Returning DB_CREATED would be useful in db_startup() too. CChris > Regards, > > Salix