Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Re: Re: Updating Specific Fields in MS Access

by p0lp0t (Initiate)
on Apr 17, 2003 at 23:36 UTC ( [id://251360]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Updating Specific Fields in MS Access
in thread Updating Specific Fields in MS Access

Your response is appreciated.

When I try to place the prepare before the loop, it complains about uninitialized values.
I tried using placeholders, to no avail, so I kept the prepare in the loop. Now I have:

#! C:\perl\bin\perl.exe -w use DBI; #use strict; my $DSN='Database'; my $driver; my $servlist; my $field='Server'; #connect to database my $dbh=DBI->connect("dbi:ODBC:$DSN", "admin", "") || die; #Open file for reading open(INPUT,"file.txt") || die; while (<INPUT>) { chomp; my ($servlist, $driver)=split(/,/); my $sqlstatement=("UPDATE Servers SET nic1_driver_version='$driver +' WHERE '$field' = '$servlist\n'"); my $sth=$dbh->prepare($sqlstatement); $sth->execute || die; } close (INPUT); $dbh->disconnect;
Spits back:
DBD::ODBC::st execute failed: MicrosoftODBC Microsoft Access Driver Too few parameters. Expected 1. (SQL-07002)(DBD: st_execute/SQLExecute err=-1) at C:\Perl\scripts\test\newer.pl line 22, <INPUT> line 1.
Died at C:\Perl\scripts\test\newer.pl line 22, <INPUT> line 1.

I am confused about the parameters error.
Regards,
jw

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Updating Specific Fields in MS Access
by pfaut (Priest) on Apr 18, 2003 at 00:24 UTC

    In order to use placeholders, put a '?' whereever you will need to plug data into the statement. Your UPDATE statement then becomes:

    my $sth = $dbh->prepare("UPDATE Servers SET nic1_driver_version=? WHER +E Server=?");

    Then, pass the values to plug into those placeholders to execute like so:

    $sth->execute($driver,$servlist);

    The statement doesn't need to change from one execution of the loop to the next. Therefore, the prepare can be done outside the loop. The values change each iteration and get plugged into the statement at execute time inside the loop.

    90% of every Perl application is already written.
    dragonchild
      I now have:
      #! C:\perl\bin\perl.exe -w use DBI; #use strict; my $DSN='Database'; my $driver; my $servlist; #connect to database my $dbh=DBI->connect("dbi:ODBC:$DSN", "admin", "") || die; my $sqlstatement=("UPDATE Servers SET Servers.nic1_driver_version=? WH +ERE server=?"); my $sth=$dbh->prepare($sqlstatement); #Open file for reading open(INPUT,"file.txt") || die; while (<INPUT>) { chomp; my ($servlist, $driver)=split(/,/); $sth->execute ($driver,$servlist) || die; } close (INPUT); $dbh->disconnect;
      but still get:

      DBD::ODBC::st execute failed: Microsoft ODBC Microsoft Access Driver Too few parameters. Expected 3. (SQL-07002)(DBD: st_execute/SQLExecute err=-1) at C:\Perl\scripts\test\newer.pl line 21, <INPUT> line 1.
      Died at C:\Perl\scripts\test\newer.pl line 21, <INPUT> line 1.

      Thanks again,
      jw

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://251360]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 01:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found