This library is installed when using the Mac OS X x86 installer .dmg package
from http://www.mysql.com

To compile MySQL with client libraries use:

./configure --prefix=/usr/local --enable-shared

This library might be in a different location on a particular
installation of MySQL or have a different name.
Change accordingly in the code at the beginning.

The MySQL server itself may reside on a different machine
on the network. The library libmysqlclient will communicate
with that server. The correct connection is created using
the MySQL:connect call.

At the bottom of the module file mysql51.lsp a test routine test-mysql
is included to test for correct installation of MySQL.

In the MySQL:connect call of that test routine the correct parameters
for the MySQL server location and user and password have to be inserted.

Functions available

MySQL:init ................ get a database handle MYSQL
MySQL:connect ............. connect to a database
MySQL:query ............... execute a SQL statement
MySQL:num-rows ............ rows in result of query
MySQL:num-fields .......... columns in result of query
MySQL:fetch-row ........... get row from the query result
MySQL:fetch-all ........... get all rows from the last query
MySQL:database ............ return all database names
MySQL:tables .............. return all tables names
MySQL:fields .............. return all fields in a table
MySQL:data-seek ........... position in result for fetching
MySQL:affected-rows ....... number of affected rows from operation
MySQL:inserted-id ......... last value of auto increment id operation
MySQL:escape .............. escapes SQL input string using mysql_real_escape_string
MySQL:error ............... get error message
MySQL:close-db ............ close database connection

The database server is listening on IP 192.168.1.10. The program
connects with username "auser" password "secret" to a database with
the name "mydb". After connecting SQL statements are performed and
finally the program disconnects from the server.

UTF-8 character encoding

When using newLISP compiled for UTF-8, the following statements
may be necessary at the beginning:

MySQL:init

syntax: (MySQL:init)

return: true on success, nil on failure.

§

MySQL:connect

syntax: (MySQL:connectstr-serverstr-userIDstr-passwordstr-db)parameter: str-server - The host name or IP address or 0 for localhost.parameter: str-userID - The user ID for authentication.parameter: str-password - The password for authentication.parameter: str-db - The name of the database to connect to.

return: true for success or nil for failure.

Connects to a database on server and authenticates a user ID.
(MySQL:init) must have been called previously.

MySQL:query

return: For insert queries rerturns the inserted ID else true for success or nil for failure.

Sends a SQL query string to the database server for evaluation.

§

MySQL:num-rows

syntax: (MySQL:num-rows)

return: Number of rows from last query.

§

MySQL:num-fields

syntax: (MySQL:num-fields)

return: Number of columns from last query.

§

MySQL:fetch-row

syntax: (MySQL:fetch-row)

return: A list of field elements.

Fetches a row from a previous SQL MySQL:queryselect statement.
Subsequent calls fetch row by row from the result table until the
end of the table is reached.

§

MySQL:fetch-all

syntax: (MySQL:fetch-all)

return: All rows/fields from the last query.

The whole result set from the query is returned at once as a list of row lists.

§

MySQL:databases

syntax: (MySQL:databases)

return: A list of databases.

Performs a show databases; query.

§

MySQL:tables

syntax: (MySQL:tables)

return: A list of tables in the database.

Performs a show tables; query.

§

MySQL:fields

syntax: (MySQL:fieldsstr-table)parameter: str-table - The name of the table.

return: A list of field description lists.

For each field name in the table a list of specifications
for that field is returned. The list starts with the name
for the field followed by the type size/precision and
other optional field descriptions.

§

MySQL:data-seek

syntax: (MySQL:data-seeknum-offset)parameter: num-offset - The 0 based offset to position inside the data set.

return: Always true.

Positions in the result set at a zero based offset
for a subsequent MySQL:fetch-row call. If the offset
is out of the allowed range for the result set a subsequent
fetch-row will return nil.

§

MySQL:error

syntax: (MySQL:error)

return: Text info about the last error which occured.

§

MySQL:affected-rows

syntax: (MySQL:affected-rows)

return: Number of affected rows by the last MySQL:query operation.

§

MySQL:inserted-id

syntax: (MySQL:inserted-id)

return: Last insert ID from an auto increment field.

§

MySQL:escape

syntax: (MySQL:escapestr-sql)

return: escaped string

This function will escape special characters in str-sql, so that it
is safe to place it in a MySQL query.

§

MySQL:close-db

syntax: (MySQL:close-db)

return: Always true.

Closes database access. For new database acess, both MySQL:init and
MySQL:connect functions have to be called.