Re: EDB Question

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

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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu