Обсуждение: DBD::PG question

Поиск
Список
Период
Сортировка

DBD::PG question

От
Frank Bax
Дата:
In a perl script using DBI and DBD:Pg, I need to drop/create a table:  $dbp->{RaiseError} = 0;  $dbp->do( "DROP TABLE
$table");  $dbp->{RaiseError} = 1;  $dbp->do( "CREATE TABLE $table ..." );
 

If the table does not exist, the "DROP TABLE" produces an error message; 
but script doesn't die because RaiseError was set to zero.  Is there a way 
to suppress this error message and then reset the change so an error in 
create *is* seen?

Frank



Re: DBD::PG question

От
Frank Bax
Дата:
At 07:30 AM 3/29/05, Frank Bax wrote:

>In a perl script using DBI and DBD:Pg, I need to drop/create a table:
>   $dbp->{RaiseError} = 0;
>   $dbp->do( "DROP TABLE $table" );
>   $dbp->{RaiseError} = 1;
>   $dbp->do( "CREATE TABLE $table ..." );
>
>If the table does not exist, the "DROP TABLE" produces an error message; 
>but script doesn't die because RaiseError was set to zero.  Is there a way 
>to suppress this error message and then reset the change so an error in 
>create *is* seen?


Thanks to Sean for suggesting I turn PrintError off/on:        http://search.cpan.org/~timb/DBI-1.48/DBI.pm#PrintError
Works as advertised - if only I'd found those docs before asking my question... 



Re: DBD::PG question

От
Greg Stark
Дата:
Frank Bax <fbax@sympatico.ca> writes:

> In a perl script using DBI and DBD:Pg, I need to drop/create a table:
>    $dbp->{RaiseError} = 0;
>    $dbp->do( "DROP TABLE $table" );
>    $dbp->{RaiseError} = 1;
>    $dbp->do( "CREATE TABLE $table ..." );
> 
> If the table does not exist, the "DROP TABLE" produces an error message; but
> script doesn't die because RaiseError was set to zero.  Is there a way to
> suppress this error message and then reset the change so an error in create
> *is* seen?


I think it looks something like this:

{ local($dbp->{RaiseError}) = 0; local($dbp->{PrintError}) = 0; $dbp->do( "DROP TABLE $table" );
}
$dbp->do( "CREATE TABLE $table ..." );


-- 
greg