[Dbix-class] Re: Insert in MSSQL fails on date time fields

William Goedicke billy at brant-interactive.com
Tue Sep 24 10:30:51 GMT 2013


Dear Y'all - 

Damn it, I sent a broken version.  Apologies.  The following snippet includes the missing "while" line.

...
  $sth = $dbh->prepare("SELECT * FROM $table_name") || die $dbh->errstr;
  $sth->execute() || print "$sth->errstr\n\n";
  
  while( $r = $sth->fetchrow_hashref) {
    my $newrec = $schema->resultset($table_name)->create($r);
    $newrec->in_storage();
  }
  $sth->finish;
...

On Sep 23, 2013, at 1:13 PM, William Goedicke <billy at brant-interactive.com> wrote:

> Dear Y'all - 
> 
> I'm migrating a bunch (100ish) tables from Foxpro 2.6 to MSSQL.
> 
> The following code works almost perfectly.
> 
> use VB_Temp::Main;
> use DBI;
> use Data::Dumper;
> 
> my $schema = VB_Temp::Main->connect('dbi:ODBC:VB_Temp');
> 
> my $dbf_dir = 'C:/users/goedicw/documents/voicebase/voicedb/';
> my $dbh = DBI->connect("DBI:XBase:".$dbf_dir) or die $DBI::errstr;
> 
> foreach ( keys $schema->{'class_mappings'}) {
>   /::([^:]+)$/;
>   my $table_name = $1;
> 
>   my $vb_temp_rs = $schema->resultset($table_name);
> 
>   $vb_temp_rs->delete_all;
> 
>   $sth = $dbh->prepare("SELECT * FROM $table_name") || die $dbh->errstr;
>   $sth->execute() || print "$sth->errstr\n\n";
> 
>     my $newrec = $schema->resultset($table_name)->create($r);
>     $newrec->in_storage();
>   }
>   $sth->finish;
> }
> 
> Except it fails on datetime fields.  I see that the insert statement is constructed to look like:
> 
> insert into tbl (key, somedate) values(100, 19930312);
> 
> which fails.
> 
> insert into tbl (key, somedate) values(100, '199303123') 
> 
> however works fine, but I can't get my script to generate the field value that way.
> 
> All help is, of course, most appreciated.
> 
>    - Billy
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130924/9775c906/attachment.htm


More information about the DBIx-Class mailing list