This is a canned perl script called iw_solution_inlinecallout.ipl which is available here:
https://support.interwoven.com/kb/kb_show_article2.asp?ArticleID=48942Does anyone know how I can eliminate the $db_user_name and $db_password so they are not in this script - to me this is a secruity no no and will mean that each time our password changes I have to manually change flat files - I tried to just use the dsn which already has all the info
by having my call like this:
$db = DBI->connect("dbi

DBC:$dsn")
however I get errors like:
DBI->connect failed: [Oracle][ODBC][Ora]ORA-01005: null password given; logon denied
#!C:\iw-home/iw-perl/bin/iwperl
# Copyright 2002 Interwoven, Inc.
# All Rights Reserved
# This is an example of a server-side inline data capture callout
# program that query a database and return results as "option" elements.
###################################################################
#
# iw_solution_inlinecallout.ipl
#
# Server-side inline data capture callout program that query a database
# and return results as "option" elements.
# This kind of callout is invoked by the data capture engine
# at data capture template (DCT) processing time. The invocation is
# triggered by an "inline" element in the DCT. That XML element in the DCT
# will be replaced by what this program outputs to stdout.
# The output of this program is supposed to be a well-formed XML document.
# The outermost tag of the document should be "substitution". The contents
# of that "substitution" element will replace the "inline" element in the
# DCT. In this case, the "substitution" element will contain six "option"
# elements, enumerating a variety of types of yacht hull materials.
# Usage:
# iw_solution_inlinecallout.ipl
#
#
####################################################################
############################## Modules #############################
use DBI;
use strict;
########################## Global variables ########################
my $XML_HEADER; # the XML header that returns to the DCT
my $XML_FOOTER; # the XML footer that returns to the DCT
##################### Set the values of variables ####################
$XML_HEADER="<?xml version='1.0' encoding='UTF-8'?>\n<substitution>\n";
$XML_FOOTER="</substitution>\n";
##################### Call the main Subroutine ####################
&main();
########################## Main Subroutine ########################
# this is the entry point of the program, it calls the other two
# subroutines
sub main{
######################## LOCAL VARIABLES ######################
my $valuearrayref1; # a reference to the option list values
my $valuearrayref2; # a reference to the option list labels
my $optionstring; # the option string
###############################################################
($valuearrayref1,$valuearrayref2) = &get_fieldvalues();
$optionstring = &get_optionstring($valuearrayref1, $valuearrayref2);
print "$XML_HEADER";
print "$optionstring";
print "$XML_FOOTER";
return 0;
}
##################### get Option String Subroutine ###################
# This subroutine creates the Option String and it will return the HTML
# to main subroutine
sub get_fieldvalues{
######################## LOCAL VARIABLES ######################
my $db; # set up for the database connection
my $query; # DB select statement to association table
my $sth; # the statement handle
my $name; # the product name that selected from the table
my
@row; # the array that contains the values
my
@row1; # the array that contains the column key (ISBN)
my
@row2; # the array that contains the column value (name)
my $dsn; # the data source
my $db_user_name; # the database username
my $db_password; # the database password
my $table_name; # the table name
my $column_key; # the column key (ISBN)
my $column_value; # the column value (name)
$dsn = "DSN_Product";
$db_user_name = "test_user";
$db_password = "test_passwd";
$table_name = "Product";
$column_key = "ISBN";
$column_value = "name";
# Connect to the database
$db = DBI->connect("dbi

DBC:$dsn", "$db_user_name", "$db_password")
or die "Unable to open database connection $!";
# the database query statement
$query = "SELECT " . $column_key. "," . $column_value . " FROM " . $table_name;
# Prepare and execute the statement
$sth = $db->prepare("$query");
$sth->execute() or die "$!";
# Get the current data and put it to the arrays
while (
@row=$sth->fetchrow()) {
push(
@row1,$row[0]);
push(
@row2,$row[1]);
}
$sth->finish;
$db->disconnect || die "Error Closing the Database\n";
return (\
@row1,\
@row2);
}
##################### get Field Value Subroutine ###################
# This subroutine creates the option list string filled with the
# necessary values from the database that has been passed as an argument
#
# the argument:
# $arrayreference - the array reference that passed as an argument
# and used to generate the option list string
sub get_optionstring{
######################## LOCAL VARIABLES ######################
my $array_ref1; # the array reference to key
my $array_ref2; # the array reference to value
my $option_string; # the option list string
my $idx; # the index of the array
$array_ref1 = shift;
$array_ref2 = shift;
# get the array value and append it to the option string
for ($idx = 0; $idx <= $#{ $array_ref1 }; $idx++) {
$option_string .= "<option label=\"$array_ref2->[$idx]\" value=\"$array_ref1->[$idx]\" />\n";
}
return ($option_string);
}