Defines a set of functions to access Database.
(import (rnrs) (mosh dbi))
(let* ([conn (dbi-connect "dbi:mysql:mysql:127.0.0.1:3306" "root" "")]
[query (dbi-prepare conn "select * from user where user = ?")]
[result (dbi-execute query "root")]
[getter (dbi-getter result)])
(for-each
(lambda (row)
(display (getter row "host")))
(dbi-result->list result))
(dbi-close conn))| Database independent interface | Defines a set of functions to access Database. |
| (mosh dbi) | Database independent interface library |
| How to write new dbd. | mosh/dbd/mysql.ss and test/dbi.scm are good sample. |
| Variables | |
| <connection> | Connection class. |
| <dbd> | Database driver class. |
| <result> | Result of query class. |
| <query> | Query class. |
| Functions | |
| dbi-result->list | Returns list of result rows. |
| dbi-getter | Returns getter for <result> which is returned by dbi-execute. |
| dbi-close | Destroy the connection and free resources associated to the connection. |
| dbi-connect | Connect to a database using a data source specified by dsn (data source name). |
| dbi-execute | Executes a query created by dbi-prepare. |
| dbi-prepare | From a string representation of SQL statement sql, creates and returns a query object (an instance of <query> or its subclass) for the database connection conn Sql may contain parameter slots, denoted by ?. |
| dbi-do | This is a convenience procedure when you create a query and immediately execute it. |
Database independent interface library
| How to write new dbd. | mosh/dbd/mysql.ss and test/dbi.scm are good sample. |
| Variables | |
| <connection> | Connection class. |
| <dbd> | Database driver class. |
| <result> | Result of query class. |
| <query> | Query class. |
| Functions | |
| dbi-result->list | Returns list of result rows. |
| dbi-getter | Returns getter for <result> which is returned by dbi-execute. |
| dbi-close | Destroy the connection and free resources associated to the connection. |
| dbi-connect | Connect to a database using a data source specified by dsn (data source name). |
| dbi-execute | Executes a query created by dbi-prepare. |
| dbi-prepare | From a string representation of SQL statement sql, creates and returns a query object (an instance of <query> or its subclass) for the database connection conn Sql may contain parameter slots, denoted by ?. |
| dbi-do | This is a convenience procedure when you create a query and immediately execute it. |
mosh/dbd/mysql.ss and test/dbi.scm are good sample.
dbd SHOULD implement following functions
Returns list of result rows.
(dbi-result->list result)
| result | an instance of <result> or its subclass returned by dbi-execute |
list of result rows.
Returns getter for <result> which is returned by dbi-execute.
(dbi-getter result)
| result | an instance of <result> or its subclass returned by dbi-execute |
getter closure. getter closure accept two arguments, row and column-name.
| row | row in results. |
| column-name | name of column to retrieve. |
Destroy the connection and free resources associated to the connection.
(dbi-close conn)
| conn | an instance of <connection> or its subclass returned by dbi-connect |
unspecified
Connect to a database using a data source specified by dsn (data source name).
Dsn is a string with the following syntax
dbi:driver:options
Driver part names a specific driver. You need to have the corresponding driver library, (mosh dbd driver), installed in your system.
For example, if dsn begins with “dbi:mysql:”, dbi-connect tries to load (mosh dbd mysql).
(dbi-connect dsn user password)
| dsn | data source name. |
| user | user name. |
| password | user password. |
Instance of <connection> class.
Executes a query created by dbi-prepare. You should pass the same number of parameters as the query expects.
If the issued query is select statement, dbi-execute returns an object represents a relation. A relation encapsulates the values in rows and columns. If the query is other types, such as create, insert or delete, the return value of the query closure is unspecified.
(dbi-execute query . args)
| query | an instance of <query> or its subclass returned by dbi-prepare |
| args | arguments for the query |
an instance of <result> or its subclass.
From a string representation of SQL statement sql, creates and returns a query object (an instance of <query> or its subclass) for the database connection conn Sql may contain parameter slots, denoted by ?.
dbi-prepare may be overloaded by dbd implmentation.
(dbi-prepare conn sql)
| conn | an instance of <connecton> or its subclass returned by dbi-connect |
| sql | sql string |
an instance of <query> or its subclass.
This is a convenience procedure when you create a query and immediately execute it.
(dbi-do conn sql)
| conn | an instance of <connection> or its subclass returned by dbi-connect |
| sql | sql string |
unspecified