Changeset 11261 in project


Ignore:
Timestamp:
07/12/08 05:52:58 (11 years ago)
Author:
Kon Lovett
Message:

Save ideas.

Location:
release/3/mysql
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/mysql/foreign-types

    r11162 r11261  
    1 XXX
    2 
    3 (let ([params (allocate-mysql-bind 4)]
    4       [date1 (allocate-mysql-time)])
    5   (time-vector->mysql-time date1 ITIMEVEC1-ARG)
    6   (let-location ([istr c-string ISTRING1-ARG]
    7                  [iflt float INUMBER1-ARG]
    8                  [iuint unsigned-short INUMBER2-ARG])
    9     (mysqlaux-stmt-param-set! params 0 MYSQL_TYPE_VARCHAR #$istr)
    10     (mysqlaux-stmt-param-set! params 1 MYSQL_TYPE_FLOAT #$iflt)
    11     (mysqlaux-stmt-param-set! params 2 MYSQL_TYPE_SHORT #$iunit #:unsigned #t)
    12     (mysqlaux-stmt-param-set! params 3 MYSQL_TYPE_NULL)
    13     (mysql-stmt-bind-param conn params)
    14     (mysql-stmt-execute conn)
    15     (let ([results (allocate-mysql-bind 5)]
    16           [ostr (make-blob OSTRING1-ARG-MAXLEN)]
    17           [oblb (make-blob OBLOB1-ARG-MAXLEN)])
    18       (let-location ([odbl double]
    19                      [oflg char]
    20                      [olng long])
    21         (mysqlaux-stmt-result-set! results 0 MYSQL_TYPE_VARCHAR #$ostr #:length OSTRING1-ARG-MAXLEN)
    22         (mysqlaux-stmt-result-set! results 1 MYSQL_TYPE_MEDIUM_BLOB #$oblb #:length OBLOB1-ARG-MAXLEN)
    23         (mysqlaux-stmt-result-set! results 2 MYSQL_TYPE_DOUBLE #$odbl)
    24         (mysqlaux-stmt-result-set! results 3 MYSQL_TYPE_TINY #$oflg)
    25         (mysqlaux-stmt-result-set! results 3 MYSQL_TYPE_LONG #$olng)
    26         (mysql-stmt-bind-result conn results)
    27         (values (blob->string ostr)
    28                 oblb
    29                 odbl
    30                 (number->boolean oflg)
    31                 olng) ) ) ) )
     1"Lexical" Interface:
     2
     3- Explicit allocation of runtime C typed storage.
     4
     5- Stack based!
     6
     7- 'mysqlaux-stmt-param/result-set!' determines buffer length from the type &
     8"value" (for blob/string types, actual value for param & buffer for result).
     9Has #:length argument override.
     10
     11- Error is rqrd for result. None for param.
     12
     13- Null is rqrd for result. Optional for param.
     14
     15- Length is rqrd for result & param.
     16
     17- Example
     18
     19  ;INPUT query, ITIMEVEC1-ARG, ISTRING1-ARG, INUMBER1-ARG, INUMBER2-ARG
     20
     21  (mysql-stmt-query-init conn query)  ;XXX
     22  (let ([params (allocate-mysql-bind 4)]
     23        [date1 (allocate-mysql-time)])
     24    (mysqlaux-time-vector->mysql-time date1 ITIMEVEC1-ARG MYSQL_TYPE_DATE)
     25    (let-location ([istr c-string ISTRING1-ARG]
     26                   [iflt float INUMBER1-ARG]
     27                   [iuint unsigned-short INUMBER2-ARG]
     28                   [i0len unsigned-long]
     29                   [i1len unsigned-long]
     30                   [i2len unsigned-long])
     31      (mysqlaux-stmt-param-set! params 0
     32        MYSQL_TYPE_VARCHAR   #$istr    #$i0len)
     33      (mysqlaux-stmt-param-set! params 1
     34        MYSQL_TYPE_FLOAT     #$iflt    #$i1len)
     35      (mysqlaux-stmt-param-set! params 2
     36        MYSQL_TYPE_SHORT     #$iunit   #$i2len   #:unsigned #t)
     37      (mysqlaux-stmt-param-set! params 3
     38        MYSQL_TYPE_NULL)
     39      (mysql-stmt-bind-param conn params)  ;XXX
     40      (mysql-stmt-execute conn)  ;XXX
     41      (let ([results (allocate-mysql-bind 5)]
     42            [ostr (make-string OSTRING1-ARG-MAXLEN)]
     43            [oblb (make-string OBLOB1-ARG-MAXLEN)])
     44        (let-location ([odbl double]
     45                       [oflg char]
     46                       [olng long]
     47                       [o0nul my-bool] [o0err my-bool] [o0len unsigned-long]
     48                       [o1nul my-bool] [o1err my-bool] [o1len unsigned-long]
     49                       [o2nul my-bool] [o2err my-bool] [o2len unsigned-long]
     50                       [o3nul my-bool] [o3err my-bool] [o3len unsigned-long]
     51                       [o4nul my-bool] [o4err my-bool] [o4len unsigned-long])
     52          (mysqlaux-stmt-result-set! results 0
     53            MYSQL_TYPE_VARCHAR       #$ostr    #$o0len #$o0nul #$o0err)
     54          (mysqlaux-stmt-result-set! results 1
     55            MYSQL_TYPE_MEDIUM_BLOB   #$oblb    #$o1len #$o1nul #$o1err)
     56          (mysqlaux-stmt-result-set! results 2
     57            MYSQL_TYPE_DOUBLE        #$odbl    #$o2len #$o2nul #$o2err)
     58          (mysqlaux-stmt-result-set! results 3
     59            MYSQL_TYPE_TINY          #$oflg    #$o3len #$o3nul #$o3err)
     60          (mysqlaux-stmt-result-set! results 4
     61            MYSQL_TYPE_LONG          #$olng    #$o4len #$o4nul #$o4err)
     62          (mysql-stmt-bind-result conn results)  ;XXX
     63          (while (mysql-stmt-fetch conn)
     64            (PROCESS-IT
     65             (substring ostr 0 o0len)
     66             (string->blob (substring oblb 0 o1len))
     67             odbl
     68             (number->boolean oflg)
     69             olng) ) ) ) ) )
     70
     71"Procedural" Interface:
     72
     73-
     74
     75(define (PROC row rownum)
     76  ;NOTE: 'row' is a procedure returning a 'mysql-bind-ptr' for a field identifer.
     77)
     78
     79
     80
     81(mysql-stmt-query-map conn PROC query params results) ) ) ) )
     82
     83-----
    3284
    3385Bind Parameter:
  • release/3/mysql/trunk/mysql.scm

    r11090 r11261  
    474474;; my_bool
    475475
    476 (define-foreign-type my-bool "my_bool" (lambda (x) (if x 1 0)) (lambda (x) (not (zero? x))))
     476(define-foreign-type my-bool "my_bool" (lambda (x) (if x 1 0)) (lambda (x) (not (fx= 0 x))))
    477477
    478478;; MYSQL_FIELD_OFFSET
     
    24092409
    24102410(define (allocate-mysql-bind #!optional (cnt 1))
    2411   (and (<= 1 cnt)
    2412        (allocate (* cnt (foreign-value "sizeof( MYSQL_BIND )" int))) ) )
     2411  (and (fx<= 1 cnt)
     2412       (allocate (fx* cnt (foreign-value "sizeof( MYSQL_BIND )" int))) ) )
     2413
     2414;;
     2415
     2416(define (make-mysql-bind #!optional (cnt 1))
     2417  (and-let* ([binds (allocate-mysql-bind cnt)])
     2418    (set-finalizer! binds free-mysql-bind)
     2419    binds ) )
    24132420
    24142421;; Returns c-pointer to MYSQL_BIND at index in a C-vector of MYSQL_BIND
     
    31723179;; Returns a procedure, or #f when no connection.
    31733180;; The procedure takes a field identifier and returns the
    3174 ;; mysql-bind-ptr of the mysql-bind record, or #f
     3181;; mysql-bind-ptr of the field's mysql-bind record, or #f
    31753182;; when no more rows to fetch.
    31763183
Note: See TracChangeset for help on using the changeset viewer.