From: [EMAIL PROTECTED] (Isaac)
To: <[EMAIL PROTECTED]>
Subject: specifying types with bind columns
Date sent: Thu, 5 Jul 2001 12:05:56 -0700
Isaac
>
> I was hoping someone could give me the right syntax for specifying
> what type of data a column is with bind columns. I get an error
> from perl.exe
what's the error ?
> when trying to update some stuff on my Access Database
> and I think telling my script explicitly what kind of data it is (number or
> string will fix it)
>
> Code: Where the ***** are is where I need the help.
>
> Thanks!
>
>
> $thismonth = $dbh->prepare( qq{Select CustomerID, CompanyName, ThisMonth
> from Customers});
>
> print "Executing SQL Statement: " . $thismonth->{Statement} . "\n\n";
>
> print $thismonth->execute() . "\n\n" or die "Could not execute SQL
> Statement:" . $thismonth->errstr;
>
> #Now Need to access the actual values
> *************** I need to have customerid be specified number,
> companyname as string and currentmonth as number *************
> $thismonth->bind_columns( \$customerid, \$companyname, \$currentmonth);
bind_columns() just binds columns to variables in order to speed up
fetching and has nothing to do with assigning data types for writing
to your database...
> while( $thismonth->fetch() ) {
>
> print "The Current month's bandwidth total for $companyname is:
> $currentmonth\n\n";
>
> ##Now Need to UPdate Archives Table with $currentmonth placed into column
> of lastmonth######
> $updatelast = $dbh->prepare (qq {update Archives set $abbrevdate =
> $currentmonth where Customerid = $customerid});
Are you sure that you want to say $abbrevdate ?
You probably mean just abbrevdate...
>
> print "Executing SQL Statement: " . $updatelast->{Statement} . "\n\n";
>
> $updatelast->execute();
>
> #End Of While Loop
> }
try the version below (untested due to lack of apprpriate database)
and post the error message if it still doesn't work.
<perlcode>
my $dbh = DBI->connect("dbi:ODBC:your_database_here", {RaiseError =>
1}) or die DBI::errstr;
my $thismonth = $dbh->prepare("Select ThisMonth, CustomerID from
Customers");
$thismonth->execute;
my $updatelast = $dbh->prepare("update Archives set abbrevdate = ?
where Customerid = ?");
while (my @row = $thismonth->fetchrow_array) {
$updatelast->execute(@row);
}
</perlcode>
Speeding up can be done using bind_columns(), and assigning data
types to the placeholders must be done with bind_param() (see the
docs).
HTH
Bodo
[EMAIL PROTECTED]