Changeset 7926 in project


Ignore:
Timestamp:
01/25/08 04:32:24 (12 years ago)
Author:
Kon Lovett
Message:

Bug fix for row map. Added test for fetch lengths.

Location:
release/3/mysql/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/3/mysql/trunk/mysql-tests-body.scm

    r7925 r7926  
    8787       (map (lambda (f) (cons f (row f))) names)))) )
    8888
     89(newline)
     90(mysql-print-and-query *db* "SELECT testboolnn, testbool FROM test1")
     91(mysql-row-for-each
     92  *db*
     93  (lambda (row idx)
     94    (print "Row " idx " lengths: " (mysql-fetch-lengths *db*))))
     95
    8996;; Finished
    9097(newline)
  • release/3/mysql/trunk/mysql.scm

    r7925 r7926  
    7979<#
    8080
    81 (use srfi-4 srfi-12)
     81(use srfi-1 srfi-4 srfi-12)
    8282(use lolevel)
    8383
     
    13721372; returns a u32vector of length num-fields.
    13731373; returns #f when no result set.
    1374 ; signals an exception upon error.
    13751374(define (mysql-fetch-lengths conn)
    1376   (and-let* ([resptr (mysql-connection-result conn)])
    1377     (let ([ulongptr (foreign-mysql-fetch-lengths resptr)])
    1378       (if ulongptr
    1379           (let* ([numflds (foreign-mysql-num-fields resptr)]
    1380                  [siz (* numflds 4)]
    1381                  [store (make-blob siz)])
    1382             (move-memory! ulongptr store siz)
    1383             (blob->u32vector/shared store) )
    1384           (signal-mysql-condition 'mysql-fetch-lengths "no rows to fetch") ) ) ) )
     1375  (and-let* ([resptr (mysql-connection-result conn)]
     1376             [ulongptr (foreign-mysql-fetch-lengths resptr)])
     1377    (let* ([siz (* (foreign-mysql-num-fields resptr) 4)]
     1378           [store (make-blob siz)])
     1379      (move-memory! ulongptr store siz)
     1380      (blob->u32vector/shared store) ) ) )
    13851381
    13861382; After a mysql-query that has results, use mysql-fetch-row to retrieve
     
    15431539; using mysql-fetch-row.
    15441540(define (mysql-row-fold conn proc init)
    1545   (when conn
    1546     (mysql-rewind conn)
    1547     (let loop ([rownum 1] [acc init])
    1548       (let ([row (mysql-fetch-row conn)])
    1549         (if row
    1550             (loop (+ rownum 1) (proc row rownum acc))
    1551             acc ) ) ) ) )
     1541  (mysql-rewind conn)
     1542  (let loop ([rownum 1] [acc init])
     1543    (let ([row (mysql-fetch-row conn)])
     1544      (if row
     1545          (loop (+ rownum 1) (proc row rownum acc))
     1546          acc ) ) ) )
    15521547
    15531548; calls proc on every row in the current result set. proc should take 2
     
    15771572; using mysql-fetch-row.
    15781573(define (mysql-row-map conn proc)
    1579   (mysql-row-fold conn
    1580                   (lambda (row rownum lst) (cons (proc row rownum) lst))
    1581                   '()) )
     1574  (reverse!
     1575    (mysql-row-fold conn
     1576                    (lambda (row rownum lst) (cons (proc row rownum) lst))
     1577                    '())) )
    15821578
    15831579; executes query and then mysql-row-for-each with the given proc. the proc
Note: See TracChangeset for help on using the changeset viewer.