"Mahdi A. Sbeih" wrote:

> Hi all,
>
> I am trying to access an Informix database, that I have only connect
> permissions,
> and I am trying to 'eval' the code below, but for some reason that I can't
> identify,
> no error occurred in the first 2 select statements, the error occurred at
> third
> SQL statement, which is drop table. When running any of the first 2 select
> statments manually, I got
> an error that I don't have permissions.

With Informix databases, CONNECT permission does not allow you to drop tables
unless they are temporary tables (which, by definition, you created).  If you
need to change the schema of the database, you need RESOURCE or possibly DBA
privileges.  In most databases, most of the time, you can select from most
tables without error.  Hence, your observed behaviour is reasonable.

Check the Informix Guide to SQL: Syntax, available from
http://www.informix.com/answers.

With regard to the code - why not simply try to select the list of 'run*' table
names and delete each one in turn, reporting none to drop if you don't get any
data back.  This is generally (marginally) more efficient than the count then
select mechanism.  It is also more reliable; if someone creates a table with the
'run' prefix after the count is executed, you won't drop it -- though you can
also argue that there's a possibility that someone creates a 'run' table after
you execute the plain select loop.


> What I am expecting is to exit the eval block from the first SQL statement
> since I don't have permissions.

You always have permission to select from the system catalog.


> I can't identify the problem, is it from the DBI or DBD::Informix, that not
> catching the error.

Neither; it is a conceptual problem in the design of your code, I'm afraid.  You
can select from the system catalog, so you can run the SELECT statements without
error.  You can't modify the system catalog, either directly (UPDATE
Systables...) or indirectly (DROP TABLE ...), so when you attempt to do so, you
get an error.

If you really want to write the SQL such that you only retrieve the table names
for which you have the ability to drop the table, then you have to deal with a
much more complex query.  Much, much, much more complex query.  For starters,
you'd have to look at SysUsers to determine which privileges you (or user
PUBLIC) has on the database.   You also need to know whether there is a current
role set, and check what privileges that role has.  Assuming that some
combination of user and role has sufficient privilege (RESOURCE or DBA) to alter
the schema, then you have to check whether the current user or role has
sufficient privilege on the table to drop it -- which usually requires DBA or
ownership of the table, and maybe ALTER privilege is sufficient too.  Yuck!


> Regards,
> Mahdi.
> #########################################################
>
>                 my ($run_tab_count);
>                 my ($sql_stmt_drop_run_cnt);
>                 my ($tab_type)          = 'T';
>                 my ($tab_name_like)     = 'run%';
>                 my (@tab_names_array)   = ();
>                 my ($run_tab_name);
> ### Starting the eval Block
>                 eval {
>                         ### Quote String Variables
>                         my($quoted_tab_type)            =
> $db_handle->quote($tab_type);
>                         my($quoted_tab_name_like)       =
> $db_handle->quote($tab_name_like);
>
>                         $run_tab_count                  =
> $db_handle->selectrow_array("
>
> select count(*)
>
> from systables
>
> where tabname like $quoted_tab_name_like
>
> AND tabtype = $quoted_tab_type
>
> ");
>                         if ($run_tab_count == 0)
>                                 {
>                                         print("\nNo RUN Tables Found In The
> Database.\n\n");
>                                         return;
>                                 }
>
>                         $sql_stmt_drop_run_cnt          =
> $db_handle->prepare("
>
> select tabname
>
> from systables
>
> where tabname like $quoted_tab_name_like
>
> AND tabtype = $quoted_tab_type
>
> ");
>                         $sql_stmt_drop_run_cnt->execute();
>                         while ( $run_tab_name =
> $sql_stmt_drop_run_cnt->fetchrow_array )
>                                 {
>                                         # dropping RUN... tables one at a
> time
>                                         print("\nDropping table
> $run_tab_name...\t");
>
>                                         $db_handle->do("
>                                                         drop table
> $run_tab_name
>                                                         ");
>
>                                         print("dropped.");
>                                 }
>                         print("\n\nRUN tables dropped successfully....\n");
>
>                         }; # End eval Block...
>
>                 if ($@)
>                         {
>                                 ++$no_of_errors;
>                                 print LOGFILE "E:\t";
>                                 error_log();
>                                 ### Disconnect and Exit
>                                 connection_function(2);
>                         }
>
> ##########################################################
>
> -----Original Message-----
> From: pkp team [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 02, 2001 12:02 PM
> To: [EMAIL PROTECTED]
> Subject: DBI error
>
> Hello all:

>[Irrelevant message deleted]




--
Jonathan Leffler ([EMAIL PROTECTED], [EMAIL PROTECTED])
Guardian of DBD::Informix 1.00.PC1 -- see http://www.cpan.org/
#include <disclaimer.h>


Reply via email to