Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date ][Interchange by thread ]

Re: [ic] SQL Query in UserTag



On Mon, May 14, 2001 at 10:21:40AM -0400, Ben Mirecki wrote:
> Hi!
> 
> I'm trying to create a UserTag that does a field value lookup from an
> arbitrary table. The UserTag will be called from CommonAdjust as part of the
> pricing method.

I just did this, so perhaps I can help :)

> 
> Here's the code I have.
> 
> UserTag calc_price Order
> UserTag calc_price Routine <<EOR
> sub {
>   my $dbh = $Sql{framestyles};
>   my $sql_query = "SELECT price FROM framestyles WHERE sku = 9848";
>   my $sth = $dbh->prepare($sql_query) or return error_message("Error...");
>   my $rc = $sth->execute() or return HTML("Error...");
> 
>   return 0;
> }
> EOR
> 

You can't access %Sql like that from a usertag. I wrote a small sub-routine
to get me a database handle.

my $get_dbh = sub {
      my ($table_name) = @_;
      my $db = Vend::Data::database_exists_ref($table_name);
      return $db->[$Vend::Table::DBI::DBI];
   };

I define this at the top of my user tag, and then I use it like this:

my $dbh = $get_dbh->('database_name');


You should now be able to replace your line

my $dbh = $Sql{framestyles};

with my line

my $dbh = $get_dbh->('framestyles');

and it should work the way you think it will.

-- 
Start random buzzword text:
Thus, the product configuration baseline adds overriding performance constraints to gain the full benefts of the client-server archetecture. 

PGP signature


Search for: Match: Format: Sort by: