Re: Finding out your current database in SPL
Posted in 1999
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
--------------543B10AD675B
Content-Type: TEXT/PLAIN; CHARSET=us-ascii
Content-ID: <Pine.GSO.3.96.990513092850.13539I@osiris>
>From: "Sheldon, Wayne" <w.sheldon@airflow-streamlines.co.uk>
>Newsgroups: comp.databases.informix
>Subject: Finding out your current database in SPL
>Date: Wed, 12 May 1999 18:43:18 +0100
>
>In my SPL I need to run a SYSTEM command that executes a batch file, which
>will then update the relevant database, but I cant any way of passing the
>current database to the system. We also have other databases which also
>need to execute the batch file, I have a work-around, which is to create
>separate procedures for each database which execute separate batch files.
>This isn't very tidy as the procedures files have to be kept separate for
>each database.
I believe the stored procedure below is both solid and still accurate,
and it has probably been posted several times previously. If you're
really lucky, it might already be in the IIUG archive (or, it soon will be
since I've sent it to the people who maintain that archive).
# "@(#)$Id: currentdb.spl,v 1.6 1998/12/31 20:04:54 jleffler Exp $"
#
# Stored procedure CURRENT_DATABASE written by Jonathan Leffler
# (jleffler@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 needs to be 128 to allow for
# the (currently forth-coming) 9.2x and later servers where the
# names of databases, tables and columns is increased to 128.
# The quoting conventions used should be safe even with DELIMIDENT
# set in the environment.
CREATE PROCEDURE current_database() RETURNING VARCHAR(128);
DEFINE s VARCHAR(128);
SELECT ODB_DBName
INTO s
FROM SysMaster:"informix".SysOpenDB
WHERE ODB_SessionID = DBINFO('sessionid')
AND ODB_IsCurrent = 'Y';
RETURN s;
END PROCEDURE;
Yours,
Jonathan Leffler (jleffler@informix.com) #include <quotes/shakespeare.h>
Guardian of DBD::Informix v0.60 (v0.61_02) -- http://www.perl.com/CPAN
Informix IDN for D4GL & Linux -- http://www.informix.com/idn
--------------543B10AD675B--