mysql.lsp

Module index

source

Module: Mysql

Author: Jeff Ober
Version: 1.1
Location: http://static.artfulcode.net/newlisp/mysql.lsp

MySQL database extensions. Requires mysql module and util.lsp.

The Mysql class wraps the MySQL module that comes with newLISP. The mysql5 module is hard-coded in, and must be replaced with the version you intend to use. Does not work with the old mysql 4 module.

All MySQL module functions may be accessed as FOOP methods. The additional functions, fetch-assoc, fetch-all-assoc, simple-escape, query-fields, sql, and sql-value, are defined in MySQL as well in this module.

Additionally, all MySQL functions may be accessed via the operate method (see below).

The only functions that are not simple pass-through to MySQL are connection-based (connect, disconnect, and reconnect) and query.

The Mysql class allows multiple separate instances of MySQL to coexist safely. Also note that currently, due to the way symbols are looked up, if you want to use the sql module together with the Mysql class, you must load this module first.

Version history

1.1 • fixed several symbol name clashes with official mysql module and the sql module
1.0 • initial release

- § -

Mysql:Mysql

syntax: (Mysql:Mysql host user pass schema)
parameter: host - mysql host to connect to
parameter: user - mysql username
parameter: pass - mysql password
parameter: schema - mysql database schema

Creates new instance of the Mysql class.

example:
 (Mysql "localhost" "joe_user" "secret" "test")
 => (Mysql (mysql gensym-n) (host "localhost") (user "joe_user") (pass "secret") (schema "test"))

- § -

:operate

syntax: (:operate Mysql-obj sym-func list-params)
parameter: Mysql-obj - Mysql instance
parameter: sym-func - symbol for function in MySQL
parameter: list-params - list of parameters to which the function shall be applied

example:
 (:operate mysql-object 'fetch-all)
 => equivalent to (MySQL:fetch-all)
 (:operate mysql-object 'query "SELECT username FROM users")
 => equivalent to (MySQL:query "SELECT username FROM users")

- § -

:connect

syntax: (:connect Mysql-obj)
parameter: Mysql-obj - Mysql instance

example:
 (:connect mysql-object) => true

- § -

:disconnect

syntax: (:disconnect Mysql-obj)
parameter: Mysql-obj - Mysql instance

example:
 (:disconnect mysql-object)

- § -

:reconnect

syntax: (:reconnect Mysql-obj)
parameter: Mysql-obj - Mysql instance

example:
 (:reconnect mysql-object)

- § -

:query

syntax: (:query Mysql-obj string-format [arg-1 [arg-2 [arg-n]]])
parameter: Mysql-obj - Mysql instance
parameter: string-format - format string for sql query
parameter: arg-1...n - arguments to format string

query accepts arguments in the same manner as format. Strings passed as arguments of the format string are escaped to be safe for use in a sql string; the result is passed to MySQL:query.

example:
 (:query mysql-obj "INSERT INTO employees (first, last) VALUES ('%s', '%s')" "John" "Doe")

- ∂ -

Artful Code

generated with newLISP  and newLISPdoc
eXTReMe Tracker