RE: [dbi] prepared insert syntax error on exec
From: Jeffrey Seger (Jeffrey.Seger_at_fairchildsemi.com)
Date: 10/15/03
- Next message: Chuck Fox: "Re: prepared insert syntax error on exec"
- Previous message: Gary Stainburn: "Re: [dbi] prepared insert syntax error on exec"
- Maybe in reply to: Martin J. Evans: "RE: [dbi] prepared insert syntax error on exec"
- Next in thread: Srinivas Thutika: "RE: [dbi] prepared insert syntax error on exec"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: "'dbi-users@perl.org'" <dbi-users@perl.org> Date: Wed, 15 Oct 2003 09:55:56 -0400
And in case you have to iterate through a list of columns....
my $sth;
foreach my $col(@cols)
{
$sth = $dbh->prepare("insert into mytable (col1, col2, $col) values
(?,?,?)");
$sth->execute($val1,$val2,$val3);
}
Obviously this code is incomplete...just to illustrate that when you
change the column name, you need a new statement handle. The SQL parser
in the RDBMS can't successfully parse the statement without knowing that
the column names are all valid.
____________________________
Jeff Seger
Fairchild Semiconductor
jeffrey.seger@fairchildsemi.com
____________________________
"andy law (RI)" <andy.law@bbsrc.ac.uk>
10/15/2003 08:43 AM
To: "'dbi-users@perl.org'" <dbi-users@perl.org>
cc:
Subject: RE: [dbi] prepared insert syntax error on exec
> I could be wrong but I didn't think you could use parameters
> to change the SQL
> which you appear to be doing by using ? where a column name
> is expected.
In which case, why is the prepare statement not failing?
Gary:
Will the following not work?
my ($fieldName) = 'nsmacc';
my ($stmt) = sprintf( "insert into names (nid, ncname, %s) values (?, ?,
?);", $fieldName);
my $cinh = $dbh->prepare( $stmt);
$cinh->execute( 1, 'test name', 'ACC01');
Later,
Andy
-------------
Yada, yada, yada...
The information contained in this e-mail (including any attachments) is
confidential and is intended for the use of the addressee only. The
opinions expressed within this e-mail (including any attachments) are the
opinions of the sender and do not necessarily constitute those of Roslin
Institute (Edinburgh) ("the Institute") unless specifically stated by a
sender who is duly authorised to do so on behalf of the Institute.
> -----Original Message-----
> From: Martin J. Evans [mailto:martin@easysoft.com]
> Sent: 15 October 2003 12:44
> To: dbi-users@perl.org
> Subject: RE: [dbi] prepared insert syntax error on exec
>
>
> I could be wrong but I didn't think you could use parameters
> to change the SQL
> which you appear to be doing by using ? where a column name
> is expected.
>
> Martin
> --
> Martin J. Evans
> Easysoft Ltd, UK
> Development
>
> On 15-Oct-2003 Gary Stainburn wrote:
> > Hi folks,
> >
> > can anyone see why this isn't working:
> >
> > my $cinh=$dbh->prepare("insert into names (nid, ncname, ?)
> values (?, ?,
> > ?);");
> > $cinh->execute('nsmacc',1,'test name','ACC01');
> >
> > produces the error message:
> >
> > ERROR: parser: parse error at or near "'"
> >
> > nid is an int4 primary key
> > ncname is a varchar(50) company name
> > nsmacc is a varchar(5) account number field
> >
> > --
> > Gary Stainburn
> >
> > This email does not contain private or confidential material as it
> > may be snooped on by interested government parties for unknown
> > and undisclosed purposes - Regulation of Investigatory
> Powers Act, 2000
>
- Next message: Chuck Fox: "Re: prepared insert syntax error on exec"
- Previous message: Gary Stainburn: "Re: [dbi] prepared insert syntax error on exec"
- Maybe in reply to: Martin J. Evans: "RE: [dbi] prepared insert syntax error on exec"
- Next in thread: Srinivas Thutika: "RE: [dbi] prepared insert syntax error on exec"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|