Re: Find out database
Posted in 1997
>From jake@apparel.net Wed Jul 23 15:34 PDT 1997
>|From johnl@informix.com Wed Jul 23 14:55 EDT 1997
>....
>|Did anybody notice the alternative solution which I posted on this thread
>|on 17th July (according to my outgoing message log)? I posted a stored
>|procedure called current_database().
>
>[...] I did not see it and, judging by the continued controversy, neither
> did anyone else. Please repost it as a reply **to this thread**
Well, here it is -- a repost of a stored procedure for telling you your
current database. If you want, you can SELECT the SITENAME too and add
that into the mix to get the database name and server name formatted as
'dbase@server'.
Date: Thu Jul 17 09:22:56 1997
From: johnl@informix.com (Jonathan Leffler)
To: informix-list@rmy.emory.edu, plassmann.pad@sni.de
Subject: Re: Find out database
>From: Johannes Plassmann <plassmann.pad@sni.de>
>Date: Thu, 17 Jul 1997 10:57:18 +0200
>X-Informix-List-Id: <news.40532>
>
>[...] I need to figure out, which database am I currently working on.
>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.