eds tables
- Posted by rudy toews <rltoews at ilos.net> May 30, 2002
- 464 views
hi all, i have been trying to work on a table cross-reference addon for the eds database.e. i am using version .5. stress.ex will have problems with my code, but createdb and addone work ok. the database looks like it should. i am trying to use a table in the current database to hold references to the other tables. whenever a record gets deleted or a table gets deleted, the pointers in database.e get corrupted and the wrong table is pointed to. this will cause the reference table to start collecting data meant for other tables. i believe the way garbage collection is done causes this to happen. i have tried to select the current table again but it does not help. some of the code is below: -- Euphoria Database System table crossreference extension include xrefdatabase.e --the orignal file, 99.9% unchanged sequence xrefprefix,xrefkey,xrefcurrenttable,xrefcurrentdb,xrefname,realname integer tblxrefkeynum object theretcode,xrefretcode constant TBLXREF = "XREFTBL" constant SCREEN = 1 xrefprefix = "xref" global procedure db_dump(integer fn, integer low_level_too) xrefdb_dump(fn,low_level_too) return end procedure global function db_create(sequence path, integer lock_method) -- when creating a new database, create the tblxref at the same time -- tblxref will be the current table then! but keep it invisible theretcode = xrefdb_create(path,lock_method) if theretcode = DB_OK then xrefcurrentdb = path xrefretcode = xrefdb_create_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN, "xreftbl not created \n") else xrefcurrenttable = "" end if end if return theretcode end function global function db_open(sequence path, integer lock_method) --when opening a database, select the xreftbl table as 'default theretcode = xrefdb_open(path,lock_method) if theretcode = DB_OK then xrefcurrentdb = path xrefretcode = xrefdb_select_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"dbopen creating the xreftbl\n") --if database is old then create the tblxref here -- future: collect the current table names , put into xref table xrefretcode = xrefdb_create_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"dbopen cannot create the xreftbl table \n") end if end if end if xrefcurrenttable = "" return theretcode end function global function db_select(sequence path) theretcode = xrefdb_select(path) if theretcode = DB_OK then xrefcurrentdb = path xrefretcode = xrefdb_select_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"dbselect cannot select xreftbl\n") else xrefcurrenttable = "" end if end if return theretcode end function global procedure db_close() --put some code here to 'log the tblxref for backup purposes --xrefretcode = xrefdb_select_table("TBLXREF") --if xrefretcode != DB_OK then --printf(SCREEN,"%s","cannot close the tblxref") --end if --xrefcurrentdb = "" xrefdb_close() end procedure global function db_create_table(sequence name) --put code here to search the tblxref for the name with /without prefix --if it does not exist in the table, maybe the database (old file) --if not found then the create can make the table entry --do the tblxref entry first, then the database entry so that the database --entry is the last table pointed to when returning from this function. xrefkey = xrefprefix & name realname = name --does the name already exist in the xref table xrefretcode = xrefdb_select_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"dbcreate table cannot access the xreftbl \n") end if tblxrefkeynum = xrefdb_find_key(name) if tblxrefkeynum > 0 then puts(SCREEN,name & " already does exist \n") else end if if tblxrefkeynum < 0 then xrefretcode = xrefdb_insert(name,xrefkey) puts(SCREEN,"putting the table into the xreftbl \n") if xrefretcode != DB_OK then puts(SCREEN, xrefkey & " entry in xreftbl cannot be done \n") else theretcode = xrefdb_create_table(xrefkey) if theretcode != DB_OK then puts(SCREEN,"xreftable has entry but actual table not created\n") tblxrefkeynum = tblxrefkeynum * -1 xrefdb_delete_record(tblxrefkeynum) end if end if end if if theretcode = DB_OK then xrefcurrenttable = name end if return theretcode end function global function db_select_table(sequence name) --look into the tblxref first, --if the last thing done is with the realname then pointers will be correct xrefname = xrefprefix & name --xrefretcode = xrefdb_select_table(xrefname) --if xrefretcode != DB_OK then xrefretcode = xrefdb_select_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"dbselecttable unable to access xreftbl \n") else tblxrefkeynum = xrefdb_find_key(name) if tblxrefkeynum < 0 then puts(SCREEN,name & " cannot be found in the xreftbl \n") else realname = xrefdb_record_data(tblxrefkeynum) xrefretcode = xrefdb_select_table(realname) puts(SCREEN,realname & " table is now selected " & xrefretcode & "\n") puts(SCREEN,name & "\n") --abort(1) end if end if --else --end if theretcode = xrefretcode if theretcode = DB_OK then xrefcurrenttable = name else puts(SCREEN,"no change in the current table selected \n") end if return theretcode end function global procedure db_delete_table(sequence name) xrefname = xrefprefix & name puts(SCREEN,name & "and" & xrefcurrenttable & "\n") xrefretcode = xrefdb_select_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"dbdeletetable unable to access xreftbl \n") else tblxrefkeynum = xrefdb_find_key(name) printf(SCREEN,"%d", tblxrefkeynum) if tblxrefkeynum < 0 then puts(SCREEN,"dbdeletetable cannot locate " & name &" \n") else puts(SCREEN,"the key to delete " & tblxrefkeynum & "\n") realname = xrefdb_record_data(tblxrefkeynum) xrefdb_delete_table(realname) xrefdb_delete_record(tblxrefkeynum) puts(SCREEN,"deleting tablexref entry - xrefname" & realname & "\n") end if end if xrefretcode = db_select_table(xrefcurrenttable) if xrefretcode != DB_OK then puts(SCREEN,"after dbtable delete, cannot return to old table \n") end if end procedure global function db_table_list() sequence onetable,alltables integer totaltables alltables ="" xrefretcode = xrefdb_select_table(TBLXREF) if xrefretcode != DB_OK then puts(SCREEN,"table list error in selecting XREFTABLE \n") else totaltables = xrefdb_table_size() for i = 1 to totaltables by 1 do onetable = xrefdb_record_key(i) alltables = append(alltables,onetable) --puts(SCREEN,onetable & "\n") end for --for i = 1 to length(alltables) by 1 do --puts(SCREEN,alltables[i] & "\n") --end for --totaltables = length(alltables) --printf(SCREEN,"%10d",totaltables ) --puts(SCREEN,"\n") end if --if getc(0) then --end if -- maybe find the entry for tblxref and delete it, huh..keep it invisible xrefretcode = db_select_table(xrefcurrenttable) --theretcode = xrefdb_table_list() theretcode = alltables --for i = 1 to length(theretcode) by 1 do --puts(SCREEN,theretcode[i] & "\n") --end for return theretcode end function global function db_compress() --after a compression of the database , the pointers are updated --so using tablenumbers would be out of the question! theretcode = xrefdb_compress() return theretcode end function the other functions have no alterations, are coded like db_compress. this is a wrapper project, so the orginal database.e function names have been changed (including the spots where they are used in the non-public functions). this would allow apps to run without change. and database.e logic go unchanged. rudy rltoews at ilos.net lotterywars