Hey all, I want to update some tables in a Postgres dbase and I want to use DBI to do that. I'm using the DBD::Pg 1.01 driver. I am running into a problem of having to do a bind_param -
$select00->bind_param(1,$id,SQL_INTEGER)|| die $select00->errstr; $select00->bind_param(3,$item,SQL_INTEGER)|| die $select00->errstr;
But when I run the script I get the following -
DBI::st=HASH(0x80f86e0)->bind_param(...): attribute parameter 'SQL_INT +EGER' is n ot a hash ref at ./dbtest.insert line 19.
Here is the entire code -
#!/usr/bin/perl -w # # use strict; use DBI; my $dsn="dbi:Pg:dbname=tabletest"; my $user="postgres"; my $passwd=""; # # # my ($dbh,$id,$descr,$item,$latin); $dbh = DBI->connect($dsn, $user, $passwd, { RaiseError => 1, AutoCommi +t => 0 }); my $select00 = $dbh->prepare('INSERT INTO hobby (id,descr,item,latin) +VALUES (?, ?,?,?)')|| die $dbh->errstr; $select00->bind_param(1,$id,SQL_INTEGER)|| die $select00->errs +tr; $select00->bind_param(3,$item,SQL_INTEGER)|| die $select00->er +rstr; my $csvfile="/home/bradley/dbtest/item_instk.csv"; open (CSV,"$csvfile"); while (<CSV>) { chop; $id = 1; ($item,$descr,$latin) = split /\//; $select00->execute( $id, $descr, $item, $latin )||die $dbh->er +rstr; ++$id; } close CSV; $dbh->disconnect;
Also, do I need to quote the SQL_INTEGER parts of the bind_params? I get
Bareword "SQL_INTEGER" not allowed while "strict subs" in use at ./dbt +est.insert line 18.
If I don't quote them. Any help anyone can provide would be greatly appreciated. Thanks Bradley Where ever there is confusion to be had... I'll be there.

In reply to DBI data types by Dalin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.