Definition: | integer i = db_open(string st, integer locktype) |
Description: | Open an existing Euphoria database. The file containing the database is given by s. i is a return code indicating success or failure. locktype indicates the type of lock that you want to place on the database file while you have it open. This database becomes the current database to which all other database operations will apply. |
Comments: |
The types of lock that you can use are:
DB_LOCK_NO (no lock), DB_LOCK_SHARED (shared lock for read-only access) and DB_LOCK_EXCLUSIVE (for read/write access). DB_LOCK_SHARED is only supported on Linux. It allows you to read the database, but not write anything to it. If you request DB_LOCK_SHARED on Windows it will be treated as if you had asked for DB_LOCK_EXCLUSIVE. The return codes are: DB_OK(0) - success, DB_OPEN_FAIL(-1) - could not open the file, and DB_LOCK_FAIL(-3) - could not lock the file in the manner requested. If the lock fails, your program should wait a few seconds and try again. Another process might be currently accessing the database. |
Example: |
tries = 0 while 1 do err = db_open("mydata", DB_LOCK_SHARED) if err = DB_OK then exit elsif err = DB_LOCK_FAIL then tries += 1 if tries > 10 then puts(2, "too many tries, giving up\n") abort(1) else sleep(5) end if else puts(2, "Couldn't open the database!\n") abort(1) end if end while |
See Also: | db_create, db_close |