Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: date! and SQL..

From: g:santilli:tiscalinet:it at: 12-Jul-2001 21:56

Hello Chris! On 12-Lug-01, you wrote: C> the correct way to go about inserting with dates? This does more than needed, but maybe you will find it useful. form-sql: func [ "Forms a value into SQL syntax" value /local result chars normal-chars ] [ if none? :value [return "NULL"] if :value = '__last-id [return "LAST_INSERT_ID()"] if date? :value [ return rejoin compose [ "'" (value/year) "-" (value/month) "-" (value/day) (either value/time [reduce [" " value/time/hour ":" value/time/minute ":" value/time/second]] []) "'" ] ] if time? :value [ return rejoin ["'" value/hour ":" value/minute ":" value/second "'"] ] if number? :value [return form value] if block? :value [ if empty? value [return "(NULL)"] ; SQL's quite silly... this is a workaround result: make string! 256 insert tail result "(" foreach element value [ insert insert tail result form-sql :element "," ] return head change back tail result ")" ] if word? :value [return form value] if not any-string? :value [value: mold :value] result: make string! 256 insert tail result "'" normal-chars: complement charset "^(00)^/^-^M^(08)'\" parse/all value [ any [ #"^(00)" (insert tail result "\0") | #"^/" (insert tail result "\n") | #"^-" (insert tail result "\t") | #"^M" (insert tail result "\r") | #"^(08)" (insert tail result "\b") | #"'" (insert tail result "\'") | #"\" (insert tail result "\\") | copy chars some normal-chars (insert tail result chars) ] ] head insert tail result "'" ] (This is part of a set of functions to simplify accessing MySQL from REBOL. If anyone's interested in doing betatesting / providing comments...) Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/