Mysql-protocol Date issue
[1/4] from: tim::johnsons-web::com at: 14-Aug-2003 16:41
Hello Rebols:
I've been Dancing With the Snake a lot lately.
- that is - I've been progamming in Python - and this is
part of a project where database tables in Mysql have data
fields which may have a default value of '0000-00-00'.
<Sigh>That is a requirement.</sigh>
Python's MySqlDb API handles date values of this value.
Now I anticipate that I will be processing data for this project with
rebol and mysql-protocol.
Here's the problem:
My current version (0.9.9) of DocKimbel's mysql-protocol throws
an exception if '0000-00-00' is found.
Does anyone know if there is a fix for this, a configuration switch or
whatever? I'd like to avoid hacking Nenad's code to get around this.
Also, I note that the URL for the protocol
(http://rebol.dhs.org/mysql/) is not reachable at this time.
Does anyone if he has relocated?
Thanks!
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com
[2/4] from: dockimbel:free at: 15-Aug-2003 3:56
Hi Tim,
Tim Johnson wrote:
[...]
> Here's the problem:
> My current version (0.9.9) of DocKimbel's mysql-protocol throws
> an exception if '0000-00-00' is found.
The driver tries to convert it to a date! value, but it's an invalid date for
REBOL :
>> 0000-00-00
** Syntax Error: Invalid date -- 0000-00-00
** Near: (line 1) 0000-00-00
> Does anyone know if there is a fix for this, a configuration switch or
> whatever? I'd like to avoid hacking Nenad's code to get around this.
No need to hack ;-), here's a workaround :
- Just after opening the port, add this line :
change-type-handler your-db-port 'date [to string!]
- Now, for this db port only, all MySQL date types will remain as string! (It's
then up to you to decide if and how you want to convert these values)
- You can also provide a little more sophisticate handler for 'date :
to-date-except-zero: func [value][
attempt [value: to date! value]
value
]
change-type-handler your-db-port 'date [to-date-except-zero]
(This one will convert to date! only if possible)
> Also, I note that the URL for the protocol
> (http://rebol.dhs.org/mysql/) is not reachable at this time.
> Does anyone if he has relocated?
http://rebol.softinnov.org/mysql/
HTH,
-DocKimbel
[3/4] from: tim:johnsons-web at: 14-Aug-2003 18:34
* Nenad Rakocevic <[dockimbel--free--fr]> [030814 18:08]:
>
> Hi Tim,
Hello DocKimbel,
> Tim Johnson wrote:
> [...]
<<quoted lines omitted: 9>>
> > whatever? I'd like to avoid hacking Nenad's code to get around this.
> No need to hack ;-), here's a workaround :
Oh Good!
> - Just after opening the port, add this line :
>
> change-type-handler your-db-port 'date [to string!]
Just what I was looking for!
Thanks!
~tj~
> - Now, for this db port only, all MySQL date types will remain as string! (It's
> then up to you to decide if and how you want to convert these values)
<<quoted lines omitted: 14>>
> To unsubscribe from this list, just send an email to
> [rebol-request--rebol--com] with unsubscribe as the subject.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com
[4/4] from: amicom:sonic at: 14-Aug-2003 19:27
Tim,
Here's a couple of functions I use for precisely that purpose:
pad: func [str len /local tmp][
if not string? str [str: form str]
tmp: copy ""
insert/dup tmp "0" len
change/part tmp head reverse str length? str
head reverse tmp
]
mysql-date: func [date /local out][
if error? try [
if string? date [date: to-date date]
out: rejoin [date/year "-" pad date/month 2 "-" pad
date/day 2]
][out: copy ""]
out
]
Bohdan "Bo" Lechnowsky
Lechnowsky Technical Consulting
At 04:41 PM 8/14/03 -0800, you wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted