Foxpro bind_param

From: Stephen Toney (toney_at_systemsplanning.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 09:46:26 -0400
To: dbi-users@perl.org

Hi everyone,

I'm using DBD::ODBC to insert into a Visual FoxPro table. Foxpro
misunderstands the param type if the statement is prepared with
placeholders. I'm reading values from one sth and using another (sth2)
to insert.

This works but is inefficient:

$sth = $::dbh->prepare ($mainquery);
$sth->execute;
my ($key, $subset);
$sth->bind_columns(\$key, \$subset);

my $seq = 0;
while ($sth->fetch)
{
        $seq++;
        my $insertquery = sprintf
                ("insert into sruser (userid, seq, key, subset) " .
                "values ('%s', %lu, %lu, %lu)",
                cookie ("user"), $seq, $key, $subset);
        my $sth2 = $::dbh->prepare ($insertquery);
        $sth2->execute ();
}

Naturally I should be preparing the query outside the loop. But this
doesn't work:

$sth = $::dbh->prepare ($mainquery);
$sth->execute;
my ($key, $subset);
$sth->bind_columns(\$key, \$subset);
                
my $insertquery = sprintf
                ("insert into sruser (userid, seq, key, subset) " .
                "values ('%s', ?, ?, ?)",
                cookie ("user"));
my $sth2 = $::dbh->prepare ($insertquery);
                
my $seq = 0;
while ($sth->fetch)
{
        $seq++;
        $sth2->bind_param (1, $seq, {TYPE => SQL_INTEGER});
        $sth2->bind_param (2, $key, {TYPE => SQL_INTEGER});
        $sth2->bind_param (3, $subset, {TYPE => SQL_INTEGER});
        $sth2->execute ();
}

The Foxpro driver returns the error "Data type mismatch". The columns
in the table are specified as I (integers).

By temporarily changing the columns to CHAR in the table, the correct
values are inserted, even when the type is specified as SQL_INTEGER in
the bind_param! So clearly driver is misunderstanding or ignoring the
TYPE in the bind_param.

The CodeBase ODBC driver handles the second example correctly, so it's
not a table issue or a DBI issue but a driver issue.

Any suggestions would be greatly appreciated!

Stephen Toney
Systems Planning
toney@systemsplanning.com
http://www.systemsplanning.com



Relevant Pages

  • Re: Access import off Fox Pro Tables
    ... I am having an issue installing the visual fox pro driver. ... and try to install from the link you provided, I am getting the error "The ... How can I get this VFP odbc driver? ... > Start with the latest ODBC driver for FoxPro and Visual FoxPro, ...
    (microsoft.public.access.externaldata)
  • Re: FoxPro 2.6 on Windows XP
    ... Note the article was specifically referring to vfp so I don't think that fix ... This is why I went for the simple option of using a Windows driver. ... In FoxPro 2.6 for Windows ... >>> 1) Created a command prompt desktop shortcut icon. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Word Mail Merge with Foxpro data
    ... As long as you have the updated FoxPro ODBC driver (I think you will see ... at open" to ensure that the extra dialog to "confirm the data source" is ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Still having problems merging with DBF
    ... works for older .dbf format files, whereas the FoxPro driver is for more ... see if you can open the DBF in Excel using the FoxPro ... you almost certainly need to install the Jet stuff ...
    (microsoft.public.word.mailmerge.fields)
  • Printing GPF
    ... I just changed one machine on a network from Windows 98 to Windows XP, ... use the SBT accounting system, I know nothing about SBT or FoxPro, I believe ... perfectly fine, with the exception of printing, any print job to LPT1 ... possibility is the driver, does FoxPro use the windows driver, or is sending ...
    (microsoft.public.fox.vfp.reports.printing)