Re: Find out database
Posted in 1997
>From: Johannes Plassmann <plassmann.pad@sni.de>
>Date: Thu, 17 Jul 1997 10:57:18 +0200
>X-Informix-List-Id: <news.40532>
>
>Hi there,
>everybody knows the ESQL-C commands
>
>EXEC SQL DATABASE <databasename>
>...
>EXEC SQL CLOSE DATABASE
>
>At some time during my execution of the code I need to figure out,
>which database I currently working on. If I had access to <databasename>
>it should be no problem, but I am doing some checks in a shared libray,
>which in turn has no knowledge about <databasename>. Therefore I looking
>forward to find out the <databasename> which is currently in use...
>Any hints???
Well, this can be used with OnLine 6.00 and above...
# "@(#)$Id: currentdb.spl,v 1.5 1997/06/03 16:19:58 johnl Exp $"
#
# Stored procedure CURRENT_DATABASE written by Jonathan Leffler
# (johnl@informix.com), based on a tip from John Lysell
# (jlysell@informix.com), with corrigenda from Raj Muralidharan
# (rmurali@informix.com) and Tue Hejlskov Larsen (tue@informix.com).
#
# If this stored procedure is created (by user informix to get
# the necessary permissions) in the SysMaster database, then any
# user in any database can run it (or call it in a SELECT
# statement) and get the name of the current database. You can
# drop the owner part if you are not using a MODE ANSI database:
#
# EXECUTE PROCEDURE sysmaster:'informix'.current_database()
# EXECUTE PROCEDURE sysmaster:current_database()
#
# The size of the return parameter probably only needs to be 18.
CREATE PROCEDURE current_database() RETURNING VARCHAR(64);
DEFINE s VARCHAR(64);
SELECT ODB_DBName
INTO s
FROM SysMaster:'informix'.SysOpenDB
WHERE ODB_SessionID = (SELECT DBINFO("sessionid")
FROM 'informix'.SysTables
WHERE TabID = 1)
AND ODB_IsCurrent = "Y";
RETURN s;
END PROCEDURE;
See the notes at the top for installation instructions. SysMaster is a
weird database -- it is the only database which can be accessed from any
type of database (logged, unlogged, mode ansi). Note that the code in
the SP is designed to work even from a MODE ANSI database.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
PS: Warning I do not reply to messages with anti-spam in the return path.