Re: EDB Question

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu