Changeset 7902 in project


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

Added more map funcs. Added enum variables. Updated eggdoc.

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

Legend:

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

    r5473 r7902  
    55(use eggdoc)
    66
    7 (define doc
    8   `((eggdoc:begin
    9      (name "mysql")
    10      (description (p "MySQL bindings for Chicken."))
    11      (author (url "mailto:toby@butzon.com" "Toby Butzon"))
    12      (history  (version "1.2" "Fix for ticket #297 [Mario Domenech Goulart].")
    13                (version "1.1" "Cross-platform compilation fixes, et al.")
    14               (version "1.0" "Initial release"))
    15      (requires (span "MySQL client library (" (tt "-lmysqlclient") ")"))
    16      (usage)
    17      (download "mysql.egg")
    18 
    19      (documentation
    20       (p
    21 "The MySQL egg provides (most of) the functions offered by the MySQL C API
    22 (the " (tt "foreign-mysql-*") " functions).
    23 It also maps those to a set of slightly more convenient Scheme functions
    24 (the " (tt "mysql-*") " functions).
    25 Finally, a few extra functions are provided for easy of use.
    26 ")
    27       (p
    28 "Only the most often used
    29         MySQL functions are described in this document. If you really
    30 want to see the full listing, consult the " (url "mysql-mole.html" "mole
    31 documentation") ".")
    32       (p
    33 "Please send bug reports and suggestions to "
    34 (url "mailto:toby@butzon.com" "toby@butzon.com") ".")
    35       (group
    36        (procedure "(mysql-connect [KEYWORDS])"
    37                   (p "Connect to a MySQL server.")
    38                   (p "Returns a MySQL connection object suitable for passing
    39                      to the other MySQL functions. This object is referred to
    40                      as " (tt "DB") " when passed by all the other MySQL
    41                      functions. Returns " (tt "#f") " when the connection
    42                      fails.")
    43                   (p "Any number of the following " (tt "KEYWORDS")
    44                      " may be included:"
    45                      (ul
    46                        (li "host")
    47                        (li "user")
    48                        (li "passwd")
    49                        (li "db")
    50                        (li "port")
    51                        (li "unix-socket")
    52                        (li "client-flag")))
    53                   (p "Note that default values are available for all of these
    54                      arguments. (Consult the "
    55                      (url "http://dev.mysql.com/doc/mysql/en/c.html"
    56                           "MySQL C API")
    57                      " for details
    58                      on how these defaults are determined.)"))
    59         (procedure "(mysql-query DB SQL-STRING)"
    60                    (p "Executes " (tt "SQL-STRING") " on the MySQL server
    61                       and stores the result in memory. Generates an error
    62                       (calls " (tt "error") ") if the query fails."))
    63         (procedure "(mysql-fetch-row DB)"
    64                    (p "Fetches a row from the result set returned by the
    65                       most recent call to " (tt "mysql-query") ". If the
    66                       last query failed, or if there are no more rows left
    67                       in the result set, returns " (tt "#f") "; otherwise
    68                       returns a row object.")
    69                    (a (@ (" name='rowobj'")))
    70                    (p
    71                       "A row object is defined as a function that
    72                       takes a single argument. If the argument is a number,
    73                       the function returns the value of the field for which
    74                       that number is the index, or " (tt "#f") " if the
    75                       index is out of range. Otherwise, the argument must
    76                       be a symbol or string, in which case the function returns
    77                       the value of the field for which that string (or symbol
    78                       converted into a string) is the field/column name. If
    79                       no such field exists, returns " (tt "#f") "."))
    80         (procedure "(mysql-rewind DB)"
    81                    (p "Rewinds the result set; that is, resets the pointer
    82                       used by " (tt "mysql-fetch-row") " so that the next
    83                       call to it will return the first row of the result
    84                       set. If there is no current result set, does nothing."))
    85         (procedure "(mysql-close DB)"
    86                    (p "Closes the connection to " (tt "DB") ". This frees
    87                       any remaining MySQL resources from memory, but
    88                       invalidates the MySQL connection object (" (tt "DB") ")
    89                       so that it may no longer be used."))
    90         (procedure "(mysql-foreach-row DB BODY)"
    91                    (p "Iterates over the entire result set (regardless of
    92                       any rows that may have already been returned by
    93                       " (tt "mysql-fetch-row") "), calling
    94                       " (tt "BODY") " on each row.")
    95                    (p (tt "BODY") " must take two arguments: the row (as
    96                       " (url "#rowobj" "described") " for "
    97                       (tt "mysql-fetch-row")
    98                       " and the index of that row in the result set, starting
    99                       with " (tt "1") " and ending with "
    100                       (tt "(mysql-num-rows DB)") "."))
    101         (procedure "(mysql-num-rows DB)"
    102                    (p "Returns the number of rows in the current result
    103                       set. If no result set exists, returns " (tt "#f") "."))
    104         (procedure "(mysql-query-foreach DB QUERY BODY)"
    105                    (p "Combines " (tt "mysql-query") " and "
    106                       (tt "mysql-foreach-row") "."))
    107       ))
    108        
    109      (examples
    110       (p "A bulky usage might look like:"
    111          (pre #<<END
    112 (use mysql)
    113 
    114 (let [(db (mysql-connect host: "mysql.example.com" user: "example"
    115                           passwd: "secret"))]
    116   (if (not db) (error (conc "MySQL connection failed: " (mysql-error db))))
    117   (mysql-query db "SHOW DATABASES")
    118   (do [(row (mysql-fetch-row db) (mysql-fetch-row db))]
    119     [(not row)]
    120     (display (conc "Row " idx ": " (row "Database") "\n")))
    121   (mysql-close db))
    122 END
    123          )) ; pre and p
    124       (p "A slightly more compact version that does the same thing:"
    125          (pre #<<END
    126 (use mysql)
    127 
    128 (let [(db (mysql-connect host: "mysql.example.com" user: "example"
    129                          passwd: "secret"))]
    130   (if (not db) (error (conc "MySQL connection failed: " (mysql-error db))))
    131   (mysql-query-foreach db "SHOW DATABASES" (lambda (row idx)
    132     (display (conc "Row " idx ": " (row "Database") "\n"))))
    133   (mysql-close db))
    134 END
    135          )) ; pre and p
    136       ) ; examples
    137 
    138      (section "Data Type Conversion"
    139       (p "All MySQL result data (except NULL) are returned as Scheme strings.
    140          The NULL
    141          value is represented by " (tt "#f") ". Booleans
    142          are expressed as Scheme strings " (tt "\"1\"") " and "
    143          (tt "\"0\"") ". All remaining types, including numeric types and
    144          strings are returned as Scheme strings.")
    145       ) ; section "Data Type Conversion"
    146 
    147      (section "Bugs"
    148        (p "This is alpha quality software. Only very basic functionality
    149           has been tested so far. I look forward to providing a more complete
    150           test suite (and probably a slew of bugfixes) with the next release.")
    151        (p "Retrieval of field info isn't supported.")
    152        (p (tt "mysql-escape-string") " is broken when it's used for
    153           binary data.")
    154        (p "Not yet sure how to handle " (tt "unsigned long *") " for "
    155           (tt "foreign-mysql-fetch-lengths") ".")
    156        (p (tt "foreign-mysql-get-charset-info") " isn't yet supported.")
    157        (p "I need to nail down the supported libmysqlclient versions. Right
    158           now there are some functions I've put off because they may or may
    159           not be supported in my target range. We'll see, soon...")
    160      ) ; section "Bugs"
    161 
    162      (license
    163 "Copyright (c) 2005 Toby Butzon.
     7(define license-text #<<END
     8Copyright (c) 2005 Toby Butzon.
    1649
    16510Permission is hereby granted, free of charge, to any person obtaining a
     
    17924OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    18025ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    181 OTHER DEALINGS IN THE SOFTWARE."))))
    182 
     26OTHER DEALINGS IN THE SOFTWARE.
     27END
     28)
     29
     30(define ex1-text #<<END
     31(use mysql)
     32
     33(let [(db (mysql-connect host: "mysql.example.com" user: "example"
     34                         passwd: "secret"))]
     35  (if (not db) (error (conc "MySQL connection failed: " (mysql-error db))))
     36  (mysql-query db "SHOW DATABASES")
     37  (do [(row (mysql-fetch-row db) (mysql-fetch-row db))]
     38      [(not row)]
     39    (display (conc "Row " idx ": " (row "Database") "\n")))
     40  (mysql-close db))
     41END
     42)
     43
     44(define ex2-text #<<END
     45(use mysql)
     46
     47(let [(db (mysql-connect host: "mysql.example.com" user: "example"
     48                         passwd: "secret"))]
     49  (if (not db) (error (conc "MySQL connection failed: " (mysql-error db))))
     50  (mysql-query-foreach db "SHOW DATABASES"
     51                       (lambda (row idx)
     52                         (display (conc "Row " idx ": " (row "Database") "\n"))))
     53  (mysql-close db))
     54END
     55)
     56
     57(define doc `(
     58  (eggdoc:begin
     59    (name "mysql")
     60    (description (p "MySQL bindings for Chicken."))
     61    (author (url "mailto:toby@butzon.com" "Toby Butzon"))
     62    (history
     63      (version "1.3" "Additional functions [Kon Lovett].")
     64      (version "1.2" "Fix for ticket #297 [Mario Domenech Goulart].")
     65      (version "1.1" "Cross-platform compilation fixes, et al.")
     66      (version "1.0" "Initial release") )
     67    (requires (span "MySQL client library (" (tt "-lmysqlclient") ")"))
     68    (usage)
     69    (download "mysql.egg")
     70
     71    (documentation
     72
     73      (p
     74        "The MySQL egg provides (most of) the functions offered by the MySQL C "
     75        "API (the " (tt "foreign-mysql-*") " functions). It also maps those to a "
     76        "set of slightly more convenient Scheme functions (the " (tt "mysql-*") " "
     77        "functions). Finally, a few extra functions are provided for easy of use.")
     78
     79      (p
     80        "Only the most often used MySQL functions are described in this "
     81        "document. If you really want to see the full listing, consult the "
     82        (url "mysql-mole.html" "mole documentation") ".")
     83
     84      (p
     85        "Please send bug reports and suggestions to "
     86        (url "mailto:toby@butzon.com" "toby@butzon.com") ".")
     87
     88      (subsection "Connections"
     89
     90        (procedure "(mysql-connect [KEYWORDS])"
     91          (p
     92            "Connect to a MySQL server.")
     93          (p
     94            "Returns a MySQL connection object suitable for passing to "
     95            "the other MySQL functions. This object is referred to as "
     96            (tt "DB") " when passed by all the other MySQL functions. "
     97            "Returns " (tt "#f") " when the connection fails.")
     98          (p
     99            "Any number of the following " (tt "KEYWORDS") " may be included:"
     100            (ul
     101              (li "host")
     102              (li "user")
     103              (li "passwd")
     104              (li "db")
     105              (li "port")
     106              (li "unix-socket")
     107              (li "client-flag")))
     108          (p
     109            "Note that default values are available for all of these "
     110            "arguments. (Consult the "
     111            (url "http://dev.mysql.com/doc/mysql/en/c.html" "MySQL C API") " "
     112            "for details on how these defaults are determined.)") )
     113
     114        (procedure "(mysql-close DB)"
     115          (p
     116            "Closes the connection to " (tt "DB") ". This frees any remaining "
     117            "MySQL resources from memory, but invalidates the MySQL connection "
     118            "object (" (tt "DB") ") so that it may no longer be used.") )
     119      )
     120
     121      (subsection "Basic Operations"
     122
     123        (procedure "(mysql-query DB SQL-STRING)"
     124          (p
     125            "Executes " (tt "SQL-STRING") " on the MySQL server "
     126            "and stores the result in memory. Generates an error "
     127            "(calls " (tt "error") ") if the query fails.") )
     128
     129        (procedure "(mysql-fetch-row DB)"
     130          (p
     131            "Fetches a row from the result set returned by the "
     132            "most recent call to " (tt "mysql-query") ". If the "
     133            "last query failed, or if there are no more rows left "
     134            "in the result set, returns " (tt "#f") "; otherwise "
     135            "returns a row object.")
     136          (a (@ (" name='rowobj'")))
     137          (p
     138            "A row object is defined as a function that "
     139            "takes a single argument. If the argument is a number, "
     140            "the function returns the value of the field for which "
     141            "that number is the index, or " (tt "#f") " if the "
     142            "index is out of range. Otherwise, the argument must "
     143            "be a symbol or string, in which case the function returns "
     144            "the value of the field for which that string (or symbol "
     145            "converted into a string) is the field/column name. If "
     146            "no such field exists, returns " (tt "#f") ".") )
     147
     148        (procedure "(mysql-rewind DB)"
     149          (p
     150            "Rewinds the result set; that is, resets the pointer used by "
     151            (tt "mysql-fetch-row") " so that the next call to it will "
     152            "return the first row of the result set. If there is no current "
     153            "result set, does nothing.") )
     154
     155        (procedure "(mysql-num-rows DB)"
     156          (p
     157            "Returns the number of rows in the current result set. "
     158            "If no result set exists, returns " (tt "#f") ".") )
     159      )
     160
     161      (subsection "Row Mapping"
     162
     163        (procedure "(mysql-row-fold DB PROC INIT)"
     164          (p
     165            "Iterates over the entire result set (regardless of any rows that may "
     166            "have already been returned by " (tt "mysql-fetch-row") "), calling "
     167            (tt "PROC") " on each row.")
     168          (p
     169            "Returns the final accumulated value.")
     170          (p
     171            (tt "PROC") " must take three arguments: the row (as "
     172            (url "#rowobj" "described") ") for " (tt "mysql-fetch-row") ", "
     173            "the index of that row in the result set, starting with " (tt "1") " "
     174            "and ending with " (tt "(mysql-num-rows DB)") ", and the "
     175            "current accumulated value (initially " (tt "INIT") ").")
     176          (p
     177            (tt "PROC") " must return a value.") )
     178
     179        (procedure "(mysql-row-for-each DB PROC)"
     180          (p
     181            "Iterates over the entire result set (regardless of any rows that "
     182            "may have already been returned by " (tt "mysql-fetch-row") "), calling "
     183            (tt "PROC") " on each row.")
     184          (p
     185            (tt "PROC") " must take three arguments: the row (as "
     186            (url "#rowobj" "described") ") for " (tt "mysql-fetch-row")
     187            ", and the index of that row in the result set, starting with "
     188            (tt "1") " and ending with " (tt "(mysql-num-rows DB)") ".") )
     189
     190        (procedure "(mysql-row-map DB PROC)"
     191          (p
     192            "Iterates over the entire result set (regardless of any rows that "
     193            "may have already been returned by " (tt "mysql-fetch-row") "), "
     194            "calling " (tt "PROC") " on each row.")
     195          (p
     196            "Returns the list of results of the " (tt "PROC") " invocations.")
     197          (p
     198            (tt "PROC") " must take three arguments: the row (as "
     199            (url "#rowobj" "described") ") for " (tt "mysql-fetch-row")
     200            ", and the index of that row in the result set, starting "
     201            "with " (tt "1") " and ending with " (tt "(mysql-num-rows DB)") ".")
     202          (p
     203            (tt "PROC") " must return a value.") )
     204
     205        (procedure "(mysql-query-fold DB QUERY PROC INIT)"
     206          (p
     207            "Combines " (tt "mysql-query") " and " (tt "mysql-row-fold") ".") )
     208
     209        (procedure "(mysql-query-for-each DB QUERY PROC)"
     210          (p
     211            "Combines " (tt "mysql-query") " and " (tt "mysql-row-for-each") ".") )
     212
     213        (procedure "(mysql-query-map DB QUERY PROC)"
     214          (p
     215            "Combines " (tt "mysql-query") " and " (tt "mysql-row-map") ".") )
     216
     217        (procedure "(mysql-foreach-row DB BODY)"
     218          (p
     219            "Synonym for " (code "mysql-row-for-each") ".") )
     220
     221        (procedure "(mysql-query-foreach DB QUERY BODY)"
     222          (p
     223            "Synonym for " (code "mysql-query-for-each") ".") )
     224      )
     225
     226      (subsection "Field Access"
     227
     228        (subsubsection "Field Set Access"
     229
     230          (procedure "(mysql-fetch-field-items DB MYSQL-FIELD-GETTER ...)"
     231            (p
     232              "Returns a list of lists of MYSQL_FIELD entry values, "
     233              "a list for each " (tt "MYSQL-FIELD-GETTER") ".")
     234            (p
     235              (tt "MYSQL-FIELD-GETTER") " is a " (code "mysql-field-*") " "
     236              "reference function.") )
     237
     238          (procedure "(*mysql-fetch-field-item MYSQL-FIELD-POINTER FIELD-COUNT MYSQL-FIELD-GETTER)"
     239            (p
     240              "Returns a " (tt "FIELD-COUNT") " length list of MYSQL_FIELD entry (object).")
     241            (p
     242              (tt "MYSQL-FIELD-POINTER") " is a pointer to a vector of MYSQL_FIELD. "
     243              (tt "FIELD-COUNT") " is the number of entries in the vector. "
     244              (tt "MYSQL-FIELD-GETTER") " is a " (code "mysql-field-*") " "
     245              "reference function.") )
     246        )
     247
     248        (subsubsection "Field Entry Access"
     249
     250          (procedure "(mysql-field-org-name MYSQL-FIELD-POINTER)"
     251            (p
     252              "Returns " (code "string") ".") )
     253
     254          (procedure "(mysql-field-name MYSQL-FIELD-POINTER)"
     255            (p
     256              "Returns " (code "string") ".") )
     257
     258          (procedure "(mysql-field-org-table MYSQL-FIELD-POINTER)"
     259            (p
     260              "Returns " (code "string") ".") )
     261
     262          (procedure "(mysql-field-org-table MYSQL-FIELD-POINTER)"
     263            (p
     264              "Returns " (code "string") ".") )
     265
     266          (procedure "(mysql-field-db MYSQL-FIELD-POINTER)"
     267            (p
     268              "Returns " (code "pointer -> ?") ".") )
     269
     270          (procedure "(mysql-field-catalog MYSQL-FIELD-POINTER)"
     271            (p
     272              "Returns " (code "pointer -> ?") ".") )
     273
     274          (procedure "(mysql-field-def MYSQL-FIELD-POINTER)"
     275            (p
     276              "Returns " (code "pointer -> ?") ".") )
     277
     278          (procedure "(mysql-field-table MYSQL-FIELD-POINTER)"
     279            (p
     280              "Returns " (code "pointer -> ?") ".") )
     281
     282          (procedure "(mysql-field-type MYSQL-FIELD-POINTER)"
     283            (p
     284              "Returns " (code "enum enum_field_types value") ".") )
     285
     286          (procedure "(mysql-field-charsetnr MYSQL-FIELD-POINTER)"
     287            (p
     288              "Returns " (code "unsigned-integer") ".") )
     289
     290          (procedure "(mysql-field-flags MYSQL-FIELD-POINTER)"
     291            (p
     292              "Returns " (code "unsigned-integer") ".") )
     293
     294          (procedure "(mysql-field-decimals MYSQL-FIELD-POINTER)"
     295            (p
     296              "Returns " (code "unsigned-integer") ".") )
     297
     298          (procedure "(mysql-field-def-length MYSQL-FIELD-POINTER)"
     299            (p
     300              "Returns " (code "unsigned-integer") ".") )
     301
     302          (procedure "(mysql-field-catalog-length MYSQL-FIELD-POINTER)"
     303            (p
     304              "Returns " (code "unsigned-integer") ".") )
     305
     306          (procedure "(mysql-field-db-length MYSQL-FIELD-POINTER)"
     307            (p
     308              "Returns " (code "unsigned-integer") ".") )
     309
     310          (procedure "(mysql-field-org-table-length MYSQL-FIELD-POINTER)"
     311            (p
     312              "Returns " (code "unsigned-integer") ".") )
     313
     314          (procedure "(mysql-field-table-length MYSQL-FIELD-POINTER)"
     315            (p
     316              "Returns " (code "unsigned-integer") ".") )
     317
     318          (procedure "(mysql-field-org-name-length MYSQL-FIELD-POINTER)"
     319            (p
     320              "Returns " (code "unsigned-integer") ".") )
     321
     322          (procedure "(mysql-field-name-length MYSQL-FIELD-POINTER)"
     323            (p
     324              "Returns " (code "unsigned-integer") ".") )
     325
     326          (procedure "(mysql-field-max-length MYSQL-FIELD-POINTER)"
     327            (p
     328              "Returns " (code "unsigned-integer") ".") )
     329
     330          (procedure "(mysql-field-length MYSQL-FIELD-POINTER)"
     331            (p
     332              "Returns " (code "unsigned-integer") ".") )
     333        )
     334      )
     335
     336      (subsection "Enumeration Values"
     337
     338        (symbol-table "enum enum_mysql_set_option"
     339          (describe mysql-option-multi-statements-on "")
     340          (describe mysql-option-multi-statements-off "") )
     341
     342        (symbol-table "enum mysql_option"
     343          (describe mysql-opt-connect-timeout "")
     344          (describe mysql-opt-compress "")
     345          (describe mysql-opt-named-pipe "")
     346          (describe mysql-init-command "")
     347          (describe mysql-read-default-file "")
     348          (describe mysql-read-default-group "")
     349          (describe mysql-set-charset-dir "")
     350          (describe mysql-set-charset-name "")
     351          (describe mysql-opt-local-infile "")
     352          (describe mysql-opt-protocol "")
     353          (describe mysql-shared-memory-base-name "")
     354          (describe mysql-opt-read-timeout "")
     355          (describe mysql-opt-write-timeout "")
     356          (describe mysql-opt-use-result "")
     357          (describe mysql-opt-use-remote-connection "")
     358          (describe mysql-opt-use-embedded-connection "")
     359          (describe mysql-opt-guess-connection "")
     360          (describe mysql-set-client-ip "")
     361          (describe mysql-secure-auth "")
     362          (describe mysql-report-data-truncation "") )
     363
     364        (symbol-table "enum enum_field_types"
     365          (describe mysql-type-decimal "")
     366          (describe mysql-type-tiny "")
     367          (describe mysql-type-short "")
     368          (describe mysql-type-long "")
     369          (describe mysql-type-float "")
     370          (describe mysql-type-double "")
     371          (describe mysql-type-null "")
     372          (describe mysql-type-timestamp "")
     373          (describe mysql-type-longlong "")
     374          (describe mysql-type-int24 "")
     375          (describe mysql-type-date "")
     376          (describe mysql-type-time "")
     377          (describe mysql-type-datetime "")
     378          (describe mysql-type-year "")
     379          (describe mysql-type-newdate "")
     380          (describe mysql-type-varchar "")
     381          (describe mysql-type-bit "")
     382          (describe mysql-type-newdecimal "")
     383          (describe mysql-type-enum "")
     384          (describe mysql-type-set "")
     385          (describe mysql-type-tiny-blob "")
     386          (describe mysql-type-medium-blob "")
     387          (describe mysql-type-long-blob "")
     388          (describe mysql-type-blob "")
     389          (describe mysql-type-var-string "")
     390          (describe mysql-type-string "")
     391          (describe mysql-type-geometry "") )
     392      )
     393    ) ; documentation
     394
     395    (examples
     396      (p
     397        "A bulky usage might look like:"
     398        (pre ,ex1-text) )
     399      (p
     400        "A slightly more compact version that does the same thing:"
     401        (pre ,ex2-text) )
     402    ) ; examples
     403
     404    (section "Data Type Conversion"
     405      (p
     406        "All MySQL result data (except NULL) are returned as Scheme strings. "
     407        "The NULL value is represented by " (tt "#f") ". Booleans are expressed "
     408        "as Scheme strings " (tt "\"1\"") " and " (tt "\"0\"") ". All remaining "
     409        "types, including numeric types and strings are returned as Scheme "
     410        "strings.")
     411    ) ; section "Data Type Conversion"
     412
     413    (section "Bugs"
     414      (p
     415        "This is alpha quality software. Only very basic functionality "
     416        "has been tested so far. I look forward to providing a more complete "
     417        "test suite (and probably a slew of bugfixes) with the next release.")
     418      (p
     419        "Does not return native types.")
     420      (p
     421        (tt "mysql-escape-string") " is broken when it's used for binary data.")
     422      (p
     423        "Not yet sure how to handle " (tt "unsigned long *") " for "
     424        (tt "foreign-mysql-fetch-lengths") ".")
     425      (p
     426        (tt "foreign-mysql-get-charset-info") " isn't yet supported.")
     427      (p
     428        "I need to nail down the supported libmysqlclient versions. Right "
     429        "now there are some functions I've put off because they may or may "
     430        "not be supported in my target range. We'll see, soon...")
     431    ) ; section "Bugs"
     432
     433    (license ,license-text)
     434  ) ; eggdoc:begin
     435) ) ; doc
    183436
    184437(eggdoc->html doc)
  • release/3/mysql/trunk/mysql-tests.scm

    r7867 r7902  
    1 #!/usr/bin/csi 
     1#!/usr/bin/csi
    22; vim:ts=2:sw=2:et:
    33; mysql-tests.scm,v 1.3 2005/08/04 09:14:44 tbutzon Exp
     
    99(define *host* #f) ; #f ==> default ==> localhost
    1010
     11#; ;???
    1112(procedure? mysql-connect)
    12 (define db (mysql-connect user: *user* passwd: *passwd* host: *host*))
    13 (display "Database: ")
    14 (display db) (newline)
    1513
    16 (if (not db)
    17   (begin
    18     (display (conc
    19       "Unable to connect to database. You might want to edit \n"
    20       "mysql-tests.scm to set *user*, *passwd*, and *host*.\n"))
    21     (exit)))
     14(define *db* (mysql-connect user: *user* passwd: *passwd* host: *host*))
     15(print "Database: " *db*)
    2216
    23 (display (conc "MySQL errno: " (mysql-errno db) "\n"))
    24 (display (conc "MySQL error: " (mysql-error db) "\n"))
     17(unless *db*
     18  (print "Unable to connect to database.")
     19  (print "You might want to edit \"mysql-tests.scm\" to set *user*, *passwd*, and *host*.")
     20  (exit) )
     21
     22(print "MySQL errno: " (mysql-errno *db*))
     23(print "MySQL error: " (mysql-error *db*))
    2524(newline)
    2625
    27 (define (mysql-print-and-query db query)
    28   (display (conc "QUERY: " query "\n"))
    29   (mysql-query db query))
     26(define (mysql-print-and-query *db* query)
     27  (print "QUERY: " query)
     28  (mysql-query *db* query))
    3029
    31 (display "Performing query: SHOW DATABASES\n")
    32 (mysql-print-and-query db "SHOW DATABASES")
    33 (display (conc "Number of rows: " (mysql-num-rows db) "\n\n"))
    34 (display "The rows can be enumerated one-per-line, like this:\n")
    35 (mysql-foreach-row db (lambda (row row-idx)
     30(print "Performing query: SHOW DATABASES")
     31(mysql-print-and-query *db* "SHOW DATABASES")
     32(print "Number of rows: " (mysql-num-rows *db*))
     33
     34(newline)
     35(print "The rows can be enumerated one-per-line, like this:")
     36(mysql-foreach-row *db* (lambda (row row-idx)
    3637  (display (conc row-idx ": " (row "Database") "\n"))))
    37 (display "\nOr they can just be comma-separated, like so:\n")
    38 (mysql-foreach-row db (lambda (row row-idx)
     38
     39(newline)
     40(display "Or they can just be comma-separated, like so:")
     41(mysql-foreach-row *db* (lambda (row row-idx)
    3942  (display (conc (row "Database")
    40                  (if (< row-idx (mysql-num-rows db)) ", " "\n")))))
     43                 (if (< row-idx (mysql-num-rows *db*)) ", " "\n")))))
    4144
    42 (mysql-print-and-query db "DROP DATABASE IF EXISTS mysql_egg_test")
    43 (mysql-print-and-query db "CREATE DATABASE mysql_egg_test")
    44 (display "selecting database: mysql_egg_test\n")
    45 (mysql-select-db db "mysql_egg_test")
    46 (mysql-print-and-query db "CREATE TABLE test1 (
     45(mysql-print-and-query *db* "DROP DATABASE IF EXISTS mysql_egg_test")
     46
     47(mysql-print-and-query *db* "CREATE DATABASE mysql_egg_test")
     48
     49(print "selecting database: mysql_egg_test")
     50(mysql-select-db *db* "mysql_egg_test")
     51
     52(newline)
     53(mysql-print-and-query *db* "CREATE TABLE test1 (
    4754  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    4855  testboolnn BOOLEAN NOT NULL,
    4956  testbool BOOLEAN DEFAULT NULL
    5057  )")
    51 (mysql-print-and-query db
     58
     59(newline)
     60(mysql-print-and-query *db*
    5261  "INSERT INTO test1 SET testboolnn=TRUE, testbool=NULL")
    53 (mysql-print-and-query db
     62(mysql-print-and-query *db*
    5463  "INSERT INTO test1 SET testboolnn=FALSE, testbool=FALSE")
    55 (mysql-print-and-query db "SELECT testboolnn, testbool FROM test1")
    56 (mysql-foreach-row db (lambda (row idx)
    57   (display (conc "row " idx ": testboolnn=" (row "testboolnn")
    58                  ", testbool="
     64
     65(newline)
     66(mysql-print-and-query *db* "SELECT testboolnn, testbool FROM test1")
     67(mysql-foreach-row *db* (lambda (row idx)
     68  (display (conc "row " idx ": testboolnn=" (row "testboolnn")
     69                 ", testbool="
    5970                 (row "testbool") "\n"))))
    6071
    61 
     72(newline)
     73(mysql-print-and-query *db* "SELECT testboolnn, testbool FROM test1")
     74(let ([names (car (mysql-fetch-field-items *db* mysql-field-name))])
     75  (pretty-print
     76   (mysql-row-map
     77     *db*
     78     (lambda (row idx)
     79       (map (lambda (f) (cons f (row f))) names)))) )
  • release/3/mysql/trunk/mysql.html

    r2989 r7902  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    2 <!-- Generated by eggdoc Revision: 1.19  -->
     2<!-- Generated by eggdoc Revision: 1.20  -->
    33<html>
    44<head>
     
    6565                /* font-size: 1.2em; */
    6666        }
    67         H3, H4, H5, H6 {
     67        H3 {
     68                color: #113;
     69                margin-bottom: 0.5em;
     70        }
     71        H4, H5, H6 {
    6872                color: #113;
    6973                margin-bottom: 1.0em;
     
    154158<h3>Version</h3>
    155159<ul>
    156 <li>1.0 Initial release</li>
    157 <li>1.1 Cross-platform compilation fixes, et al.</li></ul></div>
     160<li>1.3 Additional functions [Kon Lovett].</li>
     161<li>1.2 Fix for ticket #297 [Mario Domenech Goulart].</li>
     162<li>1.1 Cross-platform compilation fixes, et al.</li>
     163<li>1.0 Initial release</li></ul></div>
    158164<div class="section">
    159165<h3>Requires</h3>
     
    166172<div class="section">
    167173<h3>Documentation</h3>
    168 <p>The MySQL egg provides (most of) the functions offered by the MySQL C API
    169 (the <tt>foreign-mysql-*</tt> functions).
    170 It also maps those to a set of slightly more convenient Scheme functions
    171 (the <tt>mysql-*</tt> functions).
    172 Finally, a few extra functions are provided for easy of use.
    173 </p>
    174 <p>Only the most often used
    175         MySQL functions are described in this document. If you really
    176 want to see the full listing, consult the <a href="mysql-mole.html">mole
    177 documentation</a>.</p>
     174<p>The MySQL egg provides (most of) the functions offered by the MySQL C API (the <tt>foreign-mysql-*</tt> functions). It also maps those to a set of slightly more convenient Scheme functions (the <tt>mysql-*</tt> functions). Finally, a few extra functions are provided for easy of use.</p>
     175<p>Only the most often used MySQL functions are described in this document. If you really want to see the full listing, consult the <a href="mysql-mole.html">mole documentation</a>.</p>
    178176<p>Please send bug reports and suggestions to <a href="mailto:toby@butzon.com">toby@butzon.com</a>.</p>
    179 <dl>
     177<div class="subsection">
     178<h4>Connections</h4>
    180179<dt class="definition"><strong>procedure:</strong> (mysql-connect [KEYWORDS])</dt>
    181180<dd>
    182181<p>Connect to a MySQL server.</p>
    183 <p>Returns a MySQL connection object suitable for passing
    184                      to the other MySQL functions. This object is referred to
    185                      as <tt>DB</tt> when passed by all the other MySQL
    186                      functions. Returns <tt>#f</tt> when the connection
    187                      fails.</p>
     182<p>Returns a MySQL connection object suitable for passing to the other MySQL functions. This object is referred to as <tt>DB</tt> when passed by all the other MySQL functions. Returns <tt>#f</tt> when the connection fails.</p>
    188183<p>Any number of the following <tt>KEYWORDS</tt> may be included:
    189184<ul>
     
    195190<li>unix-socket</li>
    196191<li>client-flag</li></ul></p>
    197 <p>Note that default values are available for all of these
    198                      arguments. (Consult the <a href="http://dev.mysql.com/doc/mysql/en/c.html">MySQL C API</a> for details
    199                      on how these defaults are determined.)</p></dd>
     192<p>Note that default values are available for all of these arguments. (Consult the <a href="http://dev.mysql.com/doc/mysql/en/c.html">MySQL C API</a> for details on how these defaults are determined.)</p></dd>
     193<dt class="definition"><strong>procedure:</strong> (mysql-close DB)</dt>
     194<dd>
     195<p>Closes the connection to <tt>DB</tt>. This frees any remaining MySQL resources from memory, but invalidates the MySQL connection object (<tt>DB</tt>) so that it may no longer be used.</p></dd></div>
     196<div class="subsection">
     197<h4>Basic Operations</h4>
    200198<dt class="definition"><strong>procedure:</strong> (mysql-query DB SQL-STRING)</dt>
    201199<dd>
    202 <p>Executes <tt>SQL-STRING</tt> on the MySQL server
    203                       and stores the result in memory. Generates an error
    204                       (calls <tt>error</tt>) if the query fails.</p></dd>
     200<p>Executes <tt>SQL-STRING</tt> on the MySQL server and stores the result in memory. Generates an error (calls <tt>error</tt>) if the query fails.</p></dd>
    205201<dt class="definition"><strong>procedure:</strong> (mysql-fetch-row DB)</dt>
    206202<dd>
    207 <p>Fetches a row from the result set returned by the
    208                       most recent call to <tt>mysql-query</tt>. If the
    209                       last query failed, or if there are no more rows left
    210                       in the result set, returns <tt>#f</tt>; otherwise
    211                       returns a row object.</p><a name='rowobj'></a>
    212 <p>A row object is defined as a function that
    213                       takes a single argument. If the argument is a number,
    214                       the function returns the value of the field for which
    215                       that number is the index, or <tt>#f</tt> if the
    216                       index is out of range. Otherwise, the argument must
    217                       be a symbol or string, in which case the function returns
    218                       the value of the field for which that string (or symbol
    219                       converted into a string) is the field/column name. If
    220                       no such field exists, returns <tt>#f</tt>.</p></dd>
     203<p>Fetches a row from the result set returned by the most recent call to <tt>mysql-query</tt>. If the last query failed, or if there are no more rows left in the result set, returns <tt>#f</tt>; otherwise returns a row object.</p><a name='rowobj'></a>
     204<p>A row object is defined as a function that takes a single argument. If the argument is a number, the function returns the value of the field for which that number is the index, or <tt>#f</tt> if the index is out of range. Otherwise, the argument must be a symbol or string, in which case the function returns the value of the field for which that string (or symbol converted into a string) is the field/column name. If no such field exists, returns <tt>#f</tt>.</p></dd>
    221205<dt class="definition"><strong>procedure:</strong> (mysql-rewind DB)</dt>
    222206<dd>
    223 <p>Rewinds the result set; that is, resets the pointer
    224                       used by <tt>mysql-fetch-row</tt> so that the next
    225                       call to it will return the first row of the result
    226                       set. If there is no current result set, does nothing.</p></dd>
    227 <dt class="definition"><strong>procedure:</strong> (mysql-close DB)</dt>
    228 <dd>
    229 <p>Closes the connection to <tt>DB</tt>. This frees
    230                       any remaining MySQL resources from memory, but
    231                       invalidates the MySQL connection object (<tt>DB</tt>)
    232                       so that it may no longer be used.</p></dd>
     207<p>Rewinds the result set; that is, resets the pointer used by <tt>mysql-fetch-row</tt> so that the next call to it will return the first row of the result set. If there is no current result set, does nothing.</p></dd>
     208<dt class="definition"><strong>procedure:</strong> (mysql-num-rows DB)</dt>
     209<dd>
     210<p>Returns the number of rows in the current result set. If no result set exists, returns <tt>#f</tt>.</p></dd></div>
     211<div class="subsection">
     212<h4>Row Mapping</h4>
     213<dt class="definition"><strong>procedure:</strong> (mysql-row-fold DB PROC INIT)</dt>
     214<dd>
     215<p>Iterates over the entire result set (regardless of any rows that may have already been returned by <tt>mysql-fetch-row</tt>), calling <tt>PROC</tt> on each row.</p>
     216<p>Returns the final accumulated value.</p>
     217<p><tt>PROC</tt> must take three arguments: the row (as <a href="#rowobj">described</a>) for <tt>mysql-fetch-row</tt>, the index of that row in the result set, starting with <tt>1</tt> and ending with <tt>(mysql-num-rows DB)</tt>, and the current accumulated value (initially <tt>INIT</tt>).</p>
     218<p><tt>PROC</tt> must return a value.</p></dd>
     219<dt class="definition"><strong>procedure:</strong> (mysql-row-for-each DB PROC)</dt>
     220<dd>
     221<p>Iterates over the entire result set (regardless of any rows that may have already been returned by <tt>mysql-fetch-row</tt>), calling <tt>PROC</tt> on each row.</p>
     222<p><tt>PROC</tt> must take three arguments: the row (as <a href="#rowobj">described</a>) for <tt>mysql-fetch-row</tt>, and the index of that row in the result set, starting with <tt>1</tt> and ending with <tt>(mysql-num-rows DB)</tt>.</p></dd>
     223<dt class="definition"><strong>procedure:</strong> (mysql-row-map DB PROC)</dt>
     224<dd>
     225<p>Iterates over the entire result set (regardless of any rows that may have already been returned by <tt>mysql-fetch-row</tt>), calling <tt>PROC</tt> on each row.</p>
     226<p>Returns the list of results of the <tt>PROC</tt> invocations.</p>
     227<p><tt>PROC</tt> must take three arguments: the row (as <a href="#rowobj">described</a>) for <tt>mysql-fetch-row</tt>, and the index of that row in the result set, starting with <tt>1</tt> and ending with <tt>(mysql-num-rows DB)</tt>.</p>
     228<p><tt>PROC</tt> must return a value.</p></dd>
     229<dt class="definition"><strong>procedure:</strong> (mysql-query-fold DB QUERY PROC INIT)</dt>
     230<dd>
     231<p>Combines <tt>mysql-query</tt> and <tt>mysql-row-fold</tt>.</p></dd>
     232<dt class="definition"><strong>procedure:</strong> (mysql-query-for-each DB QUERY PROC)</dt>
     233<dd>
     234<p>Combines <tt>mysql-query</tt> and <tt>mysql-row-for-each</tt>.</p></dd>
     235<dt class="definition"><strong>procedure:</strong> (mysql-query-map DB QUERY PROC)</dt>
     236<dd>
     237<p>Combines <tt>mysql-query</tt> and <tt>mysql-row-map</tt>.</p></dd>
    233238<dt class="definition"><strong>procedure:</strong> (mysql-foreach-row DB BODY)</dt>
    234239<dd>
    235 <p>Iterates over the entire result set (regardless of
    236                       any rows that may have already been returned by
    237                       <tt>mysql-fetch-row</tt>), calling
    238                       <tt>BODY</tt> on each row.</p>
    239 <p><tt>BODY</tt> must take two arguments: the row (as
    240                       <a href="#rowobj">described</a> for <tt>mysql-fetch-row</tt> and the index of that row in the result set, starting
    241                       with <tt>1</tt> and ending with <tt>(mysql-num-rows DB)</tt>.</p></dd>
    242 <dt class="definition"><strong>procedure:</strong> (mysql-num-rows DB)</dt>
    243 <dd>
    244 <p>Returns the number of rows in the current result
    245                       set. If no result set exists, returns <tt>#f</tt>.</p></dd>
     240<p>Synonym for <code>mysql-row-for-each</code>.</p></dd>
    246241<dt class="definition"><strong>procedure:</strong> (mysql-query-foreach DB QUERY BODY)</dt>
    247242<dd>
    248 <p>Combines <tt>mysql-query</tt> and <tt>mysql-foreach-row</tt>.</p></dd></dl></div>
     243<p>Synonym for <code>mysql-query-for-each</code>.</p></dd></div>
     244<div class="subsection">
     245<h4>Field Access</h4>
     246<div class="subsubsection">
     247<h5>Field Set Access</h5>
     248<dt class="definition"><strong>procedure:</strong> (mysql-fetch-field-items DB MYSQL-FIELD-GETTER ...)</dt>
     249<dd>
     250<p>Returns a list of lists of MYSQL_FIELD entry values, a list for each <tt>MYSQL-FIELD-GETTER</tt>.</p>
     251<p><tt>MYSQL-FIELD-GETTER</tt> is a <code>mysql-field-*</code> reference function.</p></dd>
     252<dt class="definition"><strong>procedure:</strong> (*mysql-fetch-field-item MYSQL-FIELD-POINTER FIELD-COUNT MYSQL-FIELD-GETTER)</dt>
     253<dd>
     254<p>Returns a <tt>FIELD-COUNT</tt> length list of MYSQL_FIELD entry (object).</p>
     255<p><tt>MYSQL-FIELD-POINTER</tt> is a pointer to a vector of MYSQL_FIELD. <tt>FIELD-COUNT</tt> is the number of entries in the vector. <tt>MYSQL-FIELD-GETTER</tt> is a <code>mysql-field-*</code> reference function.</p></dd></div>
     256<div class="subsubsection">
     257<h5>Field Entry Access</h5>
     258<dt class="definition"><strong>procedure:</strong> (mysql-field-org-name MYSQL-FIELD-POINTER)</dt>
     259<dd>
     260<p>Returns <code>string</code>.</p></dd>
     261<dt class="definition"><strong>procedure:</strong> (mysql-field-name MYSQL-FIELD-POINTER)</dt>
     262<dd>
     263<p>Returns <code>string</code>.</p></dd>
     264<dt class="definition"><strong>procedure:</strong> (mysql-field-org-table MYSQL-FIELD-POINTER)</dt>
     265<dd>
     266<p>Returns <code>string</code>.</p></dd>
     267<dt class="definition"><strong>procedure:</strong> (mysql-field-org-table MYSQL-FIELD-POINTER)</dt>
     268<dd>
     269<p>Returns <code>string</code>.</p></dd>
     270<dt class="definition"><strong>procedure:</strong> (mysql-field-db MYSQL-FIELD-POINTER)</dt>
     271<dd>
     272<p>Returns <code>pointer -&gt; ?</code>.</p></dd>
     273<dt class="definition"><strong>procedure:</strong> (mysql-field-catalog MYSQL-FIELD-POINTER)</dt>
     274<dd>
     275<p>Returns <code>pointer -&gt; ?</code>.</p></dd>
     276<dt class="definition"><strong>procedure:</strong> (mysql-field-def MYSQL-FIELD-POINTER)</dt>
     277<dd>
     278<p>Returns <code>pointer -&gt; ?</code>.</p></dd>
     279<dt class="definition"><strong>procedure:</strong> (mysql-field-table MYSQL-FIELD-POINTER)</dt>
     280<dd>
     281<p>Returns <code>pointer -&gt; ?</code>.</p></dd>
     282<dt class="definition"><strong>procedure:</strong> (mysql-field-type MYSQL-FIELD-POINTER)</dt>
     283<dd>
     284<p>Returns <code>enum enum_field_types value</code>.</p></dd>
     285<dt class="definition"><strong>procedure:</strong> (mysql-field-charsetnr MYSQL-FIELD-POINTER)</dt>
     286<dd>
     287<p>Returns <code>unsigned-integer</code>.</p></dd>
     288<dt class="definition"><strong>procedure:</strong> (mysql-field-flags MYSQL-FIELD-POINTER)</dt>
     289<dd>
     290<p>Returns <code>unsigned-integer</code>.</p></dd>
     291<dt class="definition"><strong>procedure:</strong> (mysql-field-decimals MYSQL-FIELD-POINTER)</dt>
     292<dd>
     293<p>Returns <code>unsigned-integer</code>.</p></dd>
     294<dt class="definition"><strong>procedure:</strong> (mysql-field-def-length MYSQL-FIELD-POINTER)</dt>
     295<dd>
     296<p>Returns <code>unsigned-integer</code>.</p></dd>
     297<dt class="definition"><strong>procedure:</strong> (mysql-field-catalog-length MYSQL-FIELD-POINTER)</dt>
     298<dd>
     299<p>Returns <code>unsigned-integer</code>.</p></dd>
     300<dt class="definition"><strong>procedure:</strong> (mysql-field-db-length MYSQL-FIELD-POINTER)</dt>
     301<dd>
     302<p>Returns <code>unsigned-integer</code>.</p></dd>
     303<dt class="definition"><strong>procedure:</strong> (mysql-field-org-table-length MYSQL-FIELD-POINTER)</dt>
     304<dd>
     305<p>Returns <code>unsigned-integer</code>.</p></dd>
     306<dt class="definition"><strong>procedure:</strong> (mysql-field-table-length MYSQL-FIELD-POINTER)</dt>
     307<dd>
     308<p>Returns <code>unsigned-integer</code>.</p></dd>
     309<dt class="definition"><strong>procedure:</strong> (mysql-field-org-name-length MYSQL-FIELD-POINTER)</dt>
     310<dd>
     311<p>Returns <code>unsigned-integer</code>.</p></dd>
     312<dt class="definition"><strong>procedure:</strong> (mysql-field-name-length MYSQL-FIELD-POINTER)</dt>
     313<dd>
     314<p>Returns <code>unsigned-integer</code>.</p></dd>
     315<dt class="definition"><strong>procedure:</strong> (mysql-field-max-length MYSQL-FIELD-POINTER)</dt>
     316<dd>
     317<p>Returns <code>unsigned-integer</code>.</p></dd>
     318<dt class="definition"><strong>procedure:</strong> (mysql-field-length MYSQL-FIELD-POINTER)</dt>
     319<dd>
     320<p>Returns <code>unsigned-integer</code>.</p></dd></div></div>
     321<div class="subsection">
     322<h4>Enumeration Values</h4><table class="symbol-table">enum enum_mysql_set_option
     323<tr>
     324<td class="symbol">mysql-option-multi-statements-on</td>
     325<td></td></tr>
     326<tr>
     327<td class="symbol">mysql-option-multi-statements-off</td>
     328<td></td></tr></table><table class="symbol-table">enum mysql_option
     329<tr>
     330<td class="symbol">mysql-opt-connect-timeout</td>
     331<td></td></tr>
     332<tr>
     333<td class="symbol">mysql-opt-compress</td>
     334<td></td></tr>
     335<tr>
     336<td class="symbol">mysql-opt-named-pipe</td>
     337<td></td></tr>
     338<tr>
     339<td class="symbol">mysql-init-command</td>
     340<td></td></tr>
     341<tr>
     342<td class="symbol">mysql-read-default-file</td>
     343<td></td></tr>
     344<tr>
     345<td class="symbol">mysql-read-default-group</td>
     346<td></td></tr>
     347<tr>
     348<td class="symbol">mysql-set-charset-dir</td>
     349<td></td></tr>
     350<tr>
     351<td class="symbol">mysql-set-charset-name</td>
     352<td></td></tr>
     353<tr>
     354<td class="symbol">mysql-opt-local-infile</td>
     355<td></td></tr>
     356<tr>
     357<td class="symbol">mysql-opt-protocol</td>
     358<td></td></tr>
     359<tr>
     360<td class="symbol">mysql-shared-memory-base-name</td>
     361<td></td></tr>
     362<tr>
     363<td class="symbol">mysql-opt-read-timeout</td>
     364<td></td></tr>
     365<tr>
     366<td class="symbol">mysql-opt-write-timeout</td>
     367<td></td></tr>
     368<tr>
     369<td class="symbol">mysql-opt-use-result</td>
     370<td></td></tr>
     371<tr>
     372<td class="symbol">mysql-opt-use-remote-connection</td>
     373<td></td></tr>
     374<tr>
     375<td class="symbol">mysql-opt-use-embedded-connection</td>
     376<td></td></tr>
     377<tr>
     378<td class="symbol">mysql-opt-guess-connection</td>
     379<td></td></tr>
     380<tr>
     381<td class="symbol">mysql-set-client-ip</td>
     382<td></td></tr>
     383<tr>
     384<td class="symbol">mysql-secure-auth</td>
     385<td></td></tr>
     386<tr>
     387<td class="symbol">mysql-report-data-truncation</td>
     388<td></td></tr></table><table class="symbol-table">enum enum_field_types
     389<tr>
     390<td class="symbol">mysql-type-decimal</td>
     391<td></td></tr>
     392<tr>
     393<td class="symbol">mysql-type-tiny</td>
     394<td></td></tr>
     395<tr>
     396<td class="symbol">mysql-type-short</td>
     397<td></td></tr>
     398<tr>
     399<td class="symbol">mysql-type-long</td>
     400<td></td></tr>
     401<tr>
     402<td class="symbol">mysql-type-float</td>
     403<td></td></tr>
     404<tr>
     405<td class="symbol">mysql-type-double</td>
     406<td></td></tr>
     407<tr>
     408<td class="symbol">mysql-type-null</td>
     409<td></td></tr>
     410<tr>
     411<td class="symbol">mysql-type-timestamp</td>
     412<td></td></tr>
     413<tr>
     414<td class="symbol">mysql-type-longlong</td>
     415<td></td></tr>
     416<tr>
     417<td class="symbol">mysql-type-int24</td>
     418<td></td></tr>
     419<tr>
     420<td class="symbol">mysql-type-date</td>
     421<td></td></tr>
     422<tr>
     423<td class="symbol">mysql-type-time</td>
     424<td></td></tr>
     425<tr>
     426<td class="symbol">mysql-type-datetime</td>
     427<td></td></tr>
     428<tr>
     429<td class="symbol">mysql-type-year</td>
     430<td></td></tr>
     431<tr>
     432<td class="symbol">mysql-type-newdate</td>
     433<td></td></tr>
     434<tr>
     435<td class="symbol">mysql-type-varchar</td>
     436<td></td></tr>
     437<tr>
     438<td class="symbol">mysql-type-bit</td>
     439<td></td></tr>
     440<tr>
     441<td class="symbol">mysql-type-newdecimal</td>
     442<td></td></tr>
     443<tr>
     444<td class="symbol">mysql-type-enum</td>
     445<td></td></tr>
     446<tr>
     447<td class="symbol">mysql-type-set</td>
     448<td></td></tr>
     449<tr>
     450<td class="symbol">mysql-type-tiny-blob</td>
     451<td></td></tr>
     452<tr>
     453<td class="symbol">mysql-type-medium-blob</td>
     454<td></td></tr>
     455<tr>
     456<td class="symbol">mysql-type-long-blob</td>
     457<td></td></tr>
     458<tr>
     459<td class="symbol">mysql-type-blob</td>
     460<td></td></tr>
     461<tr>
     462<td class="symbol">mysql-type-var-string</td>
     463<td></td></tr>
     464<tr>
     465<td class="symbol">mysql-type-string</td>
     466<td></td></tr>
     467<tr>
     468<td class="symbol">mysql-type-geometry</td>
     469<td></td></tr></table></div></div>
    249470<div class="section">
    250471<h3>Examples</h3>
     
    253474<pre>(use mysql)
    254475
    255 (let [(db (mysql-connect host: &quot;mysql.example.com&quot; user: &quot;example&quot; 
    256                           passwd: &quot;secret&quot;))]
     476(let [(db (mysql-connect host: &quot;mysql.example.com&quot; user: &quot;example&quot;
     477                         passwd: &quot;secret&quot;))]
    257478  (if (not db) (error (conc &quot;MySQL connection failed: &quot; (mysql-error db))))
    258479  (mysql-query db &quot;SHOW DATABASES&quot;)
    259480  (do [(row (mysql-fetch-row db) (mysql-fetch-row db))]
    260     [(not row)]
     481      [(not row)]
    261482    (display (conc &quot;Row &quot; idx &quot;: &quot; (row &quot;Database&quot;) &quot;\n&quot;)))
    262483  (mysql-close db))</pre></p>
     
    264485<pre>(use mysql)
    265486
    266 (let [(db (mysql-connect host: &quot;mysql.example.com&quot; user: &quot;example&quot; 
     487(let [(db (mysql-connect host: &quot;mysql.example.com&quot; user: &quot;example&quot;
    267488                         passwd: &quot;secret&quot;))]
    268489  (if (not db) (error (conc &quot;MySQL connection failed: &quot; (mysql-error db))))
    269   (mysql-query-foreach db &quot;SHOW DATABASES&quot; (lambda (row idx)
    270     (display (conc &quot;Row &quot; idx &quot;: &quot; (row &quot;Database&quot;) &quot;\n&quot;))))
     490  (mysql-query-foreach db &quot;SHOW DATABASES&quot;
     491                       (lambda (row idx)
     492                         (display (conc &quot;Row &quot; idx &quot;: &quot; (row &quot;Database&quot;) &quot;\n&quot;))))
    271493  (mysql-close db))</pre></p></div></div>
    272494<div class="section">
    273495<h3>Data Type Conversion</h3>
    274 <p>All MySQL result data (except NULL) are returned as Scheme strings.
    275          The NULL
    276          value is represented by <tt>#f</tt>. Booleans
    277          are expressed as Scheme strings <tt>&quot;1&quot;</tt> and <tt>&quot;0&quot;</tt>. All remaining types, including numeric types and
    278          strings are returned as Scheme strings.</p></div>
     496<p>All MySQL result data (except NULL) are returned as Scheme strings. The NULL value is represented by <tt>#f</tt>. Booleans are expressed as Scheme strings <tt>&quot;1&quot;</tt> and <tt>&quot;0&quot;</tt>. All remaining types, including numeric types and strings are returned as Scheme strings.</p></div>
    279497<div class="section">
    280498<h3>Bugs</h3>
    281 <p>This is alpha quality software. Only very basic functionality
    282           has been tested so far. I look forward to providing a more complete
    283           test suite (and probably a slew of bugfixes) with the next release.</p>
    284 <p>Retrieval of field info isn't supported.</p>
    285 <p><tt>mysql-escape-string</tt> is broken when it's used for
    286           binary data.</p>
     499<p>This is alpha quality software. Only very basic functionality has been tested so far. I look forward to providing a more complete test suite (and probably a slew of bugfixes) with the next release.</p>
     500<p>Does not return native types.</p>
     501<p><tt>mysql-escape-string</tt> is broken when it's used for binary data.</p>
    287502<p>Not yet sure how to handle <tt>unsigned long *</tt> for <tt>foreign-mysql-fetch-lengths</tt>.</p>
    288503<p><tt>foreign-mysql-get-charset-info</tt> isn't yet supported.</p>
    289 <p>I need to nail down the supported libmysqlclient versions. Right
    290           now there are some functions I've put off because they may or may
    291           not be supported in my target range. We'll see, soon...</p></div>
     504<p>I need to nail down the supported libmysqlclient versions. Right now there are some functions I've put off because they may or may not be supported in my target range. We'll see, soon...</p></div>
    292505<div class="section">
    293506<h3>License</h3>
     
    295508
    296509Permission is hereby granted, free of charge, to any person obtaining a
    297 copy of this software and associated documentation files (the Software),
     510copy of this software and associated documentation files (the &quot;Software&quot;),
    298511to deal in the Software without restriction, including without limitation
    299512the rights to use, copy, modify, merge, publish, distribute, sublicense,
     
    304517in all copies or substantial portions of the Software.
    305518
    306 THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     519THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    307520IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    308521FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  • release/3/mysql/trunk/mysql.scm

    r7883 r7902  
    6767<#
    6868
     69(use lolevel)
     70
     71(require-for-syntax 'srfi-13)
     72
     73(define-for-syntax (c-name->scheme-name str)
     74  (string-downcase (string-translate str "_" "-")) )
     75
    6976(declare
    7077  (usual-integrations)
    7178  (generic)
    7279  (no-procedure-checks-for-usual-bindings)
     80  (unused
     81                mysql-field-db-set!
     82                mysql-field-type-set!
     83                mysql-field-charsetnr-set!
     84                mysql-field-catalog-set!
     85                mysql-field-org-name-set!
     86                mysql-field-name-set!
     87                mysql-field-def-set!
     88                mysql-field-org-table-set!
     89                mysql-field-table-set!
     90                mysql-field-flags-set!
     91                mysql-field-org-table
     92                mysql-field-decimals-set!
     93                mysql-field-def-length-set!
     94                mysql-field-catalog-length-set!
     95                mysql-field-db-length-set!
     96                mysql-field-org-table-length-set!
     97                mysql-field-table-length-set!
     98                mysql-field-org-name-length-set!
     99                mysql-field-name-length-set!
     100                mysql-field-max-length-set!
     101                mysql-field-length-set! )
    73102  (export
    74103
     
    216245    ;; "extended" api
    217246    mysql-rewind
     247
     248    ;; "map" api
     249    mysql-row-fold
     250    mysql-row-for-each
     251    mysql-row-map
     252    mysql-query-fold
     253    mysql-query-for-each
     254    mysql-query-map
     255    ; synonyms
    218256    mysql-foreach-row
    219257    mysql-query-foreach
    220258
     259    ;; field struct api
     260    *mysql-fetch-field-item ; this is rather primitive
     261    mysql-fetch-field-items
     262
     263                mysql-field-name
     264                mysql-field-org-name
     265                mysql-field-table
     266                mysql-field-org-table
     267                mysql-field-db
     268                mysql-field-catalog
     269                mysql-field-def
     270                mysql-field-length
     271                mysql-field-max-length
     272                mysql-field-name-length
     273                mysql-field-org-name-length
     274                mysql-field-table-length
     275                mysql-field-org-table-length
     276                mysql-field-db-length
     277                mysql-field-catalog-length
     278                mysql-field-def-length
     279                mysql-field-flags
     280                mysql-field-decimals
     281                mysql-field-charsetnr
     282                mysql-field-type
     283
    221284    ;; enum enum_mysql_set_option
    222                 #;MYSQL_OPTION_MULTI_STATEMENTS_ON
    223                 #;MYSQL_OPTION_MULTI_STATEMENTS_OFF
     285    mysql-option-multi-statements-on
     286    mysql-option-multi-statements-off
    224287
    225288    ;; enum mysql_option
    226                 #;MYSQL_OPT_CONNECT_TIMEOUT
    227                 #;MYSQL_OPT_COMPRESS
    228                 #;MYSQL_OPT_NAMED_PIPE
    229                 #;MYSQL_INIT_COMMAND
    230                 #;MYSQL_READ_DEFAULT_FILE
    231                 #;MYSQL_READ_DEFAULT_GROUP
    232                 #;MYSQL_SET_CHARSET_DIR
    233                 #;MYSQL_SET_CHARSET_NAME
    234                 #;MYSQL_OPT_LOCAL_INFILE
    235                 #;MYSQL_OPT_PROTOCOL
    236                 #;MYSQL_SHARED_MEMORY_BASE_NAME
    237                 #;MYSQL_OPT_READ_TIMEOUT
    238                 #;MYSQL_OPT_WRITE_TIMEOUT
    239                 #;MYSQL_OPT_USE_RESULT
    240                 #;MYSQL_OPT_USE_REMOTE_CONNECTION
    241                 #;MYSQL_OPT_USE_EMBEDDED_CONNECTION
    242                 #;MYSQL_OPT_GUESS_CONNECTION
    243                 #;MYSQL_SET_CLIENT_IP
    244                 #;MYSQL_SECURE_AUTH
    245                 #;MYSQL_REPORT_DATA_TRUNCATION ) )
     289    mysql-opt-connect-timeout
     290    mysql-opt-compress
     291    mysql-opt-named-pipe
     292    mysql-init-command
     293    mysql-read-default-file
     294    mysql-read-default-group
     295    mysql-set-charset-dir
     296    mysql-set-charset-name
     297    mysql-opt-local-infile
     298    mysql-opt-protocol
     299    mysql-shared-memory-base-name
     300    mysql-opt-read-timeout
     301    mysql-opt-write-timeout
     302    mysql-opt-use-result
     303    mysql-opt-use-remote-connection
     304    mysql-opt-use-embedded-connection
     305    mysql-opt-guess-connection
     306    mysql-set-client-ip
     307    mysql-secure-auth
     308    mysql-report-data-truncation
     309
     310    ;; enum enum_field_types
     311        mysql-type-decimal
     312        mysql-type-tiny
     313        mysql-type-short
     314        mysql-type-long
     315        mysql-type-float
     316        mysql-type-double
     317        mysql-type-null
     318        mysql-type-timestamp
     319        mysql-type-longlong
     320        mysql-type-int24
     321        mysql-type-date
     322        mysql-type-time
     323        mysql-type-datetime
     324        mysql-type-year
     325        mysql-type-newdate
     326        mysql-type-varchar
     327        mysql-type-bit
     328        mysql-type-newdecimal
     329        mysql-type-enum
     330        mysql-type-set
     331        mysql-type-tiny-blob
     332        mysql-type-medium-blob
     333        mysql-type-long-blob
     334        mysql-type-blob
     335        mysql-type-var-string
     336        mysql-type-string
     337        mysql-type-geometry ) )
    246338
    247339;=======================================================================
     
    293385  MYSQL_REPORT_DATA_TRUNCATION )
    294386
    295 #;
    296387(define-foreign-enum (mysql-field-types (enum "enum_field_types"))
    297388  #f  ; No aliases!
     
    324415  MYSQL_TYPE_GEOMETRY )
    325416
    326 #;
    327 (define-foreign-record (mysql-field (c-pointer (struct "MYSQL_FIELD")))
    328   (rename: (cut string-translate <> "_" "-"))
     417(define-foreign-record (mysql-field "MYSQL_FIELD")
     418  (rename: c-name->scheme-name)
    329419  ; No ctor or dtor!
    330420;; This is incomplete/incorrect - not all C-types correct
    331   (c-string name)                       ; Name of column 
    332   (c-string org_name)                   ; Original column name, if an alias 
    333   (c-pointer table)                     ; Table of column if column was a field 
    334   (c-string org_table)                  ; Org table name, if table was an alias 
    335   (c-pointer db)                        ; Database for table 
    336   (c-pointer catalog)                     ; Catalog for table 
    337   (c-pointer def)                       ; Default value (set by mysql_list_fields) 
    338   (unsigned-long length)                ; Width of column (create length) 
    339   (unsigned-long max_length)            ; Max width for selected set 
     421  (c-string name)                       ; Name of column
     422  (c-string org_name)                   ; Original column name, if an alias
     423  (c-pointer table)                     ; Table of column if column was a field
     424  (c-string org_table)                  ; Org table name, if table was an alias
     425  (c-pointer db)                        ; Database for table
     426  (c-pointer catalog)                     ; Catalog for table
     427  (c-pointer def)                       ; Default value (set by mysql_list_fields)
     428  (unsigned-long length)                ; Width of column (create length)
     429  (unsigned-long max_length)            ; Max width for selected set
    340430  (unsigned-integer name_length)
    341431  (unsigned-integer org_name_length)
     
    345435  (unsigned-integer catalog_length)
    346436  (unsigned-integer def_length)
    347   (unsigned-integer flags)              ; Div flags
    348   (unsigned-integer decimals)           ; Number of decimals in field
    349   (unsigned-integer charsetnr)          ; Character set
    350   (mysql-field-types type) )            ; Type of field. See mysql_com.h for types
     437  (unsigned-integer flags)              ; Div flags
     438  (unsigned-integer decimals)           ; Number of decimals in field
     439  (unsigned-integer charsetnr)          ; Character set
     440  (mysql-field-types type) )            ; Type of field. See mysql_com.h for types
     441
     442(define MYSQL_FIELD_SIZE (foreign-value "sizeof(MYSQL_FIELD)" unsigned-integer))
     443
     444(define-macro (gen-public-enum . ?syms)
     445  `(begin
     446     ,@(map
     447        (lambda (sym)
     448          `(define ,(string->symbol (c-name->scheme-name (symbol->string sym))) ,sym) )
     449        ?syms)) )
     450
     451(gen-public-enum
     452  MYSQL_OPTION_MULTI_STATEMENTS_ON
     453  MYSQL_OPTION_MULTI_STATEMENTS_OFF)
     454
     455(gen-public-enum
     456  MYSQL_OPT_CONNECT_TIMEOUT
     457  MYSQL_OPT_COMPRESS
     458  MYSQL_OPT_NAMED_PIPE
     459  MYSQL_INIT_COMMAND
     460  MYSQL_READ_DEFAULT_FILE
     461  MYSQL_READ_DEFAULT_GROUP
     462  MYSQL_SET_CHARSET_DIR
     463  MYSQL_SET_CHARSET_NAME
     464  MYSQL_OPT_LOCAL_INFILE
     465  MYSQL_OPT_PROTOCOL
     466  MYSQL_SHARED_MEMORY_BASE_NAME
     467  MYSQL_OPT_READ_TIMEOUT
     468  MYSQL_OPT_WRITE_TIMEOUT
     469  MYSQL_OPT_USE_RESULT
     470  MYSQL_OPT_USE_REMOTE_CONNECTION
     471  MYSQL_OPT_USE_EMBEDDED_CONNECTION
     472  MYSQL_OPT_GUESS_CONNECTION
     473  MYSQL_SET_CLIENT_IP
     474  MYSQL_SECURE_AUTH
     475  MYSQL_REPORT_DATA_TRUNCATION)
     476
     477(gen-public-enum
     478  MYSQL_TYPE_DECIMAL
     479        MYSQL_TYPE_TINY
     480  MYSQL_TYPE_SHORT
     481  MYSQL_TYPE_LONG
     482  MYSQL_TYPE_FLOAT
     483  MYSQL_TYPE_DOUBLE
     484  MYSQL_TYPE_NULL
     485  MYSQL_TYPE_TIMESTAMP
     486  MYSQL_TYPE_LONGLONG
     487  MYSQL_TYPE_INT24
     488  MYSQL_TYPE_DATE
     489  MYSQL_TYPE_TIME
     490  MYSQL_TYPE_DATETIME
     491        MYSQL_TYPE_YEAR
     492  MYSQL_TYPE_NEWDATE
     493        MYSQL_TYPE_VARCHAR
     494  MYSQL_TYPE_BIT
     495  MYSQL_TYPE_NEWDECIMAL
     496  MYSQL_TYPE_ENUM
     497  MYSQL_TYPE_SET
     498  MYSQL_TYPE_TINY_BLOB
     499  MYSQL_TYPE_MEDIUM_BLOB
     500  MYSQL_TYPE_LONG_BLOB
     501  MYSQL_TYPE_BLOB
     502  MYSQL_TYPE_VAR_STRING
     503  MYSQL_TYPE_STRING
     504  MYSQL_TYPE_GEOMETRY)
    351505
    352506;-----------------------------------------------------------------------
     
    796950        (to-fld-str
    797951          (lambda (val lbl #!optional (tst val))
    798             (if tst (format #t " ~A: \"~A\"" lbl val) "") ) )]
    799     (display (conc "#<mysql-connect"
     952            (if tst (format #f " ~A: \"~A\"" lbl val) "") ) )]
     953    (display (conc "#<mysql-connection"
    800954                   (if (mysql-connection-ptr conn)
    801955                       (conc
     
    8841038      "    (void) mysql_real_escape_string (mysql, *((char **) to), from, length);\n"
    8851039      "}")
    886      #$escstr str (string-length str))
     1040     (location escstr)
     1041     str (string-length str))
    8871042    escstr ) )
    8881043
    889 ;; TODO: foreign-mysql-fetch-field (requires MYSQL_FIELD)
    890 ;; TODO: foreign-mysql-fetch-fields (requires MYSQL_FIELD)
    891 ;; TODO: foreign-mysql-fetch-field-direct (requires MYSQL_FIELD)
    892 ;; TODO: foreign-mysql-fetch-lengths (returns unsigned long *)
     1044;; TODO: mysql-fetch-field (requires MYSQL_FIELD)
     1045;; TODO: mysql-fetch-fields (requires MYSQL_FIELD)
     1046;; TODO: mysql-fetch-field-direct (requires MYSQL_FIELD)
     1047;; TODO: mysql-fetch-lengths (returns unsigned long *)
    8931048
    8941049; After a mysql-query that has results, use mysql-fetch-row to retrieve
     
    10081163; The "extended" MySQL/Scheme API.
    10091164;
    1010 ; This API provides some additional functionality for traversing results
    1011 ; in a Scheme-ish way.
     1165; This API provides some additional functionality.
    10121166;
    10131167
     
    10181172    (foreign-mysql-row-seek (mysql-connection-result conn) res-st) ) )
    10191173
    1020 ; calls body on every row in the current result set. body should take 2
     1174;-----------------------------------------------------------------------
     1175; The "map" MySQL/Scheme API.
     1176;
     1177; This API provides some additional functionality for traversing results
     1178; in a Scheme-ish way.
     1179;
     1180
     1181; calls proc on every row in the current result set. proc should take 3
     1182; arguments: the row (as described for mysql-fetch-row), the row index
     1183; (which starts with 1 and ends with (mysql-num-rows conn), and the
     1184; current accumulated value.
     1185;
     1186; returns the final accumulated value.
     1187;
     1188; note: rewinds the result set before and after iterating over it; thus,
     1189; all rows are included.
     1190;
     1191; you must call mysql-rewind if you later want to iterate over the result set
     1192; using mysql-fetch-row.
     1193(define (mysql-row-fold conn proc init)
     1194  (when conn
     1195    (mysql-rewind conn)
     1196    (let loop ([rownum 1] [acc init])
     1197      (let ([row (mysql-fetch-row conn)])
     1198        (if row
     1199            (loop (fx+ rownum 1) (proc row rownum acc))
     1200            acc ) ) ) ) )
     1201
     1202; calls proc on every row in the current result set. proc should take 2
    10211203; arguments: the row (as described for mysql-fetch-row) and the row index
    10221204; (which starts with 1 and ends with (mysql-num-rows conn).
     1205;
    10231206; note: rewinds the result set before and after iterating over it; thus,
    1024 ; all rows are included, but you must call mysql-rewind if you later want
    1025 ; to iterate over the result set using mysql-fetch-row.
    1026 (define (mysql-foreach-row conn body)
    1027   (mysql-rewind conn)
    1028   (letrec [(foreach-row
    1029              (lambda (conn body rownum)
    1030                (and conn
    1031                     (let [(row (mysql-fetch-row conn))]
    1032                       (or (not row)
    1033                           (begin
    1034                             (body row rownum)
    1035                             (foreach-row conn body (+ rownum 1))))))))]
    1036     (foreach-row conn body 1)) )
    1037 
    1038 ; executes query and then mysql-foreach-row with the given body. the body
    1039 ; must meet the contract specified for the body passed to mysql-foreach-row.
    1040 (define (mysql-query-foreach conn query body)
     1207; all rows are included.
     1208;
     1209; you must call mysql-rewind if you later want to iterate over the result set
     1210; using mysql-fetch-row.
     1211(define (mysql-row-for-each conn proc)
     1212  (mysql-row-fold conn
     1213                  (lambda (row rownum _) (proc row rownum))
     1214                  #t) )
     1215
     1216; calls proc on every row in the current result set. proc should take 2
     1217; arguments: the row (as described for mysql-fetch-row) and the row index
     1218; (which starts with 1 and ends with (mysql-num-rows conn).
     1219;
     1220; returns a list of the results of each proc invocation.
     1221;
     1222; note: rewinds the result set before and after iterating over it; thus,
     1223; all rows are included.
     1224;
     1225; you must call mysql-rewind if you later want to iterate over the result set
     1226; using mysql-fetch-row.
     1227(define (mysql-row-map conn proc)
     1228  (mysql-row-fold conn
     1229                  (lambda (row rownum lst) (cons (proc row rownum) lst))
     1230                  '()) )
     1231
     1232; executes query and then mysql-row-for-each with the given proc. the proc
     1233; must meet the contract specified for the proc passed to mysql-row-for-each.
     1234(define (mysql-query-fold conn query proc init)
    10411235  (mysql-query conn query)
    1042   (mysql-foreach-row conn body) )
    1043 
     1236  (mysql-row-fold conn proc init) )
     1237
     1238; executes query and then mysql-row-for-each with the given proc. the proc
     1239; must meet the contract specified for the proc passed to mysql-row-for-each.
     1240(define (mysql-query-for-each conn query proc)
     1241  (mysql-query conn query)
     1242  (mysql-row-for-each conn proc) )
     1243
     1244; executes query and then mysql-row-for-each with the given proc. the proc
     1245; must meet the contract specified for the proc passed to mysql-row-for-each.
     1246(define (mysql-query-map conn query proc)
     1247  (mysql-query conn query)
     1248  (mysql-row-map conn proc) )
     1249
     1250;
     1251(define mysql-query-foreach mysql-query-for-each)
     1252(define mysql-foreach-row mysql-row-for-each)
     1253
     1254;-----------------------------------------------------------------------
     1255; The MySQL Field structure API.
     1256
     1257; returns list of MYSQL_FIELD entry (object).
     1258(define (*mysql-fetch-field-item field-pointer field-count field-getter)
     1259  (let loop ([fldptr field-pointer]
     1260             [cnt field-count]
     1261             [lst '()])
     1262    (if (fx<= cnt 0)
     1263        lst
     1264        (loop (pointer-offset fldptr MYSQL_FIELD_SIZE)
     1265              (fx- cnt 1)
     1266              (cons (field-getter fldptr) lst)) ) ) )
     1267
     1268; returns list of list of field items (object), or #f.
     1269(define (mysql-fetch-field-items conn . field-getters)
     1270  (and-let* ([res (mysql-connection-result conn)])
     1271    (let ([field-pointer (foreign-mysql-fetch-fields res)]
     1272          [field-count (foreign-mysql-num-fields res)])
     1273      (map
     1274       (cut *mysql-fetch-field-item field-pointer field-count <>)
     1275       field-getters) ) ) )
  • release/3/mysql/trunk/mysql.setup

    r7883 r7902  
    33(define has-exports? (string>=? (chicken-version) "2.310"))
    44
    5 (define mysql-header
     5(define (existing-absolute-pathname dirs #!optional fil ext)
     6  (let ([absdir (make-absolute-pathname dirs #f)])
     7    (and (file-exists? (make-absolute-pathname absdir fil ext))
     8         absdir ) ) )
     9
     10(define mysql-header-search-option
    611  (if (find-header "mysql/mysql.h")
    7       "-I/usr/include/mysql"
    8       ""))
     12      (cond [(existing-absolute-pathname '("usr" "include" "mysql") "mysql" "h")
     13              => (cut string-append "-I" <>) ]
     14            [(existing-absolute-pathname '("usr" "local" "include" "mysql") "mysql" "h")
     15              => (cut string-append "-I" <>) ]
     16            [else
     17              (print "Warning: unknown search path for \"mysql/mysql.h\"") ] )
     18      "" ) )
    919
    1020(compile -s -O2 -d1
    1121        ,@(if has-exports? '(-check-imports -emit-exports mysql.exports) '())
    12   ,mysql-header -lmysqlclient -lz mysqlaux.c mysql.scm)
     22  ,mysql-header-search-option -lmysqlclient -lz
     23  mysqlaux.c mysql.scm)
    1324
    1425(install-extension
Note: See TracChangeset for help on using the changeset viewer.