thank you so much for your help! I plan using the code for updating a date field only while using ODBC for the rest. (with in mind of an upgrade of DBMS later) Is there anything that anyone knows that I should pay attention to? thanks

regards,
Samuel

----- Original Message ----- From: "Nelson, Erick [HDS]" <[EMAIL PROTECTED]>
To: "Samuel_Zheng" <[EMAIL PROTECTED]>
Sent: Wednesday, August 29, 2007 11:53 AM
Subject: RE: perl date


[EMAIL PROTECTED]:/home/erickn> perl test.pl
1 = 20071202

[EMAIL PROTECTED]:/home/erickn> cat test.pl

use strict;
use warnings;
use DBI;
use DBD::XBase;

my $xbase_dbh = DBI->connect("DBI:XBase:.", undef, undef, {RaiseError =>
1});

my $upd = "update sample set dt = ? where id = ?";
my $upd_csr = $xbase_dbh->prepare($upd);

my $sel = "select id, dt from sample";
my $sel_csr = $xbase_dbh->prepare($sel);

$upd_csr->execute('20071202', 1);

$sel_csr->execute();
while (my ($id, $dt) = $sel_csr->fetchrow_array()) {
   print "$id = $dt\n";
}

$xbase_dbh->disconnect();

-----Original Message-----
From: Samuel_Zheng [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 29, 2007 2:30 AM
To: Nelson, Erick [HDS]; dbi-users@perl.org
Subject: Re: perl date

Hi Nelson,
Thanks for the codes. Please forgive my  ignoracne, but how to update a
date
field in dbf ? thanks again.
Samuel
----- Original Message ----- From: "Nelson, Erick [HDS]" <[EMAIL PROTECTED]>
To: "Samuel_Zheng" <[EMAIL PROTECTED]>
Sent: Tuesday, August 28, 2007 6:43 PM
Subject: RE: perl date


use strict;
use warnings;
use DBI;
use DBD::XBase;
use DBU;

my $xbase_dbh = DBI->connect("DBI:XBase:.", undef, undef, {RaiseError =>
1});
my $oracle_dbh = DBI->connect(DBU::connect('mwh'));

my $create_table = <<EOT;
create table sample (
  id     int,
  dt     date
)
EOT

unlink 'sample.dbf';

$xbase_dbh->do($create_table);

my $sel = "select 1, to_char(sysdate,'YYYYMMDD') dt from dual";
my $sel_csr = $oracle_dbh->prepare($sel);

my $ins = "insert into sample (id, dt) values (?,?)";
my $ins_csr = $xbase_dbh->prepare($ins);

$sel_csr->execute();
while (my ($id, $dt) = $sel_csr->fetchrow_array()) {
  $ins_csr->execute($id, $dt);
}

$xbase_dbh->disconnect();
$oracle_dbh->disconnect();

-----Original Message-----
From: Samuel_Zheng [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 28, 2007 3:30 PM
To: Nelson, Erick [HDS]; dbi-users@perl.org
Subject: Re: perl date

Thank you Nelson for your response. Please cut and paste your codes and
so I
can try them, or how can I get YYYY
MM and DD? What is the function to convert a string to a numeric? Do I
need
this function? Thank you for the help!

----- Original Message ----- From: "Nelson, Erick [HDS]" <[EMAIL PROTECTED]>
To: "Samuel_Zheng" <[EMAIL PROTECTED]>; <dbi-users@perl.org>
Sent: Monday, August 27, 2007 11:51 AM
Subject: RE: perl date


I've created dbf files using DBD::XBase a few times.
To get dates to insert correctly I had to have the date in YYYYMMDD
format.
DBD::Xbase writes dbase 4 files.
If Clipper is old enough that it is using dbase 3 files the answer might
be different.

-----Original Message-----
From: Samuel_Zheng [mailto:[EMAIL PROTECTED]
Sent: Monday, August 27, 2007 8:45 AM
To: dbi-users@perl.org
Subject: perl date

Hi,

I am using ODBC to convert an old clipper application to a web based
application and I came across something seems simple but it's not.

how can I save a date from perl to a date field in dbf file? can a perl
expert helps out someone who is novice in perl like me? your help would
be very much appreciated! Thanks.

Samuel

__________ NOD32 2489 (20070828) Information __________

This message was checked by NOD32 antivirus system.
http://www.nod32.com.hk


__________ NOD32 2489 (20070828) Information __________

This message was checked by NOD32 antivirus system.
http://www.nod32.com.hk


__________ NOD32 2490 (20070829) Information __________

This message was checked by NOD32 antivirus system.
http://www.nod32.com.hk


Reply via email to