Re: Determining what database your connected to in a SP
Posted in 1998
David
To find the instance name, you could use the following SQL:
SELECT cf_effective INTO currinstname
FROM sysmaster:sysconfig
WHERE cf_name = "DBSERVERNAME";
To find the database name, I could think of only this. Maybe somebody
could come up with something simpler?
LET currdbname = "";
CREATE TEMP TABLE t_allsessions (
sqs_dbname CHAR(18),
sqs_sessionid INTEGER);
INSERT INTO t_allsessions
SELECT sqs_sessionid, sqs_dbname
FROM sysmaster:syssqlstat; SELECT sqs_dbname INTO currdbname
FROM t_allsessions
WHERE sqs_sessionid = (SELECT DBINFO('sessionid')
FROM systables
WHERE tabid = 100);
The reason I could not do a query directly from syssqlstat is
presumably that the row is being written to as I execute the query.
However if you are calling the SP from a operating system script then
you would have both the instance name and database name at the point
where you call the procedure in the environment variables
INFORMIXSERVER and DBNAME, wouldn't you?
HTH
Sujit
______________________________ Reply Separator _________________________________
Subject: Determining what database your connected to in a SP
Author: "D. Sandmann" <sandman@cfer.com> at Internet
Date: 10/19/1998 2:58 PM
I have a stored procedure that is distributed accross many databases
(development, testing, certification, training and production). The
development and testing db reside on the same box in two different
instances. The certification and training database reside on the same
box on the same instance. The production database resides on its own
system and instance.
The stored procedure makes a system call that runs a shell script which
then calls a 4GL program to generate a report.
I would like the stored procedure to tell my shell script which
database/instance it is being called from. Based on that information the
shell would then know what environment variables to set up and what 4gl
program to call.
I do not want to hardcode that information into the stored procedure
because we sometimes take a snapshot of the production database and
place the snapshot on the other databases.
Any help!!
Thanks in advance,
David S.