[ic] SQL Query in UserTag
David Totten
interchange-users@lists.akopia.com
Mon May 14 10:41:58 2001
--V88s5gaDVPzZ0KCq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Mon, May 14, 2001 at 10:21:40AM -0400, Ben Mirecki wrote:
> Hi!
>=20
> 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 :)
>=20
> Here's the code I have.
>=20
> UserTag calc_price Order
> UserTag calc_price Routine <<EOR
> sub {
> my $dbh =3D $Sql{framestyles};
> my $sql_query =3D "SELECT price FROM framestyles WHERE sku =3D 9848";
> my $sth =3D $dbh->prepare($sql_query) or return error_message("Error...=
");
> my $rc =3D $sth->execute() or return HTML("Error...");
>=20
> return 0;
> }
> EOR
>=20
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 =3D sub {
my ($table_name) =3D @_;
my $db =3D 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 =3D $get_dbh->('database_name');
You should now be able to replace your line
my $dbh =3D $Sql{framestyles};
with my line
my $dbh =3D $get_dbh->('framestyles');
and it should work the way you think it will.
--=20
Start random buzzword text:
Thus, the product configuration baseline adds overriding performance constr=
aints to gain the full benefts of the client-server archetecture.=20
--V88s5gaDVPzZ0KCq
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE6/+wb6NZLqYh7hkwRAqNpAJ42DH+nQ3CneWVcemzlfGw+4YqUDACghlnb
K3ayEnwlV/p7xAcuX/1UxMc=
=K7jM
-----END PGP SIGNATURE-----
--V88s5gaDVPzZ0KCq--