473,467 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

LF example of dbinfo with "language SQL"

Can some one post an example, or where to find one, using DBINFO in a
SQL procedure? I can't seem to find one anywhere. I don't see the
linkage between the structure and the SQL language variables in the
documentation.

A SCRATCHPAD example would be useful too.

I need to identify which user is executing a stored procedure, then
pick up the same information in a trigger. The application runs on
several platforms so I don't want to code a c procedure.

Thanks

Bob
Nov 12 '05 #1
6 3454
Bob Sparks wrote:
Can some one post an example, or where to find one, using DBINFO in a
SQL procedure? I can't seem to find one anywhere. I don't see the
linkage between the structure and the SQL language variables in the
documentation.

A SCRATCHPAD example would be useful too.

I need to identify which user is executing a stored procedure, then
pick up the same information in a trigger. The application runs on
several platforms so I don't want to code a c procedure.


Are you sure this is a DB2 feature? There is a DBINFO in IBM Informix
Dynamic Server, but I was under the illusion that it was peculiar to
IDS and not available anywhere else.

--
Jonathan Leffler #include <disclaimer.h>
Email: jl******@earthlink.net, jl******@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/
Nov 12 '05 #2
Jonathan Leffler wrote:
Bob Sparks wrote:
Can some one post an example, or where to find one, using DBINFO in a
SQL procedure? I can't seem to find one anywhere. I don't see the
linkage between the structure and the SQL language variables in the
documentation.

A SCRATCHPAD example would be useful too.
You can't specify a SCRATCHPAD or the DBINFO clause for procedures that use
LANGUAGE SQL. Have a look at the manual for the CREATE PROCEDURE
statement:
http://www-306.ibm.com/cgi-bin/db2ww...n=r0008329.htm

The two options (and a few others) are solely for external procedures
implemented using C/Java/...
I need to identify which user is executing a stored procedure, then
pick up the same information in a trigger. The application runs on
several platforms so I don't want to code a c procedure.

Have a look at the special registers CURRENT USER, SESSION USER, SYSTEM
USER, and USER. Most probably, the USER register might be what you need.
http://www-306.ibm.com/cgi-bin/db2ww...n=r0005888.htm
Are you sure this is a DB2 feature? There is a DBINFO in IBM Informix
Dynamic Server, but I was under the illusion that it was peculiar to
IDS and not available anywhere else.


Yes, this is a DB2 UDB feature - at least since version 5, maybe even
earlier.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #3
Jonathan Leffler <jl******@earthlink.net> wrote in message news:<wq*****************@newsread1.news.pas.earth link.net>...
Bob Sparks wrote:
Can some one post an example, or where to find one, using DBINFO in a
SQL procedure? I can't seem to find one anywhere. I don't see the
linkage between the structure and the SQL language variables in the
documentation.

A SCRATCHPAD example would be useful too.

I need to identify which user is executing a stored procedure, then
pick up the same information in a trigger. The application runs on
several platforms so I don't want to code a c procedure.


Are you sure this is a DB2 feature? There is a DBINFO in IBM Informix
Dynamic Server, but I was under the illusion that it was peculiar to
IDS and not available anywhere else.


Sure there is are C & Java examples in the samples folder but no SQL.
(..\SQLLIB\samples\java\jdbc\DbInfo.java
...\SQLLIB\samples\c\dbinfo.c) I basically need to access some kind of
common area to synchronize routines and to pass information globally.
So any mechanism will do.
Nov 12 '05 #4
Bob Sparks wrote:
Jonathan Leffler <jl******@earthlink.net> wrote in message
news:<wq*****************@newsread1.news.pas.earth link.net>...
Bob Sparks wrote:
> Can some one post an example, or where to find one, using DBINFO in a
> SQL procedure? I can't seem to find one anywhere. I don't see the
> linkage between the structure and the SQL language variables in the
> documentation.
>
> A SCRATCHPAD example would be useful too.
>
> I need to identify which user is executing a stored procedure, then
> pick up the same information in a trigger. The application runs on
> several platforms so I don't want to code a c procedure.


Are you sure this is a DB2 feature? There is a DBINFO in IBM Informix
Dynamic Server, but I was under the illusion that it was peculiar to
IDS and not available anywhere else.


Sure there is are C & Java examples in the samples folder but no SQL.
(..\SQLLIB\samples\java\jdbc\DbInfo.java
..\SQLLIB\samples\c\dbinfo.c) I basically need to access some kind of
common area to synchronize routines and to pass information globally.
So any mechanism will do.


Could you possibly describe your scenario/problem in more detail so that we
know and understand the real requirements? Maybe we can come up with a
solution for you.

I believe that even a SCRATCHPAD, if it were available for LANGUAGE SQL
functions, would not be any help for you.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #5
Knut Stolze <st****@de.ibm.com> wrote in message news:<cb**********@fsuj29.rz.uni-jena.de>...
Bob Sparks wrote:
Jonathan Leffler <jl******@earthlink.net> wrote in message
news:<wq*****************@newsread1.news.pas.earth link.net>...
Bob Sparks wrote:

> Can some one post an example, or where to find one, using DBINFO in a
> SQL procedure? I can't seem to find one anywhere. I don't see the
> linkage between the structure and the SQL language variables in the
> documentation.
>
> A SCRATCHPAD example would be useful too.
>
> I need to identify which user is executing a stored procedure, then
> pick up the same information in a trigger. The application runs on
> several platforms so I don't want to code a c procedure.

Are you sure this is a DB2 feature? There is a DBINFO in IBM Informix
Dynamic Server, but I was under the illusion that it was peculiar to
IDS and not available anywhere else.


Sure there is are C & Java examples in the samples folder but no SQL.
(..\SQLLIB\samples\java\jdbc\DbInfo.java
..\SQLLIB\samples\c\dbinfo.c) I basically need to access some kind of
common area to synchronize routines and to pass information globally.
So any mechanism will do.


Could you possibly describe your scenario/problem in more detail so that we
know and understand the real requirements? Maybe we can come up with a
solution for you.

I believe that even a SCRATCHPAD, if it were available for LANGUAGE SQL
functions, would not be any help for you.


Thanks Knut .. I hope you are still reading this thread :-)

We want to log who changed which record. Now as with many
installations we are not using RDBMS authentication. We use our own
security as we have row level security based on the enterprise
directory. So each transaction runs from a connection pool. At the
time the connection is handed from the pool I would like to write the
users enterprise id into a scratchpad. My understanding is that any
code running on that connection would get the same scratchpad. So
therefore.
1. Write enterprise id into a fenced scratchpad and return connection
..
2. Perform any arbitrary procedure.
3. Step 2 fires of a trigger on change of a record.
4. Access the scratchpad and write the enterprise id to audit log from
inside the trigger.

This get around the fact the triggers aren't passed parameters other
than what you can get from dbinfo or the changed record's columns.
My routine, in pseudocode would simply

ENTID (userid varchar(30))
returns varchar
scratchpade
fenced
begin
declare scratchpad cookie varchar(30)
if userid is not null then
set cookie = userid
end if
return cookie
end
Nov 12 '05 #6
Bob Sparks wrote:
Could you possibly describe your scenario/problem in more detail so that
we
know and understand the real requirements? Maybe we can come up with a
solution for you.

I believe that even a SCRATCHPAD, if it were available for LANGUAGE SQL
functions, would not be any help for you.
Thanks Knut .. I hope you are still reading this thread :-)

We want to log who changed which record. Now as with many
installations we are not using RDBMS authentication. We use our own
security as we have row level security based on the enterprise
directory. So each transaction runs from a connection pool. At the
time the connection is handed from the pool I would like to write the
users enterprise id into a scratchpad.


Ok, I think I get the idea. You like to have some sort of register/storage
where you can put some information, i.e. the user name.
My understanding is that any
code running on that connection would get the same scratchpad. So
therefore.


That's not correct. Each UDF (that can have a scratchpad) gets its own
memory area. Even if you call the same UDF within a single statement more
than once, then each occurrence of the UDF would have its own, independent
scratchpad. Things become worse if the DB2 optimizer changes the plan is
such a way that the number of occurrences of the UDF changes or if you have
a partitioned environment.

For example, the following statement has 3 different, independent scratchpad
areas.

SELECT UDF1(), UDF2()
FROM table
WHERE UDF1() = <something>
You have several options to implement your scenario.
(1) Use a base table to store your data at the beginning of the connection
and remove it at the end. Of course, other connections would access the
same table and you get a bunch of problems (concurrency, how to clean up
stale entries if the application crashes, etc.) So I wouldn't do that.

(2) Use a global temporary table. At the beginning of the connection, you
create the temp table (or clean an existing one) and store the relevant
information. If the connection to DB2 is terminated (without the pooling),
then DB2 will remove the table. And global temp tables are only visible in
the current connection.

So you would do something like this:

1. DECLARE GLOBAL TEMPORARY TABLE ...
2. INSERT INTO <temp-table> ...
3. Upon insert, fire a trigger that runs a SELECT on the temp table and gets
the information you want
(3) Write your own external function to store the data somewhere else like
in the file system or shared memory. For that, you would have to resort to
Java or C/C++ code and that's not something you wanted. Besides, you will
still have to solve some problems if you have a partitioned database.
(4) You could "abuse" one of DB2's special registers like "CURRENT SCHEMA"
or so. But please be aware of the impact it may have on the SQL statement
you execute.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
5
by: Rachel Weeden | last post by:
I'm working on an ASP Web application, and am having syntax issues in a WHERE statement I'm trying to write that uses the CInt Function on a field. Basically, I want to select records using...
5
by: Thomas LeBlanc | last post by:
I copied an example from the help: CREATE FUNCTION somefunc() RETURNS integer AS ' DECLARE quantity integer := 30; BEGIN RAISE NOTICE ''Quantity here is %'', quantity; -- Quantity here is 30...
7
by: Christopher Murtagh | last post by:
Greetings, I just had to dump and restore one of my DBs (7.4RC2), and I got an interesting message. I first did: pg_dump dbname > db_restore.sql Then at console did the following:
5
by: Kivak Wolf | last post by:
Hey everyone, I have a textbox in my web page that is going to be used to enter an E-mail into (just plain text, no HTML). Now, this will interact with a SQL database where the contents of the...
7
by: RFS666 | last post by:
Hello, I would like to use variables with a type in jscript.NET. I declare them as follows: var x : double = 5.03; This doesn't work in my script, that I write to the page in codebehind with...
9
by: John Salerno | last post by:
There is an article on oreilly.net's OnLamp site called "The World's Most Maintainable Programming Language" (http://www.oreillynet.com/onlamp/blog/2006/03/the_worlds_most_maintainable_p.html). ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
84
by: aarklon | last post by:
Hi all, I found an interesting article here:- http://en.wikipedia.org/wiki/Criticism_of_the_C_programming_language well what do you guys think of this article....??? Is it constructive...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.