[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SrPersist and sql-c-char question



In learning about SrPersist, I tried the following test. It all works except
for the strange display of the strings (from the buffers). Each string is 80
characters long, filled with (apparently) null characters, or the contenets
of the previous buffer after the first null. Is there some way to "convert
to scheme strings" so the display properly?

Alex

(define test-odbc
  (lambda()
    (let* ((henv (alloc-env))
           (hdbc (alloc-connect henv)))

      (with-handlers
          ([(lambda (exn) (exn-with-info? exn))
            (lambda (exn) (printf "** ~A **~n" (get-diag-rec hdbc 1)))])
        (driver-connect hdbc "" 'sql-driver-prompt))


      (let ((hstmt (alloc-stmt hdbc)))
	(prepare hstmt "SELECT PropertyName, PropertyValue FROM ClientProperty")
	(execute hstmt)

	(let ((lookup-buffer (make-buffer 'sql-c-char 80))
              (display-buffer (make-buffer 'sql-c-char 80))
              (lookup-indicator (make-indicator))
              (display-indicator (make-indicator))
              (result '()))

          (bind-col hstmt 1 lookup-buffer lookup-indicator)
          (bind-col hstmt 2 display-buffer display-indicator)

          (with-handlers
              ([(lambda (exn) (exn-no-data? exn))
                (lambda (exn) (printf "** End of data **~n"))])
            (let loop ()
              (fetch hstmt)
              (set! result (append (list (string-copy (read-buffer
lookup-buffer))
                                         (string-copy (read-buffer
display-buffer)))
                                   result))
              (loop)))


          (free-stmt hstmt 'sql-unbind)
          (free-stmt hstmt 'sql-close)
          (free-handle hstmt)
          (disconnect hdbc)
          (free-handle hdbc)
          (free-handle henv)
          result)))))