1. suggestion for database.e

Hello,

I've added three functions, which I missed several times, to database.e
Are there any suggestions, or is there a better way to get the following 
infos?

global function db_list()
-- return all open databases
	return db_names
end function
-----
global function db_current()
-- return name of current selected database
	if length(db_names) then return db_names[find(current_db,db_file_nums)] 
else return -1 end if
end function
-----
global function db_current_table()
-- find a table, given its t_header 
-- return table name
    atom tables, nt, t_header, name_ptr
    sequence tname
    safe_seek(TABLE_HEADERS)
    tables = get4()
    safe_seek(tables)
    nt = get4()
    t_header = tables+4
    for i = 1 to nt do
		safe_seek(t_header)
		name_ptr = get4()
		safe_seek(name_ptr)
		tname = get_string()
		if t_header = current_table then
		    -- found it
		    return tname
		end if
		t_header += SIZEOF_TABLE_HEADER
    end for
    return -1
end function


bye
Markus

new topic     » topic index » view message » categorize

2. Re: suggestion for database.e

----- Original Message ----- 
From: "Markus Schaller" <markus.schaller at web.de>
To: "EUforum" <EUforum at topica.com>
Subject: suggestion for database.e


> 
> 
> Hello,
> 
> I've added three functions, which I missed several times, to database.e
> Are there any suggestions, or is there a better way to get the following 
> infos?
> 

I'd had added the same functions to my copy of database.e too. I did the
current_table differently though.

I added a new variable 'current_table_name' and set this to "" whenever the
current_table is closed and to the table name when a table is selected. My new
routine is ...


  global function db_current_table() -- DEREK PARNELL --
    return current_table_name        -- DEREK PARNELL --
  end function                       -- DEREK PARNELL --

I also added a slight performance enhancement to db_select_table ...


  global function db_select_table(sequence name)
  -- let table with the given name be the current table
    atom table, nkeys, index
    atom block_ptr, block_size
    integer blocks, k
    
    table = table_find(name)
    if table = -1 then
       return DB_OPEN_FAIL
    end if  
    if current_table = table then    -- DEREK PARNELL --
    return DB_OK                     -- DEREK PARNELL --
    end if                           -- DEREK PARNELL --
    current_table_name = name        -- DEREK PARNELL --
    current_table = table
    . . . 

-- 
Derek

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu