RE: Cannot Insert into Oracle
From: Nelson Yik (nelson.yik_at_bell.ca)
Date: 02/14/05
- Previous message: Chris Jacobson: "Re: random rows"
- Maybe in reply to: Nelson Yik: "Cannot Insert into Oracle"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Feb 2005 11:10:18 -0500 To: dbi-users@perl.org
Hi everyone,
Thanks to those who responded. I tried all the helpful ideas, and well,
I guess it's better to get a different error than living in the same
error, hehe.
If I don't use strict, I get the following errors:
Database error: DBI::st=HASH(0x239094)->bind_param(...): attribute
parameter 'SQL_VARCHAR' is not a hash ref at ./snmp.pl line 38, <INFILE>
line 7867.
If I do use strict, I get the following errors:
Bareword "SQL_VARCHAR" not allowed while "strict subs" in use at
./snmp.pl line 38.
Bareword "SQL_VARCHAR" not allowed while "strict subs" in use at
./snmp.pl line 39.
Bareword "SQL_VARCHAR" not allowed while "strict subs" in use at
./snmp.pl line 40.
Bareword "SQL_VARCHAR" not allowed while "strict subs" in use at
./snmp.pl line 41.
Here is my modified code:
#!/usr/bin/perl
use strict;
use DBI;
my $db = DBI->connect('dbi:Oracle:NelOraDB', 'system', 'bell', {
AutoCommit => 0 }) || die "Database connection not made: $DBI::errstr";
my $sql = qq{ INSERT INTO SNMP_DATA_TABLE VALUES ( ?, ?, ?, ? ) };
my $sth = $db->prepare( $sql );
my ($mib, $var, $vartype, $varvalue, $line, $m, $type, $v, $value);
use Fcntl;
open (INFILE, "/home/nyik/snmp_poller_data.txt") or die"Couldn't open
snmp_poller_data.txt";
open (FD, "+>/usr/local/apache2/htdocs/snmp.html") or die"Couldn't open
snmp.html";
# read in each line from the input and print to output
print FD "<table border=1>";
print FD "<tr><td><b>MIB</b></td><td><b>Var</b></td><td><b>Var
Type</b></td><td><b>Var Value</b></td></tr>";
while(<INFILE>)
{
$line = $_ ;
# print FD "<tr><td>$line</td></tr>";
if ($line =~
/((\w*|-|\d*)*)MIB::(\w*(\.(\d*))*)\s*=\s*((\w*|-|\d*)*):*\s*(.*)/)
{
$mib = $1."MIB";
$var = $3;
$vartype = $6;
$varvalue = $8;
} else {
print FD "<tr><td colspan=4>$line</td></tr>";
$mib = "<b>WRONG!!!</b>";
$var = "<b>WRONG!!!</b>";
$vartype = "<b>WRONG!!!</b>";
$varvalue = "<b>WRONG!!!</b>";
}
eval {
$sth->bind_param( 1, $db->quote($mib),
SQL_VARCHAR );
$sth->bind_param( 2, $db->quote($var),
SQL_VARCHAR );
$sth->bind_param( 3, $db->quote($vartype),
SQL_VARCHAR );
$sth->bind_param( 4, $db->quote($varvalue),
SQL_VARCHAR );
$sth->execute();
};
if ( $@ ) {
warn "Database error: $@\n";
$db->rollback();
}
print FD "<tr>";
print FD "<td><font face=arial
size=1>$mib </font></td>";
print FD "<td><font face=arial
size=1>$var </font></td>";
print FD "<td><font face=arial
size=1>$vartype </font></td>";
print FD "<td><font face=arial
size=1>$varvalue </font></td>";
print FD "</tr>";
}
close(INFILE);
close(FD);
$db->commit();
$sql = qq{ SELECT * FROM SNMP_DATA_TABLE };
$sth = $db->prepare( $sql );
$sth->execute();
$sth->bind_columns(undef,\$m, \$v, \$type, \$value);
while( $sth->fetch() ) {
print "$m, $v, $type, $value\n";
}
$sth->finish();
$db->disconnect();
Nelson Yik
Business Systems Analyst Co-op
New Technology Integration
Bell Canada
76 Adelaide St. W., Floor 15
* nelson.yik@bell.ca <mailto:+nelson.yik@bell.ca>
* (416) 353-9159
- Previous message: Chris Jacobson: "Re: random rows"
- Maybe in reply to: Nelson Yik: "Cannot Insert into Oracle"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|