RE: [dbi] prepared insert syntax error on exec

From: Andy Law (andy.law_at_bbsrc.ac.uk)
Date: 10/15/03


To: "'dbi-users@perl.org'" <dbi-users@perl.org>
Date: Wed, 15 Oct 2003 13:43:49 +0100


> 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
>



Relevant Pages

  • RE: [dbi] prepared insert syntax error on exec
    ... > to change the SQL ... Yada, yada, yada... ... sender who is duly authorised to do so on behalf of the Institute. ... > Martin J. Evans ...
    (perl.dbi.users)
  • Re: [dbi] prepared insert syntax error on exec
    ... >> to change the SQL ... > Yada, yada, yada... ... > sender who is duly authorised to do so on behalf of the Institute. ... >> Martin J. Evans ...
    (perl.dbi.users)
  • 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 ... Martin J. Evans ... On 15-Oct-2003 Gary Stainburn wrote: ... > ncname is a varcharcompany name ...
    (perl.dbi.users)
  • Re: MSDE Portumleitung
    ... Martin Knauer wrote: ... > Versuch doch mal deinen Provider zu überzeugen, den "SQL Server Web ... > Link dazu: ... Lizenzrechtlich ist das sauber ...
    (microsoft.public.de.sqlserver)
  • Re: cant connect to sql server with domain users? Help....
    ... Now when you change it to sql and windows authentication you have to add the ... aspnet user to the database and use Integrated Security=True ...
    (microsoft.public.dotnet.framework.aspnet)