Permalink
Browse files

added postgresql record recv, need docs, tests

  • Loading branch information...
1 parent d96c147 commit ac9e03be15051ba6b6099671883f0f4371860e01 @rmculpepper committed May 16, 2011
Showing with 26 additions and 2 deletions.
  1. +1 −1 private/TODO
  2. +25 −1 private/postgresql/dbsystem.rkt
View
@@ -1,7 +1,6 @@
To do
=====
-- postgresql record type
- remove dbsystem from exports, testing (pass symbol on construction)
- after Racket 5.1.1 release:
@@ -30,6 +29,7 @@ Testing
Types
+- postgresql record type: docs, send
- ODBC use binary format for numeric/decimal
- postgresql domain types, table record types, etc
@@ -90,6 +90,8 @@
;; The following types are not supported.
;; (But putting their names here yields better not-supported errors.)
+ (2249 record () #t)
+
(628 line () #f)
(142 xml () #f)
(702 abstime () #f)
@@ -181,6 +183,27 @@ record = cols:int4 (typeoid:int4 len/-1:int4 data:byte^len)^cols
(polygon (line-string points)
null)))
+(define (recv-record x)
+ (let ([start 0])
+ (define (get-int signed?)
+ (begin0 (integer-bytes->integer x signed? #t start (+ start 4))
+ (set! start (+ start 4))))
+ (define (get-bytes len)
+ (begin0 (subbytes x start (+ start len))
+ (set! start (+ start len))))
+ (define (recv-col)
+ (let* ([typeid (get-int #t)]
+ [len (get-int #t)])
+ (if (= len -1)
+ sql-null
+ (let* ([bin? (= (typeid->format typeid) 1)] ;; binary reader available
+ [reader (and bin? (typeid->type-reader 'recv-record typeid))])
+ (if reader
+ (reader (get-bytes len))
+ 'unreadable)))))
+ (let ([columns (get-int #t)])
+ (build-vector columns (lambda (i) (recv-col))))))
+
#|
(define (recv-numeric x)
(define (get-int2 start) (integer-bytes->integer x #t #t start (+ 2 start)))
@@ -345,6 +368,7 @@ record = cols:int4 (typeoid:int4 len/-1:int4 data:byte^len)^cols
((1186) c-parse-interval)
((1266) c-parse-time-tz)
((1700) c-parse-decimal)
+ ((2249) recv-record)
;; "string" literals have type unknown; just treat as string
((705) recv-string)
@@ -388,7 +412,7 @@ record = cols:int4 (typeoid:int4 len/-1:int4 data:byte^len)^cols
(define (typeid->format x)
(case x
((16 17 18 19 20 21 23 25 26 700 701 1042 1043 705) 1)
- ((600 601 602 603 604 718 1560 1562) 1)
+ ((600 601 602 603 604 718 1560 1562 2249) 1)
(else 0)))
(define (make-unsupported-writer x t)

0 comments on commit ac9e03b

Please sign in to comment.