aboutsummaryrefslogtreecommitdiff
path: root/src/gsql_conn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gsql_conn.c')
-rw-r--r--src/gsql_conn.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/gsql_conn.c b/src/gsql_conn.c
index 3a44c18..4a78094 100644
--- a/src/gsql_conn.c
+++ b/src/gsql_conn.c
@@ -1,19 +1,18 @@
1/* This file is part of guile-sql. 1/* This file is part of guile-sql.
2 Copyright (C) 2002, 2005 Sergey Poznyakoff 2 Copyright (C) 2002, 2005 Sergey Poznyakoff
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify it
5 it under the terms of the GNU General Public License as published by 5 under the terms of the GNU General Public License as published by the
6 the Free Software Foundation; either version 2 of the License, or 6 Free Software Foundation; either version 3 of the License, or (at your
7 (at your option) any later version. 7 option) any later version.
8 8
9 This program is distributed in the hope that it will be useful, 9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License along
15 along with this program; if not, write to the Free Software Foundation, Inc., 15 with this program. If not, see <http://www.gnu.org/licenses/>. */
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
17 16
18#ifdef HAVE_CONFIG_H 17#ifdef HAVE_CONFIG_H
19# include <config.h> 18# include <config.h>
@@ -21,14 +20,14 @@
21#include <string.h> 20#include <string.h>
22#include <guile-sql.h> 21#include <guile-sql.h>
23#include <app.h> 22#include <app.h>
23#include <stdio.h>
24 24
25static int num_iface; 25static int num_iface;
26struct sql_iface sql_iftab[MAX_IFACES]; 26static struct sql_iface sql_iftab[MAX_IFACES];
27 27
28SCM_GLOBAL_SYMBOL (gsql_error, "gsql-error"); 28SCM_GLOBAL_SYMBOL (gsql_error, "gsql-error");
29 29
30 30static long sql_connect_tag = -1;
31long sql_connect_tag;
32 31
33/* SMOB functions: */ 32/* SMOB functions: */
34static SCM 33static SCM
@@ -50,7 +49,7 @@ sql_connect_free (SCM connect_smob)
50 free(conn->username); 49 free(conn->username);
51 if (conn->database) 50 if (conn->database)
52 free(conn->database); 51 free(conn->database);
53 free(conn); 52 scm_gc_free(conn, sizeof *conn, "SQL connection");
54 return size; 53 return size;
55} 54}
56 55
@@ -76,8 +75,8 @@ sql_connect_print (SCM connect_smob, SCM port, scm_print_state * pstate)
76 return 1; 75 return 1;
77} 76}
78 77
79int 78static int
80sql_find_iface(char *name) 79sql_find_iface(const char *name)
81{ 80{
82 int iface; 81 int iface;
83 82
@@ -95,15 +94,15 @@ sql_connect_create (char *name)
95 if (iface < 0) 94 if (iface < 0)
96 scm_misc_error("sql_connect_create", 95 scm_misc_error("sql_connect_create",
97 "Unknown SQL interface ~S", 96 "Unknown SQL interface ~S",
98 SCM_LIST1(scm_makfrom0str(name))); 97 scm_list_1(scm_makfrom0str(name)));
99 98
100 conn = scm_must_malloc (sizeof (*conn), "sql_connect"); 99 conn = scm_gc_malloc (sizeof (*conn), "sql_connect");
101 memset(conn, 0, sizeof *conn); 100 memset(conn, 0, sizeof *conn);
102 conn->iface = iface; 101 conn->iface = iface;
103 SCM_RETURN_NEWSMOB (sql_connect_tag, conn); 102 SCM_RETURN_NEWSMOB (sql_connect_tag, conn);
104} 103}
105 104
106int 105static int
107scm_is_sql_connect (SCM scm) 106scm_is_sql_connect (SCM scm)
108{ 107{
109 return SCM_NIMP (scm) && SCM_CAR (scm) == (SCM) sql_connect_tag; 108 return SCM_NIMP (scm) && SCM_CAR (scm) == (SCM) sql_connect_tag;
@@ -117,18 +116,18 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
117#define FUNC_NAME s_sql_connect 116#define FUNC_NAME s_sql_connect
118{ 117{
119 SCM smob; 118 SCM smob;
120 char *hostname; 119 const char *hostname;
121 int port; 120 int port;
122 char *dbname; 121 const char *dbname;
123 char *user; 122 const char *user;
124 char *pass; 123 const char *pass;
125 int iface; 124 int iface;
126 struct sql_connect *conn; 125 struct sql_connect *conn;
127 126
128 if (SCM_IMP(IFACE) && SCM_INUMP(IFACE)) 127 if (scm_is_integer(IFACE))
129 iface = SCM_INUM(IFACE); 128 iface = scm_to_int(IFACE);
130 else if (SCM_STRINGP(IFACE)) 129 else if (scm_is_string(IFACE))
131 iface = sql_find_iface(SCM_CHARS(IFACE)); 130 iface = sql_find_iface(scm_i_string_chars(IFACE));
132 else { 131 else {
133 SCM_ASSERT(IFACE == SCM_BOOL_T || IFACE == SCM_BOOL_F, 132 SCM_ASSERT(IFACE == SCM_BOOL_T || IFACE == SCM_BOOL_F,
134 IFACE, SCM_ARG1, FUNC_NAME); 133 IFACE, SCM_ARG1, FUNC_NAME);
@@ -137,26 +136,25 @@ SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0,
137 if (iface < 0 || iface >= num_iface) 136 if (iface < 0 || iface >= num_iface)
138 scm_misc_error(FUNC_NAME, 137 scm_misc_error(FUNC_NAME,
139 "Argument ~S (~S) out of range", 138 "Argument ~S (~S) out of range",
140 SCM_LIST2(SCM_MAKINUM(1), 139 scm_list_2(scm_from_int(1),
141 IFACE)); 140 IFACE));
142 141
143 SCM_ASSERT(SCM_STRINGP(HOST), HOST, SCM_ARG1, FUNC_NAME); 142 SCM_ASSERT(scm_is_string(HOST), HOST, SCM_ARG1, FUNC_NAME);
144 hostname = SCM_ROCHARS(HOST); 143 hostname = scm_i_string_chars(HOST);
145 144
146 SCM_ASSERT(SCM_IMP(PORT) && SCM_INUMP(PORT), 145 SCM_ASSERT(scm_is_number(PORT), PORT, SCM_ARG2, FUNC_NAME);
147 PORT, SCM_ARG2, FUNC_NAME); 146 port = scm_to_int(PORT);
148 port = SCM_INUM(PORT);
149 147
150 SCM_ASSERT(SCM_STRINGP(DB), DB, SCM_ARG3, FUNC_NAME); 148 SCM_ASSERT(scm_is_string(DB), DB, SCM_ARG3, FUNC_NAME);
151 dbname = SCM_ROCHARS(DB); 149 dbname = scm_i_string_chars(DB);
152 150
153 SCM_ASSERT(SCM_STRINGP(USER), USER, SCM_ARG4, FUNC_NAME); 151 SCM_ASSERT(scm_is_string(USER), USER, SCM_ARG4, FUNC_NAME);
154 user = SCM_ROCHARS(USER); 152 user = scm_i_string_chars(USER);
155 153
156 if (SCM_UNBNDP(PASS)) 154 if (SCM_UNBNDP(PASS))
157 pass = NULL; 155 pass = NULL;
158 else if (SCM_STRINGP(USER)) 156 else if (scm_is_string(USER))
159 pass = SCM_ROCHARS(PASS); 157 pass = scm_i_string_chars(PASS);
160 158
161 smob = sql_iftab[iface].connect(hostname, port, 159 smob = sql_iftab[iface].connect(hostname, port,
162 dbname, user, pass, 160 dbname, user, pass,
@@ -192,12 +190,12 @@ SCM_DEFINE (sql_query, "sql-query", 2, 0, 0,
192{ 190{
193 struct sql_connect *conn; 191 struct sql_connect *conn;
194 void *ptr; 192 void *ptr;
195 char *query; 193 const char *query;
196 194
197 SCM_ASSERT(scm_is_sql_connect(CONN), CONN, SCM_ARG1, FUNC_NAME); 195 SCM_ASSERT(scm_is_sql_connect(CONN), CONN, SCM_ARG1, FUNC_NAME);
198 SCM_ASSERT(SCM_STRINGP(QUERY), QUERY, SCM_ARG2, FUNC_NAME); 196 SCM_ASSERT(scm_is_string(QUERY), QUERY, SCM_ARG2, FUNC_NAME);
199 conn = (struct sql_connect *)SCM_CDR(CONN); 197 conn = (struct sql_connect *)SCM_CDR(CONN);
200 query = SCM_ROCHARS(QUERY); 198 query = scm_i_string_chars(QUERY);
201 return sql_iftab[conn->iface].query(conn, query); 199 return sql_iftab[conn->iface].query(conn, query);
202} 200}
203#undef FUNC_NAME 201#undef FUNC_NAME
@@ -220,11 +218,13 @@ sql_register_iface(struct sql_iface *ifp)
220void 218void
221gsql_conn_init() 219gsql_conn_init()
222{ 220{
223 sql_connect_tag = scm_make_smob_type ("sql_connect", 221 if (sql_connect_tag == -1) {
222 sql_connect_tag = scm_make_smob_type ("sql_connect",
224 sizeof (struct sql_connect)); 223 sizeof (struct sql_connect));
225 scm_set_smob_mark (sql_connect_tag, sql_connect_mark); 224 scm_set_smob_mark (sql_connect_tag, sql_connect_mark);
226 scm_set_smob_free (sql_connect_tag, sql_connect_free); 225 scm_set_smob_free (sql_connect_tag, sql_connect_free);
227 scm_set_smob_print (sql_connect_tag, sql_connect_print); 226 scm_set_smob_print (sql_connect_tag, sql_connect_print);
227 }
228#ifndef SCM_MAGIC_SNARFER 228#ifndef SCM_MAGIC_SNARFER
229# include <gsql_conn.x> 229# include <gsql_conn.x>
230#endif 230#endif

Return to:

Send suggestions and report system problems to the System administrator.