Random name for temp table
Posted in 2014
A stored procedure creates a fixed-name temp table ("vikas"), which breaks because a Java app funnels all users through one pooled database session, so the temp table collides. Suggestions: build the table name dynamically with EXECUTE IMMEDIATE, using a sequence's nextval, a passed-in ID, or DBINFO('sessionid') — though the session ID was ruled out since all users share one session, so a thread/cookie ID was recommended instead. For the final FOREACH over the table, Art advised replacing it with PREPARE plus DECLARE/OPEN/FETCH in a loop. No confirmation of the final working result is recorded.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Stored Procedures & SPL, Data Types & Schema Design, Java & JDBC Development
Hi All,
Informix 12.10.FC2 on HP Unix 11.31
I have a stored procedure running file for 2 years which creates a temp table
with no log
CREATE TEMP TABLE vikas(
v_sr_no SMALLINT,
v_label VARCHAR(200),v_text LVARCHAR(2000) default null) WITH NO LOG;
Now One of our developers have written a java code for GUI based application
that calls this procedure and for some reasons he has used a single session
polling login that opens a single session to the database and all the users
use this session.
There starts the trouble as the temp table is session based it cannot be used
by mutiple users and the funtion fails
Until the connection logic is fixed, Is there any way I can modify the stored
procedure to create a temp table with random name instead of the hard coded
"vikas" name
I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use it
also there is "IF NOT EXISTS" but I dont know if it has any relevance with my
issue.
Regards,
Hi,
maybe you can make a sequence, which you should increment at the start of your
routine (remember the value) and then
build a dynamic sql which creates your table, the counter appended to the
table name.
Remember, you could get out of temp dbspace depending on how many calls you
make.
In case you need the table only inside the stored procedure, you could just
add an internal column where you save the sequence
value in each insert from the actual call and then use it in any query which
reads the data as filter.
Or (depends on how often the procedure is used) drop it at the beginning of
your procedure.
The next call could drop tab results of the call before in this case, and a
non-finished call
could fail, which is not desirable.
You could also try to synchronize the calls (the second one has to wait until
the first one is finished),
using a separate table and place an explicit lock there for your transaction.
(create (non-temp) table if not existing,
insert a dummy record, update the dummy record to have a lock (hope you have
lock mod wait)).
But this is already dangerous when parallel users work on a single JDBC
connection, this is mostly not thread safe
and you can get very interesting effects in the application.
Hope this helps,
Marcus Haarmann
----- Ursprüngliche Mail -----
Von: "VIKAS HIVARKAR" <vikas.hivarkar@gmail.com>
An: ids@iiug.org
Gesendet: Donnerstag, 20. März 2014 07:41:09
Betreff: Random name for temp table [32752]
Hi All,
Informix 12.10.FC2 on HP Unix 11.31
I have a stored procedure running file for 2 years which creates a temp table
with no log
CREATE TEMP TABLE vikas(
v_sr_no SMALLINT,
v_label VARCHAR(200),v_text LVARCHAR(2000) default null) WITH NO LOG;
Now One of our developers have written a java code for GUI based application
that calls this procedure and for some reasons he has used a single session
polling login that opens a single session to the database and all the users
use this session.
There starts the trouble as the temp table is session based it cannot be used
by mutiple users and the funtion fails
Until the connection logic is fixed, Is there any way I can modify the stored
procedure to create a temp table with random name instead of the hard coded
"vikas" name
I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use it
also there is "IF NOT EXISTS" but I dont know if it has any relevance with my
issue.
Regards,
*******************************************************************************
Forum Note: Use "Reply" to post a response in the discussion forum.
create procedure make_temp() return lvarchar;define sid bigint;
define tmp_stmt, tmpname lvarchar;
select dbinfo('sessionid') into sid from sysmaster:sysdual;
let tmpname = 'vikas_" || sid::lvarchar;
let tmp_stmt = "create temp table vikas_" || tmpname || " (v_sr_no
SMALLINT,v_label VARCHAR(200), v_text LVARCHAR(2000) default null) WITH NO
LOG";
execute immediate tmp_stmt;
return tmpname;
end procedure;
Art S. Kagel, Principal Consultant
ASK Database Management
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Mar 20, 2014 at 2:41 AM, VIKAS HIVARKAR
<vikas.hivarkar@gmail.com>wrote:
> Hi All,
>
> Informix 12.10.FC2 on HP Unix 11.31
>
> I have a stored procedure running file for 2 years which creates a temp
> table
> with no log
>
> CREATE TEMP TABLE vikas(
> v_sr_no SMALLINT,
> v_label VARCHAR(200),> v_text LVARCHAR(2000) default null) WITH NO LOG;
>
> Now One of our developers have written a java code for GUI based
> application
> that calls this procedure and for some reasons he has used a single session
> polling login that opens a single session to the database and all the users
> use this session.
>
> There starts the trouble as the temp table is session based it cannot be
> used
> by mutiple users and the funtion fails
>
> Until the connection logic is fixed, Is there any way I can modify the
> stored
> procedure to create a temp table with random name instead of the hard coded
> "vikas" name
>
> I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use it
> also there is "IF NOT EXISTS" but I dont know if it has any relevance with
> my
> issue.
>
> Regards,
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--001a113373022e96b704f507fb20
Hi Art,
Your solution is simply genius, I am just thinking if the developer is opening
one session and all the users are using that session that could it be possible
that the parent session established with database remains the same and hence
the session id remains the same, In such case the vikas_<sessionid> will
remain same.
I am just simulating the scenario and will check the results.
The SP takes a integer as passed by the users and I though of using that in
the table name because it is unlikely (but still possible) that the user
searches for the same integer
> drop procedure create_tab (integer);
Routine dropped.
> CREATE PROCEDURE create_tab (table_name integer)> DEFINE l_crtstmt CHAR(1024);
> LET l_crtstmt = "CREATE TEMP TABLE vikas_" ||table_name|| "(col1 integer)";
> EXECUTE IMMEDIATE l_crtstmt;
> END PROCEDURE;
Routine created.
> EXECUTE PROCEDURE create_tab (12345);
Routine executed.
> select count(*) from vikas_12345;
(count(*))
0
1 row(s) retrieved.
This is exactly what you suggested using dynamic prepare statement and will
use the integer as passed by the users but still not fool proof.
I dont know if there is a ready made function in v12 that gives me a random
number which is very unlikely to repeat in quick successions
Regards,
Vikas
============================================================================
create procedure make_temp() return lvarchar;define sid bigint;
define tmp_stmt, tmpname lvarchar;
select dbinfo('sessionid') into sid from sysmaster:sysdual;
let tmpname = 'vikas_" || sid::lvarchar;
let tmp_stmt = "create temp table vikas_" || tmpname || " (v_sr_no
SMALLINT,v_label VARCHAR(200), v_text LVARCHAR(2000) default null) WITH NO
LOG";
execute immediate tmp_stmt;
return tmpname;
end procedure;
Art S. Kagel, Principal Consultant
ASK Database Management
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Mar 20, 2014 at 2:41 AM, VIKAS HIVARKAR
<vikas.hivarkar@gmail.com>wrote:
> Hi All,
>
> Informix 12.10.FC2 on HP Unix 11.31
>
> I have a stored procedure running file for 2 years which creates a temp
> table
> with no log
>
> CREATE TEMP TABLE vikas(
> v_sr_no SMALLINT,
> v_label VARCHAR(200),> v_text LVARCHAR(2000) default null) WITH NO LOG;
>
> Now One of our developers have written a java code for GUI based
> application
> that calls this procedure and for some reasons he has used a single session
> polling login that opens a single session to the database and all the users
> use this session.
>
> There starts the trouble as the temp table is session based it cannot be
> used
> by mutiple users and the funtion fails
>
> Until the connection logic is fixed, Is there any way I can modify the
> stored
> procedure to create a temp table with random name instead of the hard coded
> "vikas" name
>
> I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use it
> also there is "IF NOT EXISTS" but I dont know if it has any relevance with
> my
> issue.
>
> Regards,
create sequence seq_vikas;
DEFINE number as Integer;
select seq_vikas.nextval into number from sysdual;
... proceed as indicated using dynamic ddl.
Best regards,
Marcus Haarmann
----- Ursprüngliche Mail -----
Von: "VIKAS HIVARKAR" <vikas.hivarkar@gmail.com>
An: ids@iiug.org
Gesendet: Donnerstag, 20. März 2014 19:16:34
Betreff: Re: Random name for temp table [32758]
Hi Art,
Your solution is simply genius, I am just thinking if the developer is opening
one session and all the users are using that session that could it be possible
that the parent session established with database remains the same and hence
the session id remains the same, In such case the vikas_<sessionid> will
remain same.
I am just simulating the scenario and will check the results.
The SP takes a integer as passed by the users and I though of using that in
the table name because it is unlikely (but still possible) that the user
searches for the same integer
> drop procedure create_tab (integer);
Routine dropped.
> CREATE PROCEDURE create_tab (table_name integer)> DEFINE l_crtstmt CHAR(1024);
> LET l_crtstmt = "CREATE TEMP TABLE vikas_" ||table_name|| "(col1 integer)";
> EXECUTE IMMEDIATE l_crtstmt;
> END PROCEDURE;
Routine created.
> EXECUTE PROCEDURE create_tab (12345);
Routine executed.
> select count(*) from vikas_12345;
(count(*))
0
1 row(s) retrieved.
This is exactly what you suggested using dynamic prepare statement and will
use the integer as passed by the users but still not fool proof.
I dont know if there is a ready made function in v12 that gives me a random
number which is very unlikely to repeat in quick successions
Regards,
Vikas
============================================================================
create procedure make_temp() return lvarchar;define sid bigint;
define tmp_stmt, tmpname lvarchar;
select dbinfo('sessionid') into sid from sysmaster:sysdual;
let tmpname = 'vikas_" || sid::lvarchar;
let tmp_stmt = "create temp table vikas_" || tmpname || " (v_sr_no
SMALLINT,v_label VARCHAR(200), v_text LVARCHAR(2000) default null) WITH NO
LOG";
execute immediate tmp_stmt;
return tmpname;
end procedure;
Art S. Kagel, Principal Consultant
ASK Database Management
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Mar 20, 2014 at 2:41 AM, VIKAS HIVARKAR
<vikas.hivarkar@gmail.com>wrote:
> Hi All,
>
> Informix 12.10.FC2 on HP Unix 11.31
>
> I have a stored procedure running file for 2 years which creates a temp
> table
> with no log
>
> CREATE TEMP TABLE vikas(
> v_sr_no SMALLINT,
> v_label VARCHAR(200),> v_text LVARCHAR(2000) default null) WITH NO LOG;
>
> Now One of our developers have written a java code for GUI based
> application
> that calls this procedure and for some reasons he has used a single session
> polling login that opens a single session to the database and all the users
> use this session.
>
> There starts the trouble as the temp table is session based it cannot be
> used
> by mutiple users and the funtion fails
>
> Until the connection logic is fixed, Is there any way I can modify the
> stored
> procedure to create a temp table with random name instead of the hard coded
> "vikas" name
>
> I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use it
> also there is "IF NOT EXISTS" but I dont know if it has any relevance with
> my
> issue.
>
> Regards,
*******************************************************************************
Forum Note: Use "Reply" to post a response in the discussion forum.
Duh, of course, you did say it was all in the same session.. I was
originally going to have the proc use the userid of the actual user to name
the temp table, but thought better of that as each user could have more
than one connection to the java service so opted for session id which won't
work <sigh>. OK, um how about the java thread id for the thread servicing
the particular client or whatever cookie value the service is using to link
the data back to the correct user? Pass that into the function and build
the temp table name from that. You can also have a proc to drop the temp
tables that are no longer needed when the users' connection to the service
is broken.
Art
Art S. Kagel, Principal Consultant
ASK Database Management
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Mar 20, 2014 at 2:16 PM, VIKAS HIVARKAR
<vikas.hivarkar@gmail.com>wrote:
> Hi Art,
>
> Your solution is simply genius, I am just thinking if the developer is
> opening
> one session and all the users are using that session that could it be
> possible
> that the parent session established with database remains the same and
> hence
> the session id remains the same, In such case the vikas_<sessionid> will
> remain same.
>
> I am just simulating the scenario and will check the results.
>
> The SP takes a integer as passed by the users and I though of using that in
> the table name because it is unlikely (but still possible) that the user
> searches for the same integer
>
> > drop procedure create_tab (integer);>
> Routine dropped.
>
> > CREATE PROCEDURE create_tab (table_name integer)> > DEFINE l_crtstmt CHAR(1024);
> > LET l_crtstmt = "CREATE TEMP TABLE vikas_" ||table_name|| "(col1
> integer)";
> > EXECUTE IMMEDIATE l_crtstmt;
> > END PROCEDURE;
>
> Routine created.
>
> > EXECUTE PROCEDURE create_tab (12345);>
> Routine executed.
>
> > select count(*) from vikas_12345;>
> (count(*))
>
> 0
>
> 1 row(s) retrieved.
>
> This is exactly what you suggested using dynamic prepare statement and will
> use the integer as passed by the users but still not fool proof.
>
> I dont know if there is a ready made function in v12 that gives me a random
> number which is very unlikely to repeat in quick successions
>
> Regards,
> Vikas
>
>
> ============================================================================
>
> create procedure make_temp() return lvarchar;> define sid bigint;
> define tmp_stmt, tmpname lvarchar;
>
> select dbinfo('sessionid') into sid from sysmaster:sysdual;
>
> let tmpname = 'vikas_" || sid::lvarchar;
>
> let tmp_stmt = "create temp table vikas_" || tmpname || " (v_sr_no
> SMALLINT,v_label VARCHAR(200), v_text LVARCHAR(2000) default null) WITH NO
> LOG";
>
> execute immediate tmp_stmt;
> return tmpname;
>
> end procedure;
>
> Art S. Kagel, Principal Consultant
> ASK Database Management
>
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on the IIUG, nor any other organization with which I am
> associated either explicitly, implicitly, or by inference. Neither do
> those opinions reflect those of other individuals affiliated with any
> entity with which I am affiliated nor those of the entities themselves.
>
> On Thu, Mar 20, 2014 at 2:41 AM, VIKAS HIVARKAR
> <vikas.hivarkar@gmail.com>wrote:
>
> > Hi All,
> >
> > Informix 12.10.FC2 on HP Unix 11.31
> >
> > I have a stored procedure running file for 2 years which creates a temp
> > table
> > with no log
> >
> > CREATE TEMP TABLE vikas(
> > v_sr_no SMALLINT,
> > v_label VARCHAR(200),> > v_text LVARCHAR(2000) default null) WITH NO LOG;
> >
> > Now One of our developers have written a java code for GUI based
> > application
> > that calls this procedure and for some reasons he has used a single
> session
> > polling login that opens a single session to the database and all the
> users
> > use this session.
> >
> > There starts the trouble as the temp table is session based it cannot be
> > used
> > by mutiple users and the funtion fails
> >
> > Until the connection logic is fixed, Is there any way I can modify the
> > stored
> > procedure to create a temp table with random name instead of the hard
> coded
> > "vikas" name
> >
> > I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use
> it
> > also there is "IF NOT EXISTS" but I dont know if it has any relevance
> with
> > my
> > issue.
> >
> > Regards,
>
>
>
>
*******************************************************************************
> Forum Note: Use "Reply" to post a response in the discussion forum.
>
>
--001a113476de9f607e04f50df68b
Hi Art and Marcus
I am just trying with the dynamic statement testing in the SP however there
are 14 places this table is used in an "INSERT INTO vikas......" and I believe
all these INSERTS will also have to be prepared dynamically which is easy but
I am struggling with the last part of SP with also need the temp table "vikas"
ORIGINAL SNIPPET
FOREACH cursor for SELECT (NVL(v_label, ' ') ||' '||'::'||' '|| NVL(v_text, '
'))
INTO v_output
FROM vikas
ORDER BY v_sr_no
RETURN v_output WITH RESUME;
END FOREACH;
I am trying different ways to replace this in to a dynamic statement and
execute but every option I try gives me a syntax error on the RETURN or END
FOREACH line;
Regards,
=============================================================================
Duh, of course, you did say it was all in the same session.. I was
originally going to have the proc use the userid of the actual user to name
the temp table, but thought better of that as each user could have more
than one connection to the java service so opted for session id which won't
work <sigh>. OK, um how about the java thread id for the thread servicing
the particular client or whatever cookie value the service is using to link
the data back to the correct user? Pass that into the function and build
the temp table name from that. You can also have a proc to drop the temp
tables that are no longer needed when the users' connection to the service
is broken.
Art
Art S. Kagel, Principal Consultant
ASK Database Management
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Mar 20, 2014 at 2:16 PM, VIKAS HIVARKAR
<vikas.hivarkar@gmail.com>wrote:
> Hi Art,
>
> Your solution is simply genius, I am just thinking if the developer is
> opening
> one session and all the users are using that session that could it be
> possible
> that the parent session established with database remains the same and
> hence
> the session id remains the same, In such case the vikas_<sessionid> will
> remain same.
>
> I am just simulating the scenario and will check the results.
>
> The SP takes a integer as passed by the users and I though of using that in
> the table name because it is unlikely (but still possible) that the user
> searches for the same integer
>
> > drop procedure create_tab (integer);>
> Routine dropped.
>
> > CREATE PROCEDURE create_tab (table_name integer)> > DEFINE l_crtstmt CHAR(1024);
> > LET l_crtstmt = "CREATE TEMP TABLE vikas_" ||table_name|| "(col1
> integer)";
> > EXECUTE IMMEDIATE l_crtstmt;
> > END PROCEDURE;
>
> Routine created.
>
> > EXECUTE PROCEDURE create_tab (12345);>
> Routine executed.
>
> > select count(*) from vikas_12345;>
> (count(*))
>
> 0
>
> 1 row(s) retrieved.
>
> This is exactly what you suggested using dynamic prepare statement and will
> use the integer as passed by the users but still not fool proof.
>
> I dont know if there is a ready made function in v12 that gives me a random
> number which is very unlikely to repeat in quick successions
>
> Regards,
> Vikas
>
>
> ============================================================================
>
> create procedure make_temp() return lvarchar;> define sid bigint;
> define tmp_stmt, tmpname lvarchar;
>
> select dbinfo('sessionid') into sid from sysmaster:sysdual;
>
> let tmpname = 'vikas_" || sid::lvarchar;
>
> let tmp_stmt = "create temp table vikas_" || tmpname || " (v_sr_no
> SMALLINT,v_label VARCHAR(200), v_text LVARCHAR(2000) default null) WITH NO
> LOG";
>
> execute immediate tmp_stmt;
> return tmpname;
>
> end procedure;
>
> Art S. Kagel, Principal Consultant
> ASK Database Management
>
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on the IIUG, nor any other organization with which I am
> associated either explicitly, implicitly, or by inference. Neither do
> those opinions reflect those of other individuals affiliated with any
> entity with which I am affiliated nor those of the entities themselves.
>
> On Thu, Mar 20, 2014 at 2:41 AM, VIKAS HIVARKAR
> <vikas.hivarkar@gmail.com>wrote:
>
> > Hi All,
> >
> > Informix 12.10.FC2 on HP Unix 11.31
> >
> > I have a stored procedure running file for 2 years which creates a temp
> > table
> > with no log
> >
> > CREATE TEMP TABLE vikas(
> > v_sr_no SMALLINT,
> > v_label VARCHAR(200),> > v_text LVARCHAR(2000) default null) WITH NO LOG;
> >
> > Now One of our developers have written a java code for GUI based
> > application
> > that calls this procedure and for some reasons he has used a single
> session
> > polling login that opens a single session to the database and all the
> users
> > use this session.
> >
> > There starts the trouble as the temp table is session based it cannot be
> > used
> > by mutiple users and the funtion fails
> >
> > Until the connection logic is fixed, Is there any way I can modify the
> > stored
> > procedure to create a temp table with random name instead of the hard
> coded
> > "vikas" name
> >
> > I was looking for the funtion DBMS_RANDOM_RANDOM but not sure how to use
> it
> > also there is "IF NOT EXISTS" but I dont know if it has any relevance
> with
> > my
> > issue.
> >
> > Regards,
Don't use a FOREACH. Build the SELECT in a string, PREPARE it, DECLARE a
cursor against the prepared statement, then OPEN cursorname and use a FOR
or WHILE loop to FETCH cursorname INTO ... inside the loop, EXIT out of the
look if SQLCODE != 0 after the FETCH, RETURN whatever you need to return,
then CLOSE the cursor and FREE it before returning from the function. You
can check error conditions using SQLCODE as well when it is < 0 (100 ==
end-of-data).
Here's a link to an article about this:
http://www.ibm.com/developerworks/data/library/techarticle/dm-0806mottupalli/ind
ex.html
Art
Art S. Kagel, Principal Consultant
ASK Database Management
Blog: http://informix-myview.blogspot.com/
Disclaimer: Please keep in mind that my own opinions are my own opinions
and do not reflect on the IIUG, nor any other organization with which I am
associated either explicitly, implicitly, or by inference. Neither do
those opinions reflect those of other individuals affiliated with any
entity with which I am affiliated nor those of the entities themselves.
On Thu, Mar 20, 2014 at 4:03 PM, VIKAS HIVARKAR
<vikas.hivarkar@gmail.com>wrote:
> Hi Art and Marcus
>
> I am just trying with the dynamic statement testing in the SP however there
> are 14 places this table is used in an "INSERT INTO vikas......" and I
> believe
> all these INSERTS will also have to be prepared dynamically which is easy
> but
> I am struggling with the last part of SP with also need the temp table
> "vikas"
>
> ORIGINAL SNIPPET
>
> FOREACH cursor for SELECT (NVL(v_label, ' ') ||' '||'::'||' '||
> NVL(v_text, '
> '))
>
> INTO v_output
>
> FROM vikas
>
> ORDER BY v_sr_no
>
> RETURN v_output WITH RESUME;
>
> END FOREACH;
>
> I am trying different ways to replace this in to a dynamic statement and
> execute but every option I try gives me a syntax error on the RETURN or END
> FOREACH line;
>
> Regards,
>
>
> =============================================================================
>
> Duh, of course, you did say it was all in the same session.. I was
> originally going to have the proc use the userid of the actual user to name
> the temp table, but thought better of that as each user could have more
> than one connection to the java service so opted for session id which won't
> work <sigh>. OK, um how about the java thread id for the thread servicing
> the particular client or whatever cookie value the service is using to link
> the data back to the correct user? Pass that into the function and build
> the temp table name from that. You can also have a proc to drop the temp
> tables that are no longer needed when the users' connection to the service
> is broken.
>
> Art
>
> Art S. Kagel, Principal Consultant
> ASK Database Management
>
> Blog: http://informix-myview.blogspot.com/
>
> Disclaimer: Please keep in mind that my own opinions are my own opinions
> and do not reflect on the IIUG, nor any other organization with which I am
> associated either explicitly, implicitly, or by inference. Neither do
> those opinions reflect those of other individuals affiliated with any
> entity with which I am affiliated nor those of the entities themselves.
>
> On Thu, Mar 20, 2014 at 2:16 PM, VIKAS HIVARKAR
> <vikas.hivarkar@gmail.com>wrote:
>
> > Hi Art,
> >
> > Your solution is simply genius, I am just thinking if the developer is
> > opening
> > one session and all the users are using that session that could it be
> > possible
> > that the parent session established with database remains the same and
> > hence
> > the session id remains the same, In such case the vikas_<sessionid> will
> > remain same.
> >
> > I am just simulating the scenario and will check the results.
> >
> > The SP takes a integer as passed by the users and I though of using that
> in
> > the table name because it is unlikely (but still possible) that the user
> > searches for the same integer
> >
> > > drop procedure create_tab (integer);> >
> > Routine dropped.
> >
> > > CREATE PROCEDURE create_tab (table_name integer)> > > DEFINE l_crtstmt CHAR(1024);
> > > LET l_crtstmt = "CREATE TEMP TABLE vikas_" ||table_name|| "(col1
> > integer)";
> > > EXECUTE IMMEDIATE l_crtstmt;
> > > END PROCEDURE;
> >
> > Routine created.
> >
> > > EXECUTE PROCEDURE create_tab (12345);> >
> > Routine executed.
> >
> > > select count(*) from vikas_12345;> >
> > (count(*))
> >
> > 0
> >
> > 1 row(s) retrieved.
> >
> > This is exactly what you suggested using dynamic prepare statement and
> will
> > use the integer as passed by the users but still not fool proof.
> >
> > I dont know if there is a ready made function in v12 that gives me a
> random
> > number which is very unlikely to repeat in quick successions
> >
> > Regards,
> > Vikas
> >
> >
> >
> ============================================================================
> >
> > create procedure make_temp() return lvarchar;> > define sid bigint;
> > define tmp_stmt, tmpname lvarchar;
> >
> > select dbinfo('sessionid') into sid from sysmaster:sysdual;
> >
> > let tmpname = 'vikas_" || sid::lvarchar;
> >
> > let tmp_stmt = "create temp table vikas_" || tmpname || " (v_sr_no
> > SMALLINT,v_label VARCHAR(200), v_text LVARCHAR(2000) default null) WITH
> NO
> > LOG";
> >
> > execute immediate tmp_stmt;
> > return tmpname;
> >
> > end procedure;
> >
> > Art S. Kagel, Principal Consultant
> > ASK Database Management
> >
> > Blog: http://informix-myview.blogspot.com/
> >
> > Disclaimer: Please keep in mind that my own opinions are my own opinions
> > and do not reflect on the IIUG, nor any other organization with which I
> am
> > associated either explicitly, implicitly, or by inference. Neither do
> > those opinions reflect those of other individuals affiliated with any
> > entity with which I am affiliated nor those of the entities themselves.
> >
> > On Thu, Mar 20, 2014 at 2:41 AM, VIKAS HIVARKAR
> > <vikas.hivarkar@gmail.com>wrote:
> >
> > > Hi All,
> > >
> > > Informix 12.10.FC2 on HP Unix 11.31
> > >
> > > I have a stored procedure running file for 2 years which creates a temp
> > > table
> > > with no log
> > >
> > > CREATE TEMP TABLE vikas(
> > > v_sr_no SMALLINT,
> > > v_label VARCHAR(200),> > > v_text LVARCHAR(2000) default null) WITH NO LOG;
> > >
> > > Now One of our developers have written a java code for GUI based
> > > application
> > > that calls this procedure and for some reasons he has used a single
> > session
> > > polling login that opens a single session to the database and all the
> > users
> > > use this session.
> > >
> > > There starts the trouble as the temp table is session based it cannot
> be
> > > used
> > > by mutiple users and the funtion fails
> > >
> > > Until the connection logic is fixed, Is there any way I can modify the
> > > stored
> > > procedure to create a temp tab