proc Fetch_Alexandria { ArgV1 } { global MD Fver FunctionName InterOp # # Fetch_Alexandria # # This routine implements the movement of data from the UCSB # Alexandria project Illustra installation to the UCB "Elib" # project Illustra installation. The strategy is simple enough: # # Since we don't have an Illustra to Illustra gateway, we're # borrowing our "distributed Tcl" engine we've already implemented # in the BigSur environment in order to kick out a "glue" component # (this routine) to suck the data we need across. We borrow the # Function components of BigSur to create a functional environ # capable of dispatching this Tcl script whenever anyone needs # data from Alexandria. # # We have a "BigSur" schema in our database in which most of our # applications data resides. We have created a second schema, # "Alexandria", which contains a complete copy of the schema used # in the Alexandria project. Also in the Alexandria schema, we have # created VIEWS of the BigSur tables which actually "look at" the # Alexandria tables. This routine is used to keep the "copy" of # the real Alexandria data current in the Alexandria schema. # # This routine is used can be used for each and every desired fetch. # Simply provide an appropriate Argv1... It then dispatches through # a switch statement to discover what "in query" and "out query" # statements to use. Finally, it enters a loop and moves all rows # from the "remote" (UCSB) Alexandria installation to the "local" # one (UCB). # set work_list "init bs_connect alex_connect move_data commit close" set InterOp(arg1) $ArgV1 foreach call $work_list { InterOp $call if {!($InterOp(ok))} { puts "Fetch_Alexandria Function Error, routine $call" if {$call == "init"} {break} puts $InterOp(error) InterOp abort if {!($InterOp(ok))} {puts "MSQL error during transaction abort!"} break } } } proc InterOp {call} { global MD Fver FunctionName InterOp set InterOp(ok) 1 set InterOp(error) "" switch $call { init { if { !($MD(location) == "client") } { set InterOp(ok) 0 set InterOp(error) "Function not on Client." break } set InterOp(dbname) "nsdb" set InterOp(server) "alex" set InterOp(user) "chalupa" set InterOp(pwd) "InterOp1" # ArgV1 is used for "mapping" to a set of in, out, and # columns values... # there is no direct relationship to table names, either in, or out, but # it's perhaps best if you pick one or the other! switch $InterOp(arg1) { Ident02 { set InterOp(inqry) "select * from Ident02;" set InterOp(outqry) "insert into Ident02 (West_Bound_Coord, South_Bound_Coord, East_Bound_Coord, North_Bound_Coord, Object_Path) values (" set InterOp(numcols) 5 } } } bs_connect { miclient_open mi_exec $MD(connection) "set schema Alexandria;" mi_exec $MD(connection) "begin transaction;" } alex_connect { # msql -s alex -U chalupa -P InterOp1 nsdb set InterOp(connection) [mi_server_connect $InterOp(dbname)] mi_login $InterOp(connection) $InterOp(dbname) $InterOp(user) $InterOp(pwd) # mi_exec $InterOp(connection) "set schema Alexandria;" mi_exec $InterOp(connection) "begin transaction;" } move_data { set results [mi_select_rows $InterOp(connection) $InterOp(inqry)] if {!($results == "MI_ERROR")} { set qry $InterOp(outqry) foreach row $results { for {set i 1} {$i<=$InterOp(numcols)} {incr i} { set col [lindex $row $i] if {$i == $InterOp(numcols)} { set qry "$qry $col);" } else { set qry "$qry $col," } } mi_exec $MB(connection) $qry if {$results == "MI_ERROR"} { set InterOp(ok) 0 set InterOp(error) "Error on insert, query was $qry" break } } } } commit { set qry "end transaction;" mi_exec $MB(connection) $qry if {$results == "MI_ERROR"} { set InterOp(ok) 0 set InterOp(error) "Error on commit." } } abort { set qry "abort transaction;" mi_exec $MB(connection) $qry if {$results == "MI_ERROR"} { set InterOp(ok) 0 set InterOp(error) "Error on abort." } } close { } } } # # Each Distributed Processing Client, on which this script runs, # has the MD() structure containing information about its state etc. # This global variable consists of; # # freemem - Each of these names contains the # logical - variable it is named after. There # daemon - is also a small set of functions # uptime - which do things over these variables. # rpcFile - # server - miclient_atexit # connection - miclient_connected # tmpdir - miclient_close # rpcPort - miclient_mkserver # database - miclient_open # machine - # freedisk - Each of these do familiar things. # uname # # There are also a number of variables which are defined in the setup # portion, before this proc is loaded. These identify the processName and # processVersion. There is an additional variable, UserOID, which is the # oid in the Contact_Information table of the person who is running this # query. This is all a bit fishy. # # FunctionName Name of the Function (processName) # Fver Version of the Function (processVersion) # UserOID oid of the Person Running the query. # # # set qry " SELECT UNIQUE BS.BigSurObject,..." # set RetVal [ mi_select_first_row $MD(connection) $InqQry ] # if { $RetVal == "MI_ERROR" } { # miclient_close # return "ERROR: Failed on $qry" # } # if { $RetVal != "" } {} # return $ResultOID # # set UNum [ mi_select_first_row $MD(connection) "return BigSur.GetNextId();" ]