1. EDB Question
- Posted by Rich Klender <rklender at excite.com> Feb 02, 2007
- 525 views
I'm starting to code writing some data to my Database and I have a couple of generic questions on the EDB commands: 1.) What exactly is returned when you do a db_create or db_open, at various points it states that DB_OK is returned or 0 is returned. Is DB_OK a variable that equals 0? Just wondering for my own education. 2.) If my database file exists or has to be created, I'm assuming we have to give the file path. So: db_create("c:\\somedir\\somesubdir\\myfile.edb") Is this correct? 3.) Now, after creating/opening the EDB, we have to select it. Do we need to give the total pathname, or can we just give the file name, and do we need the .edb extension? i.e. db_select("c:\\somedir\\somesubdir\\myfile.edb") or is it: db_select("myfile") I'm sorry if this has been gone over before...if it has, just point me to where and I'll stop bothering you guys!!! But the manual is rather vague... Thanks! Rich
2. Re: EDB Question
- Posted by Jonas Temple <jtemple at yhti.net> Feb 02, 2007
- 548 views
Rich Klender wrote: > > I'm starting to code writing some data to my Database and I have a couple of > generic questions on the EDB commands: > 1.) What exactly is returned when you do a db_create or db_open, at various > points it states that DB_OK is returned or 0 is returned. Is DB_OK a variable > that equals 0? Just wondering for my own education. If you look at the docs for EDB the db_create() function returns an integer. Also, DB_OK is a constant defined in database.e with a value of 0. So your create would look something like:
atom rtn_code rtn_code = db_create("Myfile.edb",DB_LOCK_NO) if rtn_code = DB_OK then do something here end if
Or like
if db_create("Myfile.edb", DB_LOCK_NO) = DB_OK then do something here end if
Either way works. > > 2.) If my database file exists or has to be created, I'm assuming we have to > give the file path. So: > > db_create("c:\\somedir\\somesubdir\\myfile.edb") > > Is this correct? Yes. BUT I would advise against hard-coding path names. You could use current_dir() to get the current directory if you wanted to include the path in the db_create(). For example:
sequence path path = current_dir() if db_create(path & "\\myfile.edb", DB_LOCK_NO) = DB_OK then do something here end if
or just assume you're current directory is correct:
if db_crate("myfile.edb",DB_LOCK_NO) = DB_OK then do something here end if
However this doesn't always work as you can't assume a current or working directory has been set. If you want to ensure that the file is created in the same directory as the program you could use the command_line() function and extract the program's path from the returned value. Then use the path in the db_create() function. > > 3.) Now, after creating/opening the EDB, we have to select it. Do we need to > give the total pathname, or can we just give the file name, and do we need the > .edb extension? i.e. > > db_select("c:\\somedir\\somesubdir\\myfile.edb") > > or is it: > > db_select("myfile") > Again, the answer to your path question is probably the same as my previous answer. I've never tried to use db_select() without the extensions so I'm not sure what it would do. I always like to specify extensions but that's just me. > I'm sorry if this has been gone over before...if it has, just point me to > where > and I'll stop bothering you guys!!! But the manual is rather vague... > Hey, no problem! Someone answered these questions for me 7 years ago so it's only fair! Jonas Temple http://www.yhti.net/~jktemple
3. Re: EDB Question
- Posted by "Greg Haberek" <ghaberek at gmail.com> Feb 02, 2007
- 532 views
- Last edited Feb 03, 2007
On 2/2/07, Rich Klender <guest at rapideuphoria.com> wrote: > > I'm sorry if this has been gone over before...if it has, just point me to > where > and I'll stop bothering you guys!!! But the manual is rather vague... Here is some generic code that I use as the base of all my database stuffs: (I wrote this out in GMail so don't sue me if its broken.)
global function db_load( sequence path, integer lock ) integer ret -- try selecting the database ret = db_select( path ) if ret = DB_OK then -- success! return ret end if -- select failed, try open ret = db_open( path, lock ) if ret = DB_OK then -- success! return ret end if -- open failed, try create ret = db_create( path, lock ) if ret = DB_OK then -- success! return ret end if -- failure. return ret end function global function db_load_table( sequence table ) integer ret -- try selecting the table ret = db_select_table( table ) if ret = DB_OK then -- success! return ret end if -- select failed, try create ret = db_create_table( table ) if ret = DB_OK then -- success! return ret end if -- failure. return ret end function
Keep in mind that when you create/open/select a database it is the active database until you create/open/select another. So if you call db_create(), that database is the current database, there is no need to call db_select() right after that, its redundant. The same rule goes for tables, except that when you first create/open/select a database, no table is selected. ~Greg
4. EDB Question
- Posted by Tony Steward <figjam at nlc.net.au> Feb 24, 2001
- 506 views
Hi, Does db_close() close all EDB's that are open or just the current EDB. Thanks Tony Come visit me at www.locksdownunder.com
5. Re: EDB Question
- Posted by Jim Duffy <futures8 at earthlink.net> Feb 24, 2001
- 505 views
Hi, Tony, The EDS docs state: Comments Call this procedure when you are finished with the current database. Also note that db_open() and db_create() both make the database just opened or created the current database. So, it would seem that when you db_close() the current database, then the database opened (or created) previous to that one becomes the current database. However, that results in an error. The db_select() in the last if statement is required, else it seems that no open database is current. (Probably, only Rob can verify that). But once selected(), the EDB will require its own db_close(). Hope this helps. The following example worked for me: with trace sequence s trace(1) if db_open("PATTHIST", DB_LOCK_EXCLUSIVE) != DB_OK then puts(1, "Could not open database PATTHIST.EDB. Aborting ...\n") abort(1) end if if db_open("COMMDATA", DB_LOCK_EXCLUSIVE) != DB_OK then puts(1, "Could not open database COMMDATA.EDB. Aborting ...\n") abort(1) end if s = db_table_list() -- just to verify what EDB you've got here db_close() if db_select("PATTHIST") != DB_OK then puts(1,"PATTHIST.EDB could not be selected. Abort.") abort(1) end if s = db_table_list() -- just to verify what EDB you've got here db_close() Regards, Jim Tony Steward wrote: > > Hi, > Does db_close() close all EDB's that are open or just the current EDB. > > Thanks Tony > > Come visit me at www.locksdownunder.com >