Show
Ignore:
Timestamp:
05/24/09 23:03:14 (10 months ago)
Author:
sjamaan
Message:

Get rid of time parsing procedures -- at least for now.
The problem with datetime is that output is highly dependent on the DateStyle? setting in postgresql.conf. We need to find out a way to obtain that setting or we cannot reliably parse the output of date types.
Another problem is the vector representation; nothing in Chicken can handle date vectors that are not 10 elements long, so it's pretty useless. srfi-18 is still not ported to Chicken 4 either...
Then there's the unparsing of vectors; do you simply unparse every vector to a datetime? Which date type is determined by the vector's length? ugh!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • release/4/postgresql/trunk/postgresql.scm

    r14762 r14763  
    154154(define (bool-parser str) (string=? str "t")) 
    155155 
    156 (define (abstime-parser str) str) 
    157  
    158 (define (reltime-parser str) str) 
    159  
    160 (define (parse-format-string s) 
    161   (let-syntax ((push! (syntax-rules () 
    162                         ((_ value place) 
    163                          (set! place (cons value place)))))) 
    164     (do ([i 0 (+ i 1)] 
    165          [ranges (list)] 
    166          [cur-range (list)] 
    167          [len (string-length s)]) 
    168         ([= i len] 
    169          (when (not (null? cur-range)) 
    170            (push! (cons (- i (length cur-range)) i) 
    171                   ranges)) 
    172          (reverse! ranges)) 
    173       (let ([char (string-ref s i)]) 
    174         (cond ([and (or (null? cur-range) 
    175                         (char=? char (car cur-range))) 
    176                     (char-alphabetic? char)] 
    177                (push! char cur-range)) 
    178               ([and (not (null? cur-range)) 
    179                     (not (char=? char (car cur-range)))] 
    180                (push! (cons (- i (length cur-range)) i) 
    181                       ranges) 
    182                (set! cur-range 
    183                      (if (char-alphabetic? char) 
    184                          (list char) 
    185                          (list))))))))) 
    186  
    187 (define-syntax define-time-parser 
    188   (syntax-rules () 
    189     ((_ name format-string) 
    190      (define name 
    191        (let ((format-ranges (parse-format-string format-string))) 
    192          (lambda (str) 
    193            (apply 
    194             vector 
    195             (map (lambda (range) 
    196                    (if (> (cdr range) (string-length str)) 
    197                        0 
    198                        (string->number 
    199                         (substring str (car range) (cdr range))))) 
    200                  format-ranges)))))))) 
    201  
    202 (define-time-parser date-parser "YYYY-MM-DD") 
    203 (define-time-parser timestamp-parser "YYYY-MM-DD hh:mm:ss.ssssss") 
    204 (define-time-parser timestamp/tz-parser "YYYY-MM-DD hh:mm:ss.sssssszzz") 
    205 (define-time-parser time-parser "hh:mm:ss.ssssss") 
    206  
    207156(define (numeric-parser str) 
    208157  (or (string->number str) 
     
    224173     ("float4" . ,numeric-parser) 
    225174     ("float8" . ,numeric-parser) 
    226      ("abstime" . ,abstime-parser) 
    227      ("reltime" . ,reltime-parser) 
    228      ("date" . ,date-parser) 
    229      ("time" . ,time-parser) 
    230      ("timestamp" . ,timestamp-parser) 
    231      ("timestamptz" . ,timestamp/tz-parser) 
    232175     ("numeric" . ,numeric-parser) 
    233176     ("oid" . ,numeric-parser)))) 
     
    246189     (,char? . ,string) 
    247190     (,boolean? . ,bool-unparser) 
    248      (,number? . ,number->string) 
    249      #;(,vector? . ,vector-unparser)))) 
     191     (,number? . ,number->string)))) 
    250192 
    251193;; Retrieve type-oids from PostgreSQL: