Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 03:10 AM
smcgouga@yahoo.com
 
Posts: n/a
Default ADO dates and '0001-01-01'

Visual Basic 6. ADO 2.8

I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
and have a range from '0001-01-01' to '9999-12-31'. I am trying to
update a date field on the database with a value of '0001-01-01'
(*LOVAL) The problem is that I need to use ADO cursors and can not
use the SQL update command:
"update tbl set dateField = '0001-01-01 where ..." (note this works no
problem)

The problem stems from the limitation on PC dates. the lowest value a
PC date can have is '0100-01-01'. When ADO reads a value of
'0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
with this by formatting on screen.

However I am not able to set an ADO field to '0001-01-01' since it is
not a valid PC date. How can I set a date field back to '0001-01-01'
using updateBatch or update via ADO?

Ive tried saving the ADO RS to XML to fiddle the schema to change the
date field to a character field so that it would accept "0001-01-01".
This works and fools the recordset but will not update the database on
an update/updatebatch!

Could there be a workaround using triggers or a translation DLL? It
would be much better if I could keep the solution within my VB code.

Cheers
Stu

Option Explicit

Dim CN As New ADODB.Connection
Dim RS As New ADODB.Recordset

Private Sub Command1_Click()
Dim sSQL As String
sSQL = "select prikey, anyDate from tbl where prikey = 1"

RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText

Debug.Print RS.Fields("anyDate").Value
'"2005-03-13"

RS.Fields("anyDate").Value = dateserial(1,1,1)
Debug.Print RS.Fields("anyDate").Value
'"0100-01-01" 'close: only 100 years out!

RS.Fields("anyDate").Value = 0
Debug.Print RS.Fields("anyDate").Value
'"00:00:00" 'looks promising but updates DB with '1899-12-31

RS.updatebatch

End Sub

Private Sub Form_Load()
Set CN = New ADODB.Connection

CN.CursorLocation = adUseClient
CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
"System=**SYSTEM_NAME**;" & _
"DBQ=**CATALOG_NAME**;" & _
"Uid=**USERNAME**;" & _
"Pwd=**PASSWORD**;" & _
"Commpression = 1;" & _
"Signon = 2;" & _
"Blocksize=512;" & _
"Prefetch=1;"
End Sub
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 03:10 AM
Rhino
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'


<smcgouga@yahoo.com> wrote in message
news:40e5ab91.0503150321.4d10d38c@posting.google.c om...
> Visual Basic 6. ADO 2.8
>
> I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
> and have a range from '0001-01-01' to '9999-12-31'. I am trying to
> update a date field on the database with a value of '0001-01-01'
> (*LOVAL) The problem is that I need to use ADO cursors and can not
> use the SQL update command:
> "update tbl set dateField = '0001-01-01 where ..." (note this works no
> problem)
>
> The problem stems from the limitation on PC dates. the lowest value a
> PC date can have is '0100-01-01'. When ADO reads a value of
> '0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
> with this by formatting on screen.
>
> However I am not able to set an ADO field to '0001-01-01' since it is
> not a valid PC date. How can I set a date field back to '0001-01-01'
> using updateBatch or update via ADO?
>
> Ive tried saving the ADO RS to XML to fiddle the schema to change the
> date field to a character field so that it would accept "0001-01-01".
> This works and fools the recordset but will not update the database on
> an update/updatebatch!
>
> Could there be a workaround using triggers or a translation DLL? It
> would be much better if I could keep the solution within my VB code.
>
> Cheers
> Stu
>
> Option Explicit
>
> Dim CN As New ADODB.Connection
> Dim RS As New ADODB.Recordset
>
> Private Sub Command1_Click()
> Dim sSQL As String
> sSQL = "select prikey, anyDate from tbl where prikey = 1"
>
> RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText
>
> Debug.Print RS.Fields("anyDate").Value
> '"2005-03-13"
>
> RS.Fields("anyDate").Value = dateserial(1,1,1)
> Debug.Print RS.Fields("anyDate").Value
> '"0100-01-01" 'close: only 100 years out!
>
> RS.Fields("anyDate").Value = 0
> Debug.Print RS.Fields("anyDate").Value
> '"00:00:00" 'looks promising but updates DB with '1899-12-31
>
> RS.updatebatch
>
> End Sub
>
> Private Sub Form_Load()
> Set CN = New ADODB.Connection
>
> CN.CursorLocation = adUseClient
> CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
> "System=**SYSTEM_NAME**;" & _
> "DBQ=**CATALOG_NAME**;" & _
> "Uid=**USERNAME**;" & _
> "Pwd=**PASSWORD**;" & _
> "Commpression = 1;" & _
> "Signon = 2;" & _
> "Blocksize=512;" & _
> "Prefetch=1;"
> End Sub


I don't know anything about ADO and I know darn little about AS/400 for that
matter. However it sounds to me like you might be better off to store null
rather than 0001-01-01 in your date fields.

Personally, I would only ever want to see 0001-01-01 in a date field if it
was the date that some specific thing actually happened but you seem to be
using it as a placeholder, not to represent a real date. Therefore, it would
make more sense to me to store a null, which means "unknown or not
applicable".

I don't know if ADO recognizes the concept of nulls so I don't know if it
has syntax to let you change a value to null but you might want to
investigate this if my argument has persuaded you.

Rhino


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 03:11 AM
smcgouga@yahoo.com
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'

> Personally, I would only ever want to see 0001-01-01 in a date field if it
> was the date that some specific thing actually happened but you seem to be
> using it as a placeholder, not to represent a real date. Therefore, it would
> make more sense to me to store a null, which means "unknown or not
> applicable".


The database field has been defined as not null and other programs are
expecting the '0001-01-01' value. However I agree that using nulls
may have been the "right" way to do it but too many programs depend on
the value '0001-01-01' now.

> I don't know if ADO recognizes the concept of nulls so I don't know if it
> has syntax to let you change a value to null but you might want to
> investigate this if my argument has persuaded you.


Yes ADO will let you use nulls if the field in the database allows
nulls. You can even trick ADO and force nulls (save to xml, edit
recordset definition, open) but the update will cause an error since
the database field still will not allow nulls.

Cheers
Stu
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 03:12 AM
Mark Yudkin
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'

VB6 defines that a date string with a two digit year be windowed to the
1930 - 2029 century. The purpose was to ease Y2K migration, the disadvantage
is that you can't enter dates prior to year 100 - not that these commonly
occur in typical data processing tasks (unless you're an archeologist or a
paleontologist, who has data going back that far?). This is VB6 trying to be
helpful with the 2 digit dates so popularly used prior to the late 1990s,
not a limitation on PC dates, and is clearly documented.

Use the DB2 DATE function to effect the conversion from string to DB2 DATE
in SQL. Another possibility is to use the base Windows APIs to effect
conversion, but this is definitely a lot more work, and will hinder any
subsequent port to VB.NET, which gratuitously changed the internal
representation of dates (to maximize Microsoft's earnings in the consultancy
services?)

<smcgouga@yahoo.com> wrote in message
news:40e5ab91.0503150321.4d10d38c@posting.google.c om...
> Visual Basic 6. ADO 2.8
>
> I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
> and have a range from '0001-01-01' to '9999-12-31'. I am trying to
> update a date field on the database with a value of '0001-01-01'
> (*LOVAL) The problem is that I need to use ADO cursors and can not
> use the SQL update command:
> "update tbl set dateField = '0001-01-01 where ..." (note this works no
> problem)
>
> The problem stems from the limitation on PC dates. the lowest value a
> PC date can have is '0100-01-01'. When ADO reads a value of
> '0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
> with this by formatting on screen.
>
> However I am not able to set an ADO field to '0001-01-01' since it is
> not a valid PC date. How can I set a date field back to '0001-01-01'
> using updateBatch or update via ADO?
>
> Ive tried saving the ADO RS to XML to fiddle the schema to change the
> date field to a character field so that it would accept "0001-01-01".
> This works and fools the recordset but will not update the database on
> an update/updatebatch!
>
> Could there be a workaround using triggers or a translation DLL? It
> would be much better if I could keep the solution within my VB code.
>
> Cheers
> Stu
>
> Option Explicit
>
> Dim CN As New ADODB.Connection
> Dim RS As New ADODB.Recordset
>
> Private Sub Command1_Click()
> Dim sSQL As String
> sSQL = "select prikey, anyDate from tbl where prikey = 1"
>
> RS.Open sSQL, CN, adOpenStatic, adLockBatchOptimistic, adCmdText
>
> Debug.Print RS.Fields("anyDate").Value
> '"2005-03-13"
>
> RS.Fields("anyDate").Value = dateserial(1,1,1)
> Debug.Print RS.Fields("anyDate").Value
> '"0100-01-01" 'close: only 100 years out!
>
> RS.Fields("anyDate").Value = 0
> Debug.Print RS.Fields("anyDate").Value
> '"00:00:00" 'looks promising but updates DB with '1899-12-31
>
> RS.updatebatch
>
> End Sub
>
> Private Sub Form_Load()
> Set CN = New ADODB.Connection
>
> CN.CursorLocation = adUseClient
> CN.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
> "System=**SYSTEM_NAME**;" & _
> "DBQ=**CATALOG_NAME**;" & _
> "Uid=**USERNAME**;" & _
> "Pwd=**PASSWORD**;" & _
> "Commpression = 1;" & _
> "Signon = 2;" & _
> "Blocksize=512;" & _
> "Prefetch=1;"
> End Sub



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 03:12 AM
Jonathan Bailey
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'

I suppose you could choose to update the lovalue fields in ADO by
setting them to another value - lets say '1899-12-31' then add a
change/add trigger on the as400 file to change any of these dates to
lovalue.

Jonathan

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 03:12 AM
Madcap
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'

Can you make the field's default value "0001-01-01" and then pass it a
NULL value from VB? Sorry if this is off base, my DB experience is
mainly in MySQL.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-27-2008, 03:16 AM
cwahlmeier@data-tronics.com
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'

Stu,

Date, Time and Timestamps are the such a pain in ADO. I would suggest
using a command object, but you say you cannot use one.
Next I would suggest that you select the date using a CHAR(anyDate). I
see your comment about fooling the recordset but failing the update...
Thus I wonder if the CHAR will meet the same demise.

Also, what is in your DB2CLI.INI file? There are several settings that
affect the interpretation of the date datatype. Many of them are
dependant on the version of your DB2 Client.

Another question, why doesn't the ADODB.Command object work for you?

Regards,

Craig Wahlmeier

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-27-2008, 07:40 AM
Bob Barrows [MVP]
 
Posts: n/a
Default Re: ADO dates and '0001-01-01'

smcgouga@yahoo.com wrote:
> Visual Basic 6. ADO 2.8
>
> I have an as400 DB2 V5R1 datasource. Dates are defined as *ISO format
> and have a range from '0001-01-01' to '9999-12-31'. I am trying to
> update a date field on the database with a value of '0001-01-01'
> (*LOVAL) The problem is that I need to use ADO cursors and can not
> use the SQL update command:
> "update tbl set dateField = '0001-01-01 where ..." (note this works no
> problem)
>
> The problem stems from the limitation on PC dates. the lowest value a
> PC date can have is '0100-01-01'. When ADO reads a value of
> '0001-01-01' it fills an ADO recordset with "00:00:00". I can deal
> with this by formatting on screen.
>
> However I am not able to set an ADO field to '0001-01-01' since it is
> not a valid PC date. How can I set a date field back to '0001-01-01'
> using updateBatch or update via ADO?
>
> Ive tried saving the ADO RS to XML to fiddle the schema to change the
> date field to a character field so that it would accept "0001-01-01".
> This works and fools the recordset but will not update the database on
> an update/updatebatch!
>
> Could there be a workaround using triggers or a translation DLL? It
> would be much better if I could keep the solution within my VB code.
>

What is the issue with using a SQL statement? Are you aware that under the
covers, ADO is constructing and executing a sql statement to perform the
update? Why can't you just create the sql statement yourself?

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


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 02:33 AM.


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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729