Unix Technical Forum

OLEDB and Dates and Timestamps

This is a discussion on OLEDB and Dates and Timestamps within the DB2 forums, part of the Database Server Software category; --> Am I the only one in the world that selects dates and timestamps with OLEDB? V8 of UDB has ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 06:07 PM
Craig Wahlmeier
 
Posts: n/a
Default OLEDB and Dates and Timestamps

Am I the only one in the world that selects dates and timestamps with
OLEDB?
V8 of UDB has brought me a big problem.

The PATCH2=24 setting no longer works the way it used to. The
settings of MAPDATEDESCRIBE=1, MAPTIMEDESCRIBE=1, and
MAPTIMESTAMPDESCRIBE=1 allow me to reverse that V8 change, almost.
Before V8, the format of a date column returned in OLEDB was based
upon the regional settings of the client. Now, it returns it in
YYYY-MM-DD. Guess what all my web servers have for their regional
settings! MM-DD-YYYY! Can you imagine the mass hysteria and peasant
land seizure that I am experiencing!

I see no mention of this on the message board. Is there something I
am missing? Does anyone have a slick way of dealing with timestamps,
dates, and times in OLEDB or ADO?

TIA,

Craig Wahlmeier
Senior Technical Administrator - Database Systems
Data-Tronics Corp.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2008, 06:08 PM
Mark Yudkin
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

Define the datatype of your target variable as a date / timestamp variable;
then you'll get the native format (e.g., for VB6, you get a Date). You
problem only arises as your'e attempting to convert to a string
representation.

"Craig Wahlmeier" <cwahlmeier@data-tronics.com> wrote in message
news:ac94a6bf.0402131227.6185af98@posting.google.c om...
> Am I the only one in the world that selects dates and timestamps with
> OLEDB?
> V8 of UDB has brought me a big problem.
>
> The PATCH2=24 setting no longer works the way it used to. The
> settings of MAPDATEDESCRIBE=1, MAPTIMEDESCRIBE=1, and
> MAPTIMESTAMPDESCRIBE=1 allow me to reverse that V8 change, almost.
> Before V8, the format of a date column returned in OLEDB was based
> upon the regional settings of the client. Now, it returns it in
> YYYY-MM-DD. Guess what all my web servers have for their regional
> settings! MM-DD-YYYY! Can you imagine the mass hysteria and peasant
> land seizure that I am experiencing!
>
> I see no mention of this on the message board. Is there something I
> am missing? Does anyone have a slick way of dealing with timestamps,
> dates, and times in OLEDB or ADO?
>
> TIA,
>
> Craig Wahlmeier
> Senior Technical Administrator - Database Systems
> Data-Tronics Corp.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-26-2008, 06:08 PM
Craig Wahlmeier
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

Mark,

Thank you for your reply. We are using VBScript inside of ASP pages.
As you know, VBScript is untyped like REXX. IBM has really made this
V8 conversion a mess! To add insult to injury, I just noticed that
the MAPTIMESTAMPDESCRIBE=1 returns a timestamp that is missing a dash,
e.g. 2001-01-01 00.00.00.000000.

I opened PMR 46073,370 last November. I took me a week to convince
the rep that you could indeed select a timestamp via OLEDB! I figured
out the MAPDATEDESCRIBE myself and closed the PMR. I guess I will
open another. I still cannot believe that we are the only ones
accessing DB2 via OLEDB in Active Server Pages and having a problem.

Thanks,

Craig Wahlmeier
Senior Technical Administrator - Database Systems
Data-Tronics Corp.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-26-2008, 06:08 PM
Phil Jackson
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

We always select dates as CHAR(MyDateField) and then manipulate in the
ASP code,
as our DBAs like to store dates that have not happened - i.e.
termination_date
for an active employee as 0001-01-01, which gives ADO fits unless you
fetch as a charactor string. Have NEVER had any luck manipulating
timestamps from DB2 via ADO. Can compare timestamps as in ... where
A.ts = B.ts, but never able to execute a query, save ts in an ASP
variable and use again in a query via ASP/ADO...

Phil J.


> Mark,
>
> Thank you for your reply. We are using VBScript inside of ASP pages.
> As you know, VBScript is untyped like REXX. IBM has really made this
> V8 conversion a mess! To add insult to injury, I just noticed that
> the MAPTIMESTAMPDESCRIBE=1 returns a timestamp that is missing a dash,
> e.g. 2001-01-01 00.00.00.000000.
>
> I opened PMR 46073,370 last November. I took me a week to convince
> the rep that you could indeed select a timestamp via OLEDB! I figured
> out the MAPDATEDESCRIBE myself and closed the PMR. I guess I will
> open another. I still cannot believe that we are the only ones
> accessing DB2 via OLEDB in Active Server Pages and having a problem.
>
> Thanks,
>
> Craig Wahlmeier
> Senior Technical Administrator - Database Systems
> Data-Tronics Corp.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008, 06:09 PM
Mark Yudkin
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

I wish you'd said VBScript / ASP up front; I assumed you were using a
compiled language. VBScript is very much a mess. But I'd still like to see
your ADO code for defining the field.

"Craig Wahlmeier" <cwahlmeier@data-tronics.com> wrote in message
news:ac94a6bf.0402160736.5a5e2a5c@posting.google.c om...
> Mark,
>
> Thank you for your reply. We are using VBScript inside of ASP pages.
> As you know, VBScript is untyped like REXX. IBM has really made this
> V8 conversion a mess! To add insult to injury, I just noticed that
> the MAPTIMESTAMPDESCRIBE=1 returns a timestamp that is missing a dash,
> e.g. 2001-01-01 00.00.00.000000.
>
> I opened PMR 46073,370 last November. I took me a week to convince
> the rep that you could indeed select a timestamp via OLEDB! I figured
> out the MAPDATEDESCRIBE myself and closed the PMR. I guess I will
> open another. I still cannot believe that we are the only ones
> accessing DB2 via OLEDB in Active Server Pages and having a problem.
>
> Thanks,
>
> Craig Wahlmeier
> Senior Technical Administrator - Database Systems
> Data-Tronics Corp.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-26-2008, 06:12 PM
Craig Wahlmeier
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

Mark,

Below is some vbscript. On a V7 fp10 client I get this output -
ts = 2001-01-01-00.00.00.000000
dt = 01/01/2001

On a V8 fp4 client, I get this output -
ts = 01/01/2001
dt = 01/01/2001

Both db2cli.ini files have this for the Sample database -
[sample]
DBALIAS=SAMPLE
LOBMAXCOLUMNSIZE=1048575
LONGDATACOMPAT=1
PATCH1=132096
PATCH2=24,6
SYSSCHEMA=SYSIBM
TXNISOLATION=1

If I add MAPTIMESTAMPDESCRIBE=1 to the V8 client, the output looks
like this -
ts = 2001-01-01 00:00:00.000000
dt = 01/01/2001

If the date column has '0001-01-01', then you have to either add
MAPDATEDESCRIBE=1, or take Phil's advice at use the CHAR funtion. I
think Phil's advice is better because the MAPDATEDESCRIBE=1 causes
this output -
ts = 2001-01-01 00:00:00.000000
dt = 2001-01-01

The date field format is no longer based on your regional settings.

Thanks for your input. Here is the script

Craig


<Job id="DB2 SQL Tester">

<script language="VBScript">
Option Explicit
Const ForReading = 1
Const adUseClient = 3
Const adLockReadOnly = 1
Const adOpenForwardOnly = 0

dim rstDB2
dim sSQL
dim cnnDB2
dim sDB2DBname
dim sDB2UserID
dim sDB2Password

sDB2DBname = "SAMPLE"
sDB2UserID = "xxxxxxx"
sDB2Password = "yyyyyy"

Set cnnDB2 = WScript.CreateObject("ADODB.Connection")
Set rstDB2 = WScript.CreateObject("ADODB.Recordset")

sSQL = "Select COL1, COL2 FROM DTC.TABLE1 "
cnnDB2.Provider = "IBMDADB2;dsn=" & sDB2DBname & ";uid=" &
sDB2UserID & ";pwd=" & sDB2Password
cnnDB2.CursorLocation = adUseClient
cnnDB2.Open
rstDB2.Open sSQL,cnnDB2,adOpenForwardOnly,adLockReadOnly
wscript.echo ("ts = " & rstDB2("COL1"))
wscript.echo ("dt = " & rstDB2("COL2"))

rstDB2.close
cnnDB2.close
set cnnDB2 = Nothing
set rstDB2 = Nothing

</Script>
</Job>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-26-2008, 06:12 PM
Mark Yudkin
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

Try defining the target field as datetime, rather than leaving it to default
(to a string). That way, you'll have a VBA [OLE] Date type rather than a
string, which you can format however you like using the VBA Format$ function
and related routines.

"Craig Wahlmeier" <cwahlmeier@data-tronics.com> wrote in message
news:ac94a6bf.0402191314.4d60e641@posting.google.c om...
> <Job id="DB2 SQL Tester">
>
> <script language="VBScript">
> Option Explicit
> Const ForReading = 1
> Const adUseClient = 3
> Const adLockReadOnly = 1
> Const adOpenForwardOnly = 0
>
> dim rstDB2
> dim sSQL
> dim cnnDB2
> dim sDB2DBname
> dim sDB2UserID
> dim sDB2Password
>
> sDB2DBname = "SAMPLE"
> sDB2UserID = "xxxxxxx"
> sDB2Password = "yyyyyy"
>
> Set cnnDB2 = WScript.CreateObject("ADODB.Connection")
> Set rstDB2 = WScript.CreateObject("ADODB.Recordset")
>
> sSQL = "Select COL1, COL2 FROM DTC.TABLE1 "
> cnnDB2.Provider = "IBMDADB2;dsn=" & sDB2DBname & ";uid=" &
> sDB2UserID & ";pwd=" & sDB2Password
> cnnDB2.CursorLocation = adUseClient
> cnnDB2.Open
> rstDB2.Open sSQL,cnnDB2,adOpenForwardOnly,adLockReadOnly
> wscript.echo ("ts = " & rstDB2("COL1"))
> wscript.echo ("dt = " & rstDB2("COL2"))
>
> rstDB2.close
> cnnDB2.close
> set cnnDB2 = Nothing
> set rstDB2 = Nothing
>
> </Script>
> </Job>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-26-2008, 06:12 PM
Craig Wahlmeier
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

Mark,

You lost me. VBScript is an untyped language...

Craig
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-26-2008, 06:14 PM
Mark Yudkin
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

In ADO, you define how your recordset's fields tie up by using statements:
myRS.Fields.Append name, type, defined_size, attributes
In your case, you would specify type as adDate.

Since you don't do this yourself, you're getting the default bindings. These
are often not what you want; in your case, they obviously aren't, as you've
complained about it.

Note: we're not talking about declaring VBScript variables, we're talking
about declaring the bindings between the ADO source and the data consumer
(your VBScript), as processed by ADO. Also. VBScript typing is irrelevant as
for data access you're using ADO's recordset to access the field:
myRS!FieldName.

To ask ADO to give you what you want, you have to tell ADO how to do it.
Otherwise it second-guesses, based on the database content (which is fine
for simple types like integers or strings).

"Craig Wahlmeier" <cwahlmeier@data-tronics.com> wrote in message
news:ac94a6bf.0402200614.48a10c67@posting.google.c om...
> Mark,
>
> You lost me. VBScript is an untyped language...
>
> Craig



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-26-2008, 06:20 PM
Craig Wahlmeier
 
Posts: n/a
Default Re: OLEDB and Dates and Timestamps

I finally got some relief from IBM. I opened pmr 85254,370. If I
apply V8 fixpak 5 to both the client and the server, add patch2=24,33
and maptimestampdescribe=1 to the db2cli.ini, my problem is fixed.
(With one exception.) I don't know if the patch1=131072 is also
required, but I have it.

Now, my date fields are observing the regional settings of my client.
My timestamp fields are displaying as true timestamps. The only
problem I am left with concerns date fields containing 0001-01-01.
Those cause ado/oledb to trap. I could add a mapdatedescribe=1 to fix
that error. But, that changes my date layout away from my regional
settings to yyyy-mm-dd. So, I will be forced to find all the queries
that could be affected and add a CHAR function to the SQL.

Thanks for all your replies. We plan to start using the CHAR function
for date and timestamp columns in all our queries in the future. I
don't know what IBM tests back at the lab, but it isn't OLEDB.

Thanks,

Craig Wahlmeier
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:31 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com