Hello all,
I am trying to use place holders to stream line some database interaction.
RH 8 - kernel 2.4.18-18.7
Freetds libs 0.6 (nightly build from 11/22/2002 to get around the cs_ctx_global
problem) --with-tdsver=7.0
Perl 5.6.1
Perl DBI
Perl DBD::Sybase 0.95
Connecting to a MS SQL Server 7.
In the code chunk below, if I use the call to sub 'build_issues_vvl', it works just
fine. The inserts work / the data shows up in the
database.
However, if I use the sub 'use_place_holder' instead, I get the following.
==TEXT OF DBI ERROR==
ct_send(CS_DESCRIBE_INPUT) returned 0 at
/usr/lib/perl5/site_perl/5.6.1/i386-linux/DBD/Sybase.pm line 105.
ct_param() failed! at ./jru.pl line 51.
Died at ./jru.pl line 51.
==END TEXT OF DBI ERROR==
Line 51 is: $sth->execute($var) || die $dbh->errstr;
The table is a simple one column table intended to contain a valid-values-list to
constrain data in another table.
CREATE TABLE issues_vvl (
issue varchar(50) NOT NULL PRIMARY KEY
)
I've tried a number of variations of the place_holder trick and cruised through
"Programming the Perl DBI" by Misters Bunce and
Descarte and don't see why this is not working. Any advice/wisdom would be
appreciated.
==CODE CHUNK ==
#!/usr/bin/perl
use DBI;
use strict;
#--------------------------------------------------------------------------------
my $dbh = DBI->connect("dbi:Sybase:server=stagesrv", 'db_user', 'passwd', {PrintError
=> 0});
unless ($dbh) { die "Unable for connect to server $DBI::errstr"; }
my @data = (
'General',
'Hazards',
'Land and Habitat Protection',
'Policy and Planning',
'Smart Growth');
$dbh->do("use perl"); # there is a test db named 'perl'
$dbh->do("delete from issues_vvl"); # remove any existing data
# &build_issues_vvl; # this works
# &use_place_holder; # this dies - here lies the problem???
my @dat;
my $sth = $dbh->prepare("select * from issues_vvl");
if($sth->execute) { while(@dat = $sth->fetchrow) { print "@dat\n"; } }
#--------------------------------------------------------------------------------
sub build_issues_vvl
{
foreach my $var(@data)
{
my $sql = qq(insert into issues_vvl values ('$var'));
my $sth = $dbh->prepare("$sql");
print "Running - $sql\n";
$sth->execute() || die "Failed EXECUTE:".$dbh->errstr;
}
}
#--------------------------------------------------------------------------------
sub use_place_holder
{
my $sth = $dbh->prepare(q{INSERT INTO issues_vvl (issue) VALUES (?)})
|| die $dbh->errstr;
foreach my $var(@data)
{
$sth->execute($var) || die $dbh->errstr;
}
}
==END CODE CHUNK==
Thanks,
--
John R. Ulmer
Senior Computer Analyst
TPMC Contractor
NOAA Coastal Services Center
[EMAIL PROTECTED]
(843)740-1228
2234 South Hobson Avenue, Charleston, SC 29405