[ic] SQL Query in UserTag

David Totten interchange-users@lists.akopia.com
Mon May 14 17:10:00 2001


On Mon, May 14, 2001 at 03:58:12PM -0400, Ben Mirecki wrote:
> Hi David,
> 
> Thanks for your reply to my Interchange question! I modified my code so that
> it now looks like this....

No problem.. just glad to help


> UserTag calc_price Order sku framesize frametype
> UserTag calc_price Interpolate
> UserTag calc_price HasEndTag
> UserTag calc_price Routine <<EOR
> sub {
> 
>   my $get_dbh = sub {
>     my ($table_name) = @_;
>     my $db = Vend::Data::database_exists_ref($table_name);
>     return $db->[$Vend::Table::DBI::DBI];
>   };
> 
>   my $dbh = $get_dbh->('framestyles');
>   my $sql_query = "SELECT price FROM framestyles WHERE sku = '9848'";
>   my $sth = $dbh->prepare($sql_query) or return error_message("Can't open
> framestyles database");
> 
>   return $dbh;
> }
> EOR
> 
> 
> 
> The one thing I forgot to mention is.. this database is a text file (gdbm)
> format, not a SQL database. Does that make a difference? All I need to do is
> a simple field lookup based on some criteria and preferably using an SQL
> statement. I am such a newbie at Perl so it seems very confusing to me :)

I don't think that this code will work for you. It returns an sql database
handle, so I don't know that this will work with a gdbm database.

Although, I was looking through some of the new 4.8 docs 
(found at http://developer.akopia.com/cgi-bin/ic/dev-4.8/ictags)

and thought that you could probably use the query tag. Here is what the docs
say:

 my $sql = "select * from products order by price";
   my $result_array = $Tag->query( { sql => $sql,  },
                                   $body );
   my ($same_results, $col_name_hash, $col_name_array) =
                      $Tag->query( { sql => $sql,  },
                                   $body );

   my $result_hasharray = $Tag->query( { sql     => $sql,
                                         hashref => 'my_results',  },
                                       $body );

or similarly with positional parameters,

$Tag->query( $sql, $attribute_hash_reference, $body);

Doing your query like this should work.


-- 
Start random buzzword text:
In particular, initiation of critical subsystem development mandates staff-meeting-level attention to the distributed e-commerce solution.