X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=interfaces%2Fpostgresql-socket%2Fpostgresql-socket-api.cl;h=0c64353403fe7912a1378fc567c1d80a20dd91a9;hb=ed0ba77f1cff4820da69c6229018e06b9efad1b5;hp=2cfb1551f602f9102d419da8b280a3c43a73be2b;hpb=1df22499c04a8913878990a36634b3bb07063385;p=clsql.git diff --git a/interfaces/postgresql-socket/postgresql-socket-api.cl b/interfaces/postgresql-socket/postgresql-socket-api.cl index 2cfb155..0c64353 100644 --- a/interfaces/postgresql-socket/postgresql-socket-api.cl +++ b/interfaces/postgresql-socket/postgresql-socket-api.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id: postgresql-socket-api.cl,v 1.7 2002/03/26 17:16:18 kevin Exp $ +;;;; $Id: postgresql-socket-api.cl,v 1.11 2002/03/27 11:13:27 kevin Exp $ ;;;; ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai @@ -36,6 +36,7 @@ ((:bytea 17) (:int2 21) (:int4 23) + (:int8 20) (:float4 700) (:float8 701))) @@ -568,7 +569,7 @@ connection, if it is still open." (defun read-field (socket type) (let ((length (- (read-socket-value 'int32 socket) 4))) (case type - (:int + ((:int :long :longlong) (read-integer-from-socket socket length)) (:double (read-double-from-socket socket length)) @@ -585,28 +586,30 @@ connection, if it is still open." (uffi:def-constant +char-code-upper-e+ (char-code #\E)) (defun read-integer-from-socket (socket length) - (let ((val 0) - (first-char (read-byte socket)) - (minusp nil)) - (declare (fixnum first-char)) - (if (zerop length) - nil - (progn - (cond - ((= first-char +char-code-minus+) - (setq minusp t)) - ((= first-char +char-code-plus+) - ) ; nothing to do - (t - (setq val (- first-char +char-code-zero+)))) - (dotimes (i (1- length)) - (declare (fixnum i)) - (setq val (+ - (* 10 val) - (- (read-byte socket) +char-code-zero+)))) - (if minusp - (- val) - val))))) + (declare (fixnum length)) + (if (zerop length) + nil + (let ((val 0) + (first-char (read-byte socket)) + (minusp nil)) + (declare (fixnum first-char)) + (decf length) ;; read first char + (cond + ((= first-char +char-code-minus+) + (setq minusp t)) + ((= first-char +char-code-plus+) + ) ;; nothing to do + (t + (setq val (- first-char +char-code-zero+)))) + + (dotimes (i length) + (declare (fixnum i)) + (setq val (+ + (* 10 val) + (- (read-byte socket) +char-code-zero+)))) + (if minusp + (- val) + val)))) (defmacro ascii-digit (int) (let ((offset (gensym))) @@ -618,6 +621,7 @@ connection, if it is still open." nil)))) (defun read-double-from-socket (socket length) + (declare (fixnum length)) (let ((before-decimal 0) (after-decimal 0) (decimal-count 0) @@ -626,40 +630,42 @@ connection, if it is still open." (minusp nil) (result nil) (char (read-byte socket))) - (declare (fixnum char)) + (declare (fixnum char exponent decimal-count)) (decf length) ;; already read first character (cond ((= char +char-code-minus+) - (setq minusp t) - (setq char (read-byte socket)) - (decf length)) + (setq minusp t)) ((= char +char-code-plus+) - (setq char (read-byte socket)) - (decf length))) + ) + ((= char +char-code-period+) + (setq decimalp t)) + (t + (setq before-decimal (ascii-digit char)) + (unless before-decimal + (error "Unexpected value")))) - (dotimes (i length) - (let ((weight (ascii-digit char))) - (cond - ((and weight (not decimalp)) ;; before decimal point - (setq before-decimal (+ weight (* 10 before-decimal))) - (setq char (read-byte socket))) - ((and weight decimalp) ;; after decimal point - (setq after-decimal (+ weight (* 10 after-decimal))) - (incf decimal-count) - (setq char (read-byte socket))) - ((and (= char +char-code-period+)) - (setq decimalp t) - (setq char (read-byte socket))) - ((or (= char +char-code-lower-e+) ;; E is for exponent - (= char +char-code-upper-e+)) - (setq exponent (read-integer-from-socket socket (- length i))) - (format t "~&exp: ~a" exponent) - (setq exponent (or exponent 0)) - (setq i length)) + (block loop + (dotimes (i length) + (setq char (read-byte socket)) + ;; (format t "~&len:~D, i:~D, char:~D, minusp:~A, decimalp:~A" length i char minusp decimalp) + (let ((weight (ascii-digit char))) + (cond + ((and weight (not decimalp)) ;; before decimal point + (setq before-decimal (+ weight (* 10 before-decimal)))) + ((and weight decimalp) ;; after decimal point + (setq after-decimal (+ weight (* 10 after-decimal))) + (incf decimal-count)) + ((and (= char +char-code-period+)) + (setq decimalp t)) + ((or (= char +char-code-lower-e+) ;; E is for exponent + (= char +char-code-upper-e+)) + (setq exponent (read-integer-from-socket socket (- length i 1))) + (setq exponent (or exponent 0)) + (return-from loop)) (t (break "Unexpected value")) ) - )) + ))) (setq result (* (+ (coerce before-decimal 'double-float) (* after-decimal (expt 10 (- decimal-count))))