Reposting of ActivePerl/MySQL problem dropping tables

Reposting of ActivePerl/MySQL problem dropping tables

am 29.09.2005 22:00:56 von mfanderson

Hi all,

This is a reposting of a message. I was advised that my attached code
did not make it through.

Basically, I am running ActivePerl 5.8.7 and mySQL 4.1 under windows XP.
Although I can handle data manipulation statements through DBI, it balks
at drop table and create table statements. Here is a listing of the code
and my error messages:

#!C:\perl\bin\perl.exe

use strict;
use DBI;

open(STDERR, ">LoadJgan.err");
open(STDOUT, ">LoadJgan.out");
## Remove any old dbi trace logs
unlink 'dbitrace.log' if -e 'dbitrace.log';

my $dbh = DBI->connect("dbi:mysql:meadowrue", "root", "qu3rcus",
{RaiseError => 0,
PrintError => 0})
or die "Can't connect to database";
$dbh->trace(2, 'dbitrace.log');

$DropCmd = "drop table IF EXISTS JGanSamples";
my $sth = $dbh->prepare($DropCmd)
or die "Could not prepare $DropCmd:\n", $dbh->errstr(),"\n";
$sth->execute ($sth)
or die "Could not execute $DropCmd:\n", $sth->errstr(),"\n";
.......
The error message was:

Could not execute drop table IF EXISTS JGanSamples:
called with 1 bind variables when 0 are needed

Re: Reposting of ActivePerl/MySQL problem dropping tables

am 29.09.2005 22:29:42 von jon.mangin

----- Original Message -----
From: "Mary Anderson"
To:
Sent: Thursday, September 29, 2005 3:00 PM
Subject: Reposting of ActivePerl/MySQL problem dropping tables


>
> Hi all,
>
> This is a reposting of a message. I was advised that my attached code
> did not make it through.
>
> Basically, I am running ActivePerl 5.8.7 and mySQL 4.1 under windows XP.
> Although I can handle data manipulation statements through DBI, it balks
> at drop table and create table statements. Here is a listing of the code
> and my error messages:
>
> #!C:\perl\bin\perl.exe
>
> use strict;
> use DBI;
>
> open(STDERR, ">LoadJgan.err");
> open(STDOUT, ">LoadJgan.out");
> ## Remove any old dbi trace logs
> unlink 'dbitrace.log' if -e 'dbitrace.log';
>
> my $dbh = DBI->connect("dbi:mysql:meadowrue", "root", "qu3rcus",
> {RaiseError => 0,
> PrintError => 0})
> or die "Can't connect to database";
> $dbh->trace(2, 'dbitrace.log');
>
> $DropCmd = "drop table IF EXISTS JGanSamples";
> my $sth = $dbh->prepare($DropCmd)
> or die "Could not prepare $DropCmd:\n", $dbh->errstr(),"\n";
> $sth->execute ($sth)
> or die "Could not execute $DropCmd:\n", $sth->errstr(),"\n";
> ......
> The error message was:
>
> Could not execute drop table IF EXISTS JGanSamples:
> called with 1 bind variables when 0 are needed
>
>
I believe it should be:
$sth->execute(); # no bind variable

Don't forget scoping:
my $DropCmd = ...

Re: Reposting of ActivePerl/MySQL problem dropping tables

am 29.09.2005 22:34:50 von chris.jacobson

Mary,

Your error is occuring on this line:

$sth->execute ($sth)


This line should actually read:

$sth->execute ()


Anything passed into the execute function is assumed to be a bind
variable. Try making that change to your script and run it again.

HTH,
Chris

Mary Anderson wrote:

>Hi all,
>
> This is a reposting of a message. I was advised that my attached code
>did not make it through.
>
> Basically, I am running ActivePerl 5.8.7 and mySQL 4.1 under windows XP.
> Although I can handle data manipulation statements through DBI, it balks
>at drop table and create table statements. Here is a listing of the code
>and my error messages:
>
>#!C:\perl\bin\perl.exe
>
>use strict;
>use DBI;
>
>open(STDERR, ">LoadJgan.err");
>open(STDOUT, ">LoadJgan.out");
>## Remove any old dbi trace logs
>unlink 'dbitrace.log' if -e 'dbitrace.log';
>
>my $dbh = DBI->connect("dbi:mysql:meadowrue", "root", "qu3rcus",
> {RaiseError => 0,
> PrintError => 0})
>or die "Can't connect to database";
>$dbh->trace(2, 'dbitrace.log');
>
>$DropCmd = "drop table IF EXISTS JGanSamples";
>my $sth = $dbh->prepare($DropCmd)
> or die "Could not prepare $DropCmd:\n", $dbh->errstr(),"\n";
> $sth->execute ($sth)
> or die "Could not execute $DropCmd:\n", $sth->errstr(),"\n";
>......
> The error message was:
>
>Could not execute drop table IF EXISTS JGanSamples:
>called with 1 bind variables when 0 are needed
>
>
>
>
>
>

Re: Reposting of ActivePerl/MySQL problem dropping tables

am 29.09.2005 23:35:16 von ron

On Thu, 29 Sep 2005 13:00:56 -0700 (PDT), Mary Anderson wrote:

Hi Mary

> #!C:\perl\bin\perl.exe
>
> use strict;

This is good to add:

use warnings;

> use DBI;
>
> open(STDERR, ">LoadJgan.err");
> open(STDOUT, ">LoadJgan.out");
> ## Remove any old dbi trace logs
> unlink 'dbitrace.log' if -e 'dbitrace.log';
>
> my $dbh =3D DBI->connect("dbi:mysql:meadowrue", "root", "qu3rcus",

I sure hope this isn't your real password being published in a public=
forum...

> {RaiseError =3D> 0, PrintError =3D> 0}) or die "Can't connect to
> database"; $dbh->trace(2, 'dbitrace.log');
>
> $DropCmd =3D "drop table IF EXISTS JGanSamples";
> my $sth =3D $dbh->prepare($DropCmd)
> or die "Could not prepare $DropCmd:\n", $dbh->errstr(),"\n"; $sth-
> >execute ($sth)

$sth -> execute();

You has supplied an unnecessary parameter, which the error message below=
tells
you about by saying 0 are needed.

> or die "Could not execute $DropCmd:\n", $sth->errstr(),"\n"; ......
> The error message was:
>
> Could not execute drop table IF EXISTS JGanSamples:
> called with 1 bind variables when 0 are needed


--
Cheers
Ron Savage, ron@savage.net.au on 30/09/2005
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company