db_open on steroids !
- Posted by K_D_R
Nov 26, 2012
-- the following prefix macro saves (;dbo) many key strokes and
-- also decreases the chances of errors. It even tests the routine!
-- The same routines that ed.ex employs to select files and maintain
-- command histories are used here to automate the db_open command/
-- The database name can be selected from a pick list *.edb's that
-- already exist in the current directory, or a new *.edb name can be
-- entered.
--Paste these assignments at the beginning of the prefix_macro routine:
-- for db_open prefix macro: --------------
sequence lock_method ={}
object current_dir_db = dir("*.edb")
sequence tmp = {}
-------------------------------------------
-- then paste the following code within the routines elsif clauses:
elsif equal(macro,"dbo") then
set_top_line("Select/Open/Create Database: ")
text_color(TOP_LINE_TEXT_COLOR)
if not(equal(current_dir_db, -1)) then
if length(current_dir_db)>=1 then
for i = 1 to length(current_dir_db) do
tmp = update_history(tmp, sprintf("%s", {current_dir_db[i][D_NAME]}))
current_dir_db = trim(key_gets("",tmp))
end for
end if
else
current_dir_db = trim(key_gets("", {}))
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"}) & ' ')
-- test
if db_select(sprintf("%s", {current_dir_db})) != DB_OK then
if db_open(sprintf("%s", {current_dir_db})) != DB_OK then
if db_create(sprintf("%s", {current_dir_db})) != DB_OK then
set_top_line(" ")
any_key("Could not Select/open/create db!")
end if
end if
end if
-- end test
add_queue("db_open(\"" & sprintf("%s", {current_dir_db}) & "\"," & sprintf("%s", {lock_method}) & ")")
add_queue(HOME & repeat(DELETE, 4) & END)
normal_video()
goto_line(0, b_col)
-- The macro should be executed from the start of a new line
Not Categorized, Please Help
|
|