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

Re: SrPersist and sql-c-char question



"Alex Peake" <apeake@comac.com> writes:

> 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?

You may use the following procedure:

,--------------------
|    ;; This procedure adjusts BUFF keeping everything up to the first null
|    ;; char #\^@, as those stored by bind-table into buffers.
|    (define schemeql-trim                     
|      (lambda (buff)                          
|        (let ((len (string-length buff)))     
|          (let loop ((idx 0))                 
|            (cond ((= idx len) buff)          
|                  ((char=? (string-ref buff idx) #\null)
|                   (substring buff 0 idx))    
|                  (else (loop (+ idx 1))))))))
`--------------------

substitute string-copy by schemeql-trim in:

[...]

>               (set! result (append (list (string-copy (read-buffer
> lookup-buffer))
>                                          (string-copy (read-buffer
> display-buffer)))
>                                    result))

Finally, I believe it is a feature (not a bug) that SrPersist behaves
like this, because usually one expect to have "fixed" length buffers
returning from the ODBC layer.  And cleaning those buffers before
returning them would be a major overhead, I guess.

Of course, you can always use SchemeQL without bothering about these
kind of problems. :-)  You can get the latest version at:

ftp://wish.com.mx/pub/scheme/schemeql-0.05-2.plt

I corrected some bugs since version 0.03 (the one published at "PLT
Scheme Libraries and Extensions" web page). Hopefully this new version
will be there soon.  There are quite a few extensions I'd like to add
to SchemeQL yet (union, intersection, interactive support for
`driver-connect', etc.) but I haven't had much time lately.  Anyway,
the SQL Minimum Grammar, and some extensions are included, and may
be useful for basic database interaction.  For one, your `test-odbc'
procedure would become:

,--------------------
| (define test-odbc                    
|   (lambda ()                         
|     (let* ((cursor (find '(ClientProperty)
|                          '(PropertyName PropertyValue))))
|       (finite-cursor->list cursor))))
`--------------------

HTH,
--Francisco