aboutsummaryrefslogtreecommitdiff
path: root/doc/sql.texi
blob: 8e1b4da8df00aeb487c46686217e6ad71ace587e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
@c This file is part of the Gamma manual.
@c Copyright (C) 2010 Sergey Poznyakoff
@c See gamma.texi for copying conditions.
@c *******************************************************************

The @samp{(gamma sql)} module provides interface with MySQL and
PostfeSQL database management systems. 

Usage:

@lisp
(use-modules ((gamma sql)))
@end lisp

@deffn {Scheme procedure} sql-open-connection params
This function opens a connection to the @acronym{SQL}
server and returns a connection object. This object is
then used as argument to @code{sql-query} and
@code{sql-close-connection} functions.

The @code{params} argument supplies the connection parameters.
It is a list of conses, each of which is composed from a keyword
and a value.

@defvr {Keyword} #:iface
Defines the type of the @acronym{SQL} interface.  Valid values are:
@samp{"mysql"}, to connect to a MySQL server, and @samp{"pgsql"}, to
connect to a Postgres server.
@end defvr

@defvr {Keyword} #:host
Defines server host name.  The value is a string, containing the host
name or @acronym{ASCII} representation of the host IP address.
@end defvr

@defvr {Keyword} #:port
Defines the port number server is listening on.  The value is a
decimal port number.
@end defvr

@defvr {Keyword} #:socket
If the @acronym{SQL} server is listening on a socket, this keyword
defines the @acronym{UNIX} pathname of the socket.  This keyword
cannot be used together with @samp{#:host} or @samp{#:port} keyword
pairs.
@end defvr

@defvr {Keyword} #:user
Sets the @acronym{SQL} user name.
@end defvr

@defvr {Keyword} #:pass
Sets the @acronym{SQL} user password.
@end defvr

@defvr {Keyword} #:db
Sets the database name.
@end defvr

@defvr {Keyword} #:ssl-cert
Defines full pathname of the @acronym{SSL} certificate to use.  If
this keyword is present, the connection with the server will be
encrypted using @acronym{SSL}.

Currently it is implemented only for MySQL connections.
@end defvr

@defvr {Keyword} #:config-file
Use the specified MySQL configuration file to obtain missing parameters.
@end defvr

@defvr {Keyword} #:config-group
Obtain missing parameters from the specified group in the MySQL
configuration file (see @samp{#:config-file}, above).
@end defvr

@end deffn

@deffn {Scheme procedure} sql-close-connection conn
Close the @acronym{SQL} connection.  The @var{conn} must be a
connection descriptor returned from a previous call to
@code{sql-open-connection}.
@end deffn

@deffn {Scheme procedure} sql-query conn query
@var{Conn} is a connection descriptor returned from a previous call to
@code{sql-open-connection}, and @var{query} is a valid @acronym{SQL}
query.  This function executes the query and returns its results.

If @var{query} is a @code{SELECT} query (or a similar query, returning
tuples), the return is a list, each element of which is a list
representing a row.  Elements of each row (@dfn{columns}) are string
values.

If @var{query} results in some modifications to the database (e.g. an
@code{UPDATE} statement), the @code{sql-query} function returns
the number of affected database rows.
@end deffn

@defvr {Error Keyword} gsql-error
An error of this type is raised when any of the above functions
fails.  Two arguments are supplied: a string describing the error,
and error message from the underlying @acronym{SQL} implementation.
@end defvr

@deffn {Scheme syntax} sql-catch-failure (handler) expr
@deffnx {Scheme syntax} sql-catch-failure expr
This syntax executes the Scheme expression @var{expr} and calls
@code{handler} if a @code{gsql-error} exception occurs.  The handler
must be declared as follows:

@lisp
(define (handler err descr)
  ...)
@end lisp

In its second form, @code{sql-catch-failure} calls a function named
@code{sql-error-handler} if a @code{gsql-error} exception occurs.
The @code{sql-error-handler} must be declared by the user.
@end deffn

@deffn {Scheme syntax} sql-ignore-failure (value) expr
@deffnx {Scheme syntax} sql-ignore-failure expr
Evaluates Scheme expression @var{expr} and returns the result of
evaluation, or @var{value} if a @code{gsql-error} exception occurs.

In its second form, returns @code{#f} in case of error.
@end deffn



Return to:

Send suggestions and report system problems to the System administrator.