![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Folks: I have a need to detect and drop temporary tables from SQL if they exist in my session. It's the standard IF EXISTS temp_table_x THEN DROP TABLE temp_table_x; END IF; SELECT ... INTO TEMP temp_table_x; logic. I am aware that temporary tables are automatically dropped when the session closes. This does not help as I cannot guarantee the SP that creates a given temporary table will only be called once per session. Connection pooling and other connection-reusing client application behaviors must be dealt with gracefully. Simply ignoring the error that dropping a nonexistent table generates causes problems if something else blows up, as that will cause the error generated by a "SELECT ... FROM table_that_should_exist_but_doesnt;" query to be ignored. This is not acceptable behavior, as it can lead to silent failure. I've been googling, but all of the solutions I've found so far that involve trolling around in sysmaster to enumerate temporary tables are not reliably session-specific. Surely "onstat -g ses" must be querying the information from the system tables _somehow_! How do I duplicate that logic? I hate to say this but because of the partial solutions provided to others who have asked this question in the past I want to be perfectly clear: Parsing the output of "onstat -g ses" is not an option, as this is for use within a stored procedure. Please don't suggest anything that is not session-specific. Any query that solves this problem is going to involve dbinfo('sessionid') at some point, and must not return results if a temporary table with the name in question has been created in a different session but not in the current session. It also cannot rely on username to differentiate the temporary tables, multiple different sessions may be using the same username to connect to the database and run the same stored procedure. Thanks in advance to anybody who can describe how this could be done. -- John Hardin KA7OHZ Senior Applications Developer, BI Specialist EPICOR Retail web: http://www.epicor.com voice: (425) 245-1800 fax: (425) 670-1810 email: <jhardin (AT) epicor (DOT) com 20818 44th Ave. W., Suite 270 Lynnwood, WA 98036 USA Worldwide Headquarters 18200 Von Karman, Suite 1000, Irvine CA 92612 USA ------------------------------------------------------------------------ The first time I saw a bagpipe, I thought the player was torturing an octopus. I was amazed they could scream so loudly. ------------------------------------------------------------------------ --- news://freenews.netfront.net/ - complaints: news (AT) netfront (DOT) net --- _______________________________________________ Informix-list mailing list Informix-list (AT) iiug (DOT) org http://www.iiug.org/mailman/listinfo/informix-list |
#3
| |||
| |||
|
|
Folks: I have a need to detect and drop temporary tables from SQL if they exist in my session. It's the standard IF EXISTS temp_table_x THEN DROP TABLE temp_table_x; END IF; SELECT ... INTO TEMP temp_table_x; logic. I am aware that temporary tables are automatically dropped when the session closes. This does not help as I cannot guarantee the SP that creates a given temporary table will only be called once per session. Connection pooling and other connection-reusing client application behaviors must be dealt with gracefully. Simply ignoring the error that dropping a nonexistent table generates causes problems if something else blows up, as that will cause the error generated by a "SELECT ... FROM table_that_should_exist_but_doesnt;" query to be ignored. This is not acceptable behavior, as it can lead to silent failure. I've been googling, but all of the solutions I've found so far that involve trolling around in sysmaster to enumerate temporary tables are not reliably session-specific. Surely "onstat -g ses" must be querying the information from the system tables _somehow_! How do I duplicate that logic? I hate to say this but because of the partial solutions provided to others who have asked this question in the past I want to be perfectly clear: Parsing the output of "onstat -g ses" is not an option, as this is for use within a stored procedure. Please don't suggest anything that is not session-specific. Any query that solves this problem is going to involve dbinfo('sessionid') at some point, and must not return results if a temporary table with the name in question has been created in a different session but not in the current session. It also cannot rely on username to differentiate the temporary tables, multiple different sessions may be using the same username to connect to the database and run the same stored procedure. Thanks in advance to anybody who can describe how this could be done. |
#4
| |||
| |||
|
|
On Thu, Jan 28, 2010 at 8:44 PM, John Hardin <jhardin (AT) epicor (DOT) com> wrote: I have a need to detect and drop temporary tables from SQL if they exist in my session. The only way to do this in an SPL routine is to DROP the temp table at the beginning of the routine, but trap the -206 error that occurs when the table is not found and ignore it. Then continue to create the temp table as if it had been dropped successfully. Not elegant, but it's the only way that works. |
#5
| |||
| |||
|
|
"Art Kagel" <art.kagel (AT) gmail (DOT) com> wrote in message news:mailman.509.1264734584.6236.informix-list (AT) iiug (DOT) org... On Thu, Jan 28, 2010 at 8:44 PM, John Hardin <jhardin (AT) epicor (DOT) com> wrote: I have a need to detect and drop temporary tables from SQL if they exist in my session. The only way to do this in an SPL routine is to DROP the temp table at the beginning of the routine, but trap the -206 error that occurs when the table is not found and ignore it. Then continue to create the temp table as if it had been dropped successfully. Not elegant, but it's the only way that works. It doesn't work very well. How do you restore trapping of -206 exceptions so that valid errors of that sort in the stored procedure are properly trapped? Ignoring exceptions generated for what arguably should not even _be_ an error in the first place will also ignore valid exceptions that do indicate serious problems in the process that need to be fixed. -- John Hardin KA7OHZ Senior Applications Developer, BI Specialist EPICOR Retail web: http://www.epicor.com voice: (425) 245-1800 fax: (425) 670-1810 email: <jhardin (AT) epicor (DOT) com 20818 44th Ave. W., Suite 270 Lynnwood, WA 98036 USA Worldwide Headquarters 18200 Von Karman, Suite 1000, Irvine CA 92612 USA ------------------------------------------------------------------------ The first time I saw a bagpipe, I thought the player was torturing an octopus. I was amazed they could scream so loudly. ------------------------------------------------------------------------ --- news://freenews.netfront.net/ - complaints: news (AT) netfront (DOT) net --- _______________________________________________ Informix-list mailing list Informix-list (AT) iiug (DOT) org http://www.iiug.org/mailman/listinfo/informix-list |
#6
| |||
| |||
|
|
On Fri, Jan 29, 2010 at 3:51 PM, John Hardin <jhardin (AT) epicor (DOT) com> wrote: "Art Kagel" <art.kagel (AT) gmail (DOT) com> wrote in message news:mailman.509.1264734584.6236.informix-list (AT) iiug (DOT) org... On Thu, Jan 28, 2010 at 8:44 PM, John Hardin <jhardin (AT) epicor (DOT) com wrote: I have a need to detect and drop temporary tables from SQL if they exist in my session. The only way to do this in an SPL routine is to DROP the temp table at the beginning of the routine, but trap the -206 error that occurs when the table is not found and ignore it. Then continue to create the temp table as if it had been dropped successfully. Not elegant, but it's the only way that works. It doesn't work very well. How do you restore trapping of -206 exceptions so that valid errors of that sort in the stored procedure are properly trapped? Ignoring exceptions generated for what arguably should not even _be_ an error in the first place will also ignore valid exceptions that do indicate serious problems in the process that need to be fixed. LET flag=1 DROP TABLE temp_table LET flag=0 |

#7
| |||
| |||
|
|
"Fernando Nunes" <domusonl... (AT) gmail (DOT) com> wrote in message news:mailman.512.1264785176.6236.informix-list (AT) iiug (DOT) org... On Fri, Jan 29, 2010 at 3:51 PM, John Hardin <jhar... (AT) epicor (DOT) com> wrote: "Art Kagel" <art.ka... (AT) gmail (DOT) com> wrote in message news:mailman.509.1264734584.6236.informix-list (AT) iiug (DOT) org... On Thu, Jan 28, 2010 at 8:44 PM, John Hardin <jhar... (AT) epicor (DOT) com wrote: I have a need to detect and drop temporary tables from SQL if they exist in my session. The only way to do this in an SPL routine is to DROP the temp table at the beginning of the routine, but trap the -206 error that occurs when the table is not found and ignore it. *Then continue to create thetemp table as if it had been dropped successfully. *Not elegant, but it's the only way that works. It doesn't work very well. How do you restore trapping of -206 exceptions so that valid errors of that sort in the stored procedure are properly trapped? Ignoring exceptions generated for what arguably should not even _be_ an error in the first place will also ignore valid exceptions that do indicate serious problems in the process that need to be fixed. LET flag=1 DROP TABLE temp_table LET flag=0 That works, but... eww. ![]() As an elegant solution is apparently impossible, I've just restructured all my SPs so that the DROP TABLEs are isolated in a helper SP that does nothing but ignore the -206 exception and drop the list of temporary tables that the primary SP will be creating. I'd hoped to avoid doing that, but I think it's the least disgusting hack to achieve this. Can anybody tell my _why_ that even throws an exception in the first place? It's not logically defensible to generate an error because you've been asked to delete something that does not exist - the end state of that failure mode is identical to the end state of a success! |
#8
| |||
| |||
|
|
"Art Kagel" <art.ka... (AT) gmail (DOT) com> wrote in message news:mailman.509.1264734584.6236.informix-list (AT) iiug (DOT) org... On Thu, Jan 28, 2010 at 8:44 PM, John Hardin <jhar... (AT) epicor (DOT) com> wrote: I have a need to detect and drop temporary tables from SQL if they exist in my session. The only way to do this in an SPL routine is to DROP the temp table at the beginning of the routine, but trap the -206 error that occurs when the table is not found and ignore it. *Then continue to create the temp table as if it had been dropped successfully. *Not elegant, but it's the only way that works. It doesn't work very well. How do you restore trapping of -206 exceptionsso that valid errors of that sort in the stored procedure are properly trapped? Ignoring exceptions generated for what arguably should not even _be_ an error in the first place will also ignore valid exceptions that do indicate serious problems in the process that need to be fixed. -- John Hardin KA7OHZ Senior Applications Developer, BI SpecialistEPICORRetail * web:http://www.epicor.com voice: (425) 245-1800 * fax: (425) 670-1810 email: <jhar... (AT) epicor (DOT) com 20818 44th Ave. W., Suite 270 Lynnwood, WA 98036 USA Worldwide Headquarters 18200 Von Karman, Suite 1000, Irvine CA 92612 USA ------------------------------------------------------------------------ *The first time I saw a bagpipe, I thought the player was torturing an *octopus. I was amazed they could scream so loudly. ------------------------------------------------------------------------ --- news://freenews.netfront.net/ - complaints: n... (AT) netfront (DOT) net --- |
![]() |
| Thread Tools | |
| Display Modes | |
| |