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)