List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 5 2003 2:34am
Subject:Re: Temporary Tables
View as plain text  
At 12:08 +1100 3/5/03, Daniel Kasak wrote:
>Paul DuBois wrote:
>
>>That is, you're making an assumption that cannot necessarily be made.
>>If you can guarantee that the web script will establish a new connection,
>>and the connection will terminate when the script ends, you can indeed
>>do what you describe above.
>>
>>But you *cannot* do that if you're running your script in an environment
>>that uses persistent connections that may be used by successive instances
>>of the script.  PHP persistent connections fall into this class, for
>>example.  Several requests might be served by the same instance of the
>>web server process, and you don't know that one request won't be getting
>>the connection used by a previous request.  In that case, the connection
>>won't have closed, and the TEMPORARY table won't have disappeared.
>>
>>You can guard against this by issuing this query before creating the
>>TEMPORARY table:
>>
>>DROP TABLE IF EXISTS tbl_name
>
>In this case I would actually use unique table names.
>If you have a web server that is set up to use persistant database 
>connections and there is a chance that 2 clients may run the same 
>script in the same connection, then dropping the tmp table isn't 
>going to solve all of your problems. You can't have the 2nd instance 
>of the script screwing with the 1st. If you have some form of unique 
>identifier, then append it to the table name. Otherwise consider 
>creating your own (and testing for it's existance before using it) 
>and appending it to the table name.

Dropping the table before attempting to use it eliminates any need to
come up with a unique name.

Two clients *cannot* run the same script at the same time, *unless* they
are being executed by different web server processes.  In that case, they'll
be using different connections, and a temporary table created by one
connection cannot be seen by the other connection.

>--
>Daniel Kasak
>IT Developer
>* NUS Consulting Group*
>Level 18, 168 Walker Street
>North Sydney, NSW, Australia 2060
>T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
>email: dkasak@stripped
>website: www.nusconsulting.com

Thread
Temporary TablesMamatha Balasubramanian5 Mar
  • Re: Temporary TablesPaul DuBois5 Mar
  • Re: Temporary TablesDaniel Kasak5 Mar
Re: Temporary TablesMamatha Balasubramanian5 Mar
  • Re: Temporary TablesPaul DuBois5 Mar
    • Re: Temporary TablesWilliam R. Mussatto5 Mar
      • Re: Temporary TablesPaul DuBois5 Mar
    • Re: Temporary TablesKH Chiu5 Mar
    • Re: Temporary TablesDaniel Kasak5 Mar
      • Re: Temporary TablesPaul DuBois5 Mar
Re: Temporary TablesMamatha Balasubramanian5 Mar