Re: db_open on steroids !
- Posted by K_D_R
Nov 30, 2012
-- I think this is a little improvement over the code listed in the previous post
-- The code block written is the same as the test code. Essentially, the macro combines
-- db_select, db_open, & db_create.
-- I added a variable for facilitate testing the LOCK_METHOD,
-- so the assignment statements at the top of the prefix_macro routine
-- now looks like this:
sequence lock_method ={}
object current_dir_db = dir("*.edb")
sequence tmp = {}
integer lm = 0
------------------------------------------------------------------------
------------------------------------------------------------------------
elsif equal(macro,"dbo") then
-- select/open/create euphoria database
set_top_line("Select/Open/Create Database: ")
text_color(TOP_LINE_TEXT_COLOR)
if equal(current_dir_db, -1) then
current_dir_db = trim(key_gets("", {}))
else
for i = 1 to length(current_dir_db) do
tmp = update_history(tmp, sprintf("%s", {current_dir_db[i][D_NAME]}))
end for
current_dir_db = trim(key_gets("",tmp))
end if
set_top_line("Database lock method = ")
text_color(TOP_LINE_TEXT_COLOR)
lock_method = trim(key_gets(" ",{"DB_LOCK_SHARED", "DB_LOCK_EXCLUSIVE", "DB_LOCK_NO"}))
if equal(lock_method, "DB_LOCK_SHARED") then
lm = DB_LOCK_SHARED
elsif equal(lock_method, "DB_LOCK_EXCLUSIVE") then
lm = DB_LOCK_EXCLUSIVE
else
lm = DB_LOCK_NO
end if
-- test
if db_select(sprintf("%s", {current_dir_db}), lm) != DB_OK then
if db_open(sprintf("%s", {current_dir_db}), lm) != DB_OK then
if db_create(sprintf("%s", {current_dir_db}), lm) != DB_OK then
set_top_line(" ")
text_color(TOP_LINE_TEXT_COLOR)
any_key("Could not Select/open/create db!")
end if
end if
end if
-- end test
-- write code block
add_queue(repeat(BS,length(macro)+1)) -- erase calling macrol label
add_queue("\nif db_select(\"" & sprintf("%s", {current_dir_db}) & "\","
& sprintf("%s", {lock_method}) & ") != DB_OK then "
& "\n\tif db_open(\"" & sprintf("%s", {current_dir_db}) & "\","
& sprintf("%s", {lock_method}) & ") != DB_OK then"
& "\n\tif db_create(\"" & sprintf("%s", {current_dir_db}) & "\","
& sprintf("%s", {lock_method}) & ") != DB_OK "
& ARROW_DOWN & "\tend if" & ARROW_DOWN
& "\tend if" & CR & BS & END & CR)
normal_video() -- refresh
goto_line(0, b_col) -- screen
-- comments & suggestions for improvements will be appreciated!
Not Categorized, Please Help
|
|