#lang scheme

 (prefix-in psql: "")
 (prefix-in vector: "")
 (prefix-in general: "")

; to generate this table, I used psql and for instance:
; SELECT encode(numeric_send(15.0::numeric(7,5)),'hex');
; thanks to a tip from RhodiumToad

(define casts

(require "")

(general:set-info! (get-engine))
;(numeric:set-info! (get-engine))

(define (apply-values l) (apply values l))

(define (introspect)
  (let-values ([(input output) (psql:generate)])
    (let loop ([oids (send (get-engine) get-oids)])
      (if (null? oids) (void)
          (let ([oid (car oids)])
            (display (format "select oid,typlen from pg_type where typelem = ~a;" oid) output)
              (λ (parent-oid length)
                 (string->number parent-oid)
                 (if (equal? length "-1") #f
                     (string->number length))
                (display (format "oid ~s poid ~s len ~s~n" oid parent-oid length)))
              apply-values) (read input))
            (loop (cdr oids)))))
    (close-input-port input)
    (close-output-port output)))