Modules and PostgreSQL

I am trying to split a report design into modules like this:
1. Basic Sales Module
2. Sales reports which use the basic module to calculate sales.

I use PostgreSQL dbms, Pg module, but Im having a hard time sharing the
database connection object from calling perl program to module. I need to
create temporary tables and access them in the module.
To insert data into the tables created in the calling program I am passing
the  connection object as argument to module function but it keeps dying.
Is it correct to construct a copy of the conn object using my()
Like so :
** Calling program:
Use Pg;
Use Sales;

$conn = Pg::connectdb("dbname = "salesdb");
die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;
$crt = $conn->exec("create temporary table sales (product char(10),
sales_qty float8, sales_amt float8)");
die $conn->errorMessage unless PGRES_COMMAND_OK eq $crt->resultStatus;

*** Basic Module:
Package Sales;
@export stuff declarations etc...
sub cal_sales()
my($local_conn) = @_;

$result = $local_conn->exec ("select (qty * price) from invoice_table");
die $local_conn->errorMessage unless PGRES_TUPLES_OK eq
# Say sales data is picked up and to be stored in table "sales"

Everytime a die statement is encountered, Perl seems only too happy to
comply, but this is only in the module. Is there a conflict of Pg in
other packages? I have a line Use Pg in my module as well as in calling


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]