diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-12-26 21:54:07 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-12-26 21:54:07 +0000 |
commit | f60b650e9acd449b142c37e4fcc55390c62f4832 (patch) | |
tree | 3f3e026b1db43a9344fb65e6a83d7534b7434ff0 /src | |
parent | 06e6d0bcfcd33203091a817e4423fdd12e1bcd68 (diff) | |
download | gamma-f60b650e9acd449b142c37e4fcc55390c62f4832.tar.gz gamma-f60b650e9acd449b142c37e4fcc55390c62f4832.tar.bz2 |
* NEWS: Update.
* configure.ac: Version number 1.1
* COPYING: GPLv3.
* Makefile.am: GPLv3.
* examples/whoisd.scm: GPLv3.
* m4/guile.m4: Require Guile v. 1.8 or later.
* scripts/Makefile.am: GPLv3.
* scripts/guile-doc-snarf.awk: GPLv3.
* src/.cvsignore (gettext.inc, gettext.scm): Remove.
* src/Makefile.am: Remove libguile-gettext.
* src/app.h: GPLv3.
* src/gsql_conn.c, src/gsql_lib.c, src/guile-sql.h, src/mysql.c,
src/pgsql.c: GPLv3; Guile v.>=1.8.
* src/gettext.sci, src/gettext.h, src/gettext.c: Remove.
* src/gettext.scm: New file.
Diffstat (limited to 'src')
-rw-r--r-- | src/.cvsignore | 3 | ||||
-rw-r--r-- | src/Makefile.am | 19 | ||||
-rw-r--r-- | src/app.h | 13 | ||||
-rw-r--r-- | src/gettext.scm | 29 | ||||
-rw-r--r-- | src/gsql_conn.c | 88 | ||||
-rw-r--r-- | src/gsql_lib.c | 29 | ||||
-rw-r--r-- | src/guile-sql.h | 22 | ||||
-rw-r--r-- | src/mysql.c | 48 | ||||
-rw-r--r-- | src/pgsql.c | 44 |
9 files changed, 140 insertions, 155 deletions
diff --git a/src/.cvsignore b/src/.cvsignore index cff4dcc..822742d 100644 --- a/src/.cvsignore +++ b/src/.cvsignore @@ -7,9 +7,6 @@ Makefile .libs *.la guile-procedures.txt gsql_conn.inc gsql_lib.inc sql.scm -gettext.inc -gettext.scm - diff --git a/src/Makefile.am b/src/Makefile.am index 8b44d37..c5d713b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,56 +1,47 @@ # This file is part of guile-sql. -# Copyright (C) 2002, Sergey Poznyakoff +# Copyright (C) 2002, 2007, Sergey Poznyakoff # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. INCLUDES =-I$(top_builddir) -I$(srcdir) -I. @GUILE_INCLUDES@ @INCLUDEPATH@ LIB_SQL=libguile-sql.la -LIB_GETTEXT=libguile-gettext.la -EXTRA_LTLIBRARIES=libguile-sql.la libguile-gettext.la +EXTRA_LTLIBRARIES=libguile-sql.la lib_LTLIBRARIES=@BUILD_LIBS@ libguile_sql_la_LIBADD = @LTLIBOBJS@ @GUILE_LIBS@ libguile_sql_la_SOURCES=\ gsql_conn.c\ gsql_lib.c libguile_sql_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0 -libguile_gettext_la_LIBADD = @GUILE_LIBS@ @LTLIBINTL@ -libguile_gettext_la_SOURCES = gettext.c - -libguile_gettext_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0 - - -noinst_HEADERS=guile-sql.h app.h gettext.h -EXTRA_DIST=sql.sci gettext.sci +noinst_HEADERS=guile-sql.h app.h +EXTRA_DIST=sql.sci gettext.scm .sci.scm: m4 -DVERSION=$(VERSION) -DLIBDIR=$(libdir) \ -DBUILDDIR="`pwd`" $< > $@ sql.scm: Makefile $(libguile_sql_la_SOURCES:.c=.inc) -gettext.scm: Makefile $(libguile_gettext_la_SOURCES:.c=.inc) SCM_SQL=sql.scm X_SQL=gsql_conn.x SCM_GETTEXT=gettext.scm -X_GETTEXT=gettext.x guiledir=$(GUILE_SITE)/$(PACKAGE) -guile_DATA=guile-procedures.txt @BUILD_DATA@ +guile_DATA=guile-procedures.txt @BUILD_DATA@ DOT_X_FILES=@BUILD_X@ DOT_DOC_FILES=$(DOT_X_FILES:.x=.doc) CLEANFILES=*.inc *.x *.doc BUILT_SOURCES=$(DOT_X_FILES) $(DOT_DOC_FILES) @@ -1,22 +1,21 @@ /* This file is part of guile-sql. Copyright (C) 2002 Sergey Poznyakoff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifdef USE_SQL_MYSQL extern struct sql_iface mysql_iface; #endif #ifdef USE_SQL_PGSQL extern struct sql_iface pgsql_iface; diff --git a/src/gettext.scm b/src/gettext.scm new file mode 100644 index 0000000..a60bd59 --- /dev/null +++ b/src/gettext.scm @@ -0,0 +1,29 @@ +;;;; This file is part of gettext interface for guile. +;;;; Copyright (C) 2004, 2007 Sergey Poznyakoff +;;;; +;;;; This program is free software; you can redistribute it and/or modify it +;;;; under the terms of the GNU General Public License as published by the +;;;; Free Software Foundation; either version 3 of the License, or (at your +;;;; option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License along +;;;; with this program. If not, see <http://www.gnu.org/licenses/>. + + +(define-module (gamma gettext)) + +(define (_ msgid) + (gettext msgid)) + +(define (N_ msgid) + msgid) + +(export _) +(export N_) + +;;;; EOF 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,37 +1,36 @@ /* This file is part of guile-sql. Copyright (C) 2002, 2005 Sergey Poznyakoff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <string.h> #include <guile-sql.h> #include <app.h> +#include <stdio.h> static int num_iface; -struct sql_iface sql_iftab[MAX_IFACES]; +static struct sql_iface sql_iftab[MAX_IFACES]; SCM_GLOBAL_SYMBOL (gsql_error, "gsql-error"); - -long sql_connect_tag; +static long sql_connect_tag = -1; /* SMOB functions: */ static SCM sql_connect_mark (SCM connect_smob) { struct sql_connect *conn = (struct sql_connect *)SCM_CDR(connect_smob); @@ -47,13 +46,13 @@ sql_connect_free (SCM connect_smob) if (conn->hostname) free(conn->hostname); if (conn->username) free(conn->username); if (conn->database) free(conn->database); - free(conn); + scm_gc_free(conn, sizeof *conn, "SQL connection"); return size; } static int sql_connect_print (SCM connect_smob, SCM port, scm_print_state * pstate) { @@ -73,14 +72,14 @@ sql_connect_print (SCM connect_smob, SCM port, scm_print_state * pstate) scm_puts(conn->database, port); }; scm_puts (">", port); return 1; } -int -sql_find_iface(char *name) +static int +sql_find_iface(const char *name) { int iface; for (iface = 0; iface < num_iface; iface++) if (strcmp(sql_iftab[iface].name, name) == 0) return iface; @@ -92,21 +91,21 @@ sql_connect_create (char *name) { struct sql_connect *conn; int iface = sql_find_iface(name); if (iface < 0) scm_misc_error("sql_connect_create", "Unknown SQL interface ~S", - SCM_LIST1(scm_makfrom0str(name))); + scm_list_1(scm_makfrom0str(name))); - conn = scm_must_malloc (sizeof (*conn), "sql_connect"); + conn = scm_gc_malloc (sizeof (*conn), "sql_connect"); memset(conn, 0, sizeof *conn); conn->iface = iface; SCM_RETURN_NEWSMOB (sql_connect_tag, conn); } -int +static int scm_is_sql_connect (SCM scm) { return SCM_NIMP (scm) && SCM_CAR (scm) == (SCM) sql_connect_tag; } /* Interface */ @@ -114,52 +113,51 @@ scm_is_sql_connect (SCM scm) SCM_DEFINE (sql_connect, "sql-connect", 5, 1, 0, (SCM IFACE, SCM HOST, SCM PORT, SCM DB, SCM USER, SCM PASS), "Connect to a database.") #define FUNC_NAME s_sql_connect { SCM smob; - char *hostname; + const char *hostname; int port; - char *dbname; - char *user; - char *pass; + const char *dbname; + const char *user; + const char *pass; int iface; struct sql_connect *conn; - if (SCM_IMP(IFACE) && SCM_INUMP(IFACE)) - iface = SCM_INUM(IFACE); - else if (SCM_STRINGP(IFACE)) - iface = sql_find_iface(SCM_CHARS(IFACE)); + if (scm_is_integer(IFACE)) + iface = scm_to_int(IFACE); + else if (scm_is_string(IFACE)) + iface = sql_find_iface(scm_i_string_chars(IFACE)); else { SCM_ASSERT(IFACE == SCM_BOOL_T || IFACE == SCM_BOOL_F, IFACE, SCM_ARG1, FUNC_NAME); iface = 0; } if (iface < 0 || iface >= num_iface) scm_misc_error(FUNC_NAME, "Argument ~S (~S) out of range", - SCM_LIST2(SCM_MAKINUM(1), - IFACE)); + scm_list_2(scm_from_int(1), + IFACE)); - SCM_ASSERT(SCM_STRINGP(HOST), HOST, SCM_ARG1, FUNC_NAME); - hostname = SCM_ROCHARS(HOST); + SCM_ASSERT(scm_is_string(HOST), HOST, SCM_ARG1, FUNC_NAME); + hostname = scm_i_string_chars(HOST); - SCM_ASSERT(SCM_IMP(PORT) && SCM_INUMP(PORT), - PORT, SCM_ARG2, FUNC_NAME); - port = SCM_INUM(PORT); + SCM_ASSERT(scm_is_number(PORT), PORT, SCM_ARG2, FUNC_NAME); + port = scm_to_int(PORT); - SCM_ASSERT(SCM_STRINGP(DB), DB, SCM_ARG3, FUNC_NAME); - dbname = SCM_ROCHARS(DB); + SCM_ASSERT(scm_is_string(DB), DB, SCM_ARG3, FUNC_NAME); + dbname = scm_i_string_chars(DB); - SCM_ASSERT(SCM_STRINGP(USER), USER, SCM_ARG4, FUNC_NAME); - user = SCM_ROCHARS(USER); + SCM_ASSERT(scm_is_string(USER), USER, SCM_ARG4, FUNC_NAME); + user = scm_i_string_chars(USER); if (SCM_UNBNDP(PASS)) pass = NULL; - else if (SCM_STRINGP(USER)) - pass = SCM_ROCHARS(PASS); + else if (scm_is_string(USER)) + pass = scm_i_string_chars(PASS); smob = sql_iftab[iface].connect(hostname, port, dbname, user, pass, FUNC_NAME); conn = (struct sql_connect *)SCM_CDR(smob); @@ -189,18 +187,18 @@ SCM_DEFINE (sql_query, "sql-query", 2, 0, 0, (SCM CONN, SCM QUERY), "Run an SQL query") #define FUNC_NAME s_sql_query { struct sql_connect *conn; void *ptr; - char *query; + const char *query; SCM_ASSERT(scm_is_sql_connect(CONN), CONN, SCM_ARG1, FUNC_NAME); - SCM_ASSERT(SCM_STRINGP(QUERY), QUERY, SCM_ARG2, FUNC_NAME); + SCM_ASSERT(scm_is_string(QUERY), QUERY, SCM_ARG2, FUNC_NAME); conn = (struct sql_connect *)SCM_CDR(CONN); - query = SCM_ROCHARS(QUERY); + query = scm_i_string_chars(QUERY); return sql_iftab[conn->iface].query(conn, query); } #undef FUNC_NAME int sql_register_iface(struct sql_iface *ifp) @@ -217,17 +215,19 @@ sql_register_iface(struct sql_iface *ifp) return num_iface++; } void gsql_conn_init() { - sql_connect_tag = scm_make_smob_type ("sql_connect", + if (sql_connect_tag == -1) { + sql_connect_tag = scm_make_smob_type ("sql_connect", sizeof (struct sql_connect)); - scm_set_smob_mark (sql_connect_tag, sql_connect_mark); - scm_set_smob_free (sql_connect_tag, sql_connect_free); - scm_set_smob_print (sql_connect_tag, sql_connect_print); + scm_set_smob_mark (sql_connect_tag, sql_connect_mark); + scm_set_smob_free (sql_connect_tag, sql_connect_free); + scm_set_smob_print (sql_connect_tag, sql_connect_print); + } #ifndef SCM_MAGIC_SNARFER # include <gsql_conn.x> #endif } diff --git a/src/gsql_lib.c b/src/gsql_lib.c index c988b2e..a6103b2 100644 --- a/src/gsql_lib.c +++ b/src/gsql_lib.c @@ -1,35 +1,34 @@ /* This file is part of guile-sql. Copyright (C) 2002 Sergey Poznyakoff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <guile-sql.h> #include <app.h> SCM scm_makenum (unsigned long val) #ifndef HAVE_SCM_LONG2NUM { if (SCM_FIXABLE ((long) val)) - return SCM_MAKINUM (val); + return scm_from_int (val); #ifdef SCM_BIGDIG return scm_i_long2big (val); #else /* SCM_BIGDIG */ return scm_make_real ((double) val); #endif /* SCM_BIGDIG */ @@ -37,26 +36,12 @@ scm_makenum (unsigned long val) #else { return scm_long2num (val); } #endif -/* - * Chop off trailing whitespace. Return length of the resulting string - */ -int -chop(char *str) -{ - int len; - - for (len = strlen(str); len > 0 && isspace(str[len-1]); len--) - ; - str[len] = 0; - return len; -} - extern void sql_init() { gsql_conn_init(); #ifdef USE_SQL_MYSQL sql_register_iface(&mysql_iface); diff --git a/src/guile-sql.h b/src/guile-sql.h index 5203123..154b322 100644 --- a/src/guile-sql.h +++ b/src/guile-sql.h @@ -1,22 +1,21 @@ /* This file is part of guile-sql. - Copyright (C) 2002 Sergey Poznyakoff + Copyright (C) 2002, 2007 Sergey Poznyakoff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <libguile.h> @@ -38,16 +37,17 @@ struct sql_result { }; struct sql_iface { char *name; SCM (*mark) (struct sql_connect *); scm_sizet (*free) (struct sql_connect *); - SCM (*connect) (char *hostname, int port, - char *dbname, char *user, char *pass, const char *why); + SCM (*connect) (const char *hostname, int port, + const char *dbname, const char *user, + const char *pass, const char *why); void (*close) (struct sql_connect *); - SCM (*query) (struct sql_connect *, char *query); + SCM (*query) (struct sql_connect *, const char *query); }; extern struct sql_iface sql_iftab[]; extern SCM gsql_error; SCM sql_connect_create (char *name); diff --git a/src/mysql.c b/src/mysql.c index d788a92..ac7e0f7 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -1,54 +1,54 @@ /* This file is part of guile-sql. - Copyright (C) 2002,2004,2005 Sergey Poznyakoff + Copyright (C) 2002, 2004, 2005 Sergey Poznyakoff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <string.h> #include <guile-sql.h> #include <mysql/mysql.h> -SCM +static SCM s_mysql_mark(struct sql_connect *conn) { return SCM_BOOL_F; } -scm_sizet +static scm_sizet s_mysql_free(struct sql_connect *conn) { MYSQL *mysql = (MYSQL*) conn->data; if (!mysql) return 0; mysql_close(mysql); return sizeof(MYSQL); } -SCM -s_mysql_connect (char *hostname, int port, - char *dbname, char *user, char *pass, const char *why) +static SCM +s_mysql_connect (const char *hostname, int port, + const char *dbname, const char *user, const char *pass, + const char *why) { MYSQL *mysql; SCM smob; struct sql_connect *conn; - char *socket_path = NULL; + const char *socket_path = NULL; mysql = mysql_init(NULL); if (!mysql) scm_throw(gsql_error, scm_list_2(scm_makfrom0str("mysql_init() failed"), scm_makfrom0str(""))); @@ -69,14 +69,14 @@ s_mysql_connect (char *hostname, int port, smob = sql_connect_create("mysql"); conn = (struct sql_connect *)SCM_CDR(smob); conn->data = mysql; return smob; } -SCM -s_mysql_query(struct sql_connect *conn, char *query) +static SCM +s_mysql_query(struct sql_connect *conn, const char *query) { MYSQL *mysql = conn->data; MYSQL_RES *result; SCM cell; if (mysql_query(mysql, query)) @@ -96,36 +96,28 @@ s_mysql_query(struct sql_connect *conn, char *query) SCM head = SCM_EOL, tail; MYSQL_ROW row = mysql_fetch_row(result); if (!row) break; for (j = 0; j < nfields; j++) { - SCM new_elt; - SCM_NEWCELL(new_elt); - SCM_SETCAR(new_elt, scm_makfrom0str(row[j])); + SCM new_elt = scm_cons(scm_makfrom0str(row[j]), + SCM_EOL); if (head == SCM_EOL) head = new_elt; else SCM_SETCDR(tail, new_elt); tail = new_elt; } - if (head != SCM_EOL) - SCM_SETCDR(tail, SCM_EOL); - - SCM_NEWCELL(new_row); - SCM_SETCAR(new_row, head); - + new_row = scm_cons(head, SCM_EOL); if (row_head == SCM_EOL) row_head = new_row; else SCM_SETCDR(row_tail, new_row); row_tail = new_row; } - if (row_head != SCM_EOL) - SCM_SETCDR(row_tail, SCM_EOL); cell = row_head; mysql_free_result(result); } else { /* should it have returned something? */ if (mysql_field_count(mysql) == 0) { cell = scm_makenum(mysql_affected_rows(mysql)); } else { /* mysql_store_result() should have returned data */ @@ -134,13 +126,13 @@ s_mysql_query(struct sql_connect *conn, char *query) scm_makfrom0str(mysql_error(mysql)))); } } return cell; } -void +static void s_mysql_close(struct sql_connect *conn) { if (conn->data) mysql_close(conn->data); conn->data = NULL; } diff --git a/src/pgsql.c b/src/pgsql.c index 44b1fa6..011a4b7 100644 --- a/src/pgsql.c +++ b/src/pgsql.c @@ -1,49 +1,49 @@ /* This file is part of guile-sql. Copyright (C) 2002 Sergey Poznyakoff - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 3 of the License, or (at your + option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + You should have received a copy of the GNU General Public License along + with this program. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <string.h> #include <guile-sql.h> #include <libpq-fe.h> -SCM +static SCM s_pgsql_mark(struct sql_connect *conn) { return SCM_BOOL_F; } -scm_sizet +static scm_sizet s_pgsql_free(struct sql_connect *conn) { PGconn *pgconn = (PGconn*) conn->data; if (!pgconn) return 0; PQfinish(pgconn); return sizeof(pgconn); } -SCM -s_pgsql_connect (char *hostname, int port, - char *dbname, char *user, char *pass, const char *why) +static SCM +s_pgsql_connect (const char *hostname, int port, + const char *dbname, const char *user, const char *pass, + const char *why) { PGconn *pgconn; char buf[24]; SCM smob; struct sql_connect *conn; @@ -59,55 +59,47 @@ s_pgsql_connect (char *hostname, int port, smob = sql_connect_create("pgsql"); conn = (struct sql_connect *)SCM_CDR(smob); conn->data = pgconn; return smob; } -SCM +static SCM result_to_list(PGresult *res) { int i, j; int ntuples = PQntuples(res); int nfields = PQnfields(res); SCM row_head = SCM_EOL, row_tail; for (i = 0; i < ntuples; i++) { SCM new_row; SCM head = SCM_EOL, tail; for (j = 0; j < nfields; j++) { - SCM new_elt; char *val = PQgetvalue(res, i, j); - SCM_NEWCELL(new_elt); - SCM_SETCAR(new_elt, scm_makfrom0str(val)); + SCM new_elt = scm_cons(scm_makfrom0str(val), SCM_EOL); if (head == SCM_EOL) head = new_elt; else SCM_SETCDR(tail, new_elt); tail = new_elt; } - if (head != SCM_EOL) - SCM_SETCDR(tail, SCM_EOL); - - SCM_NEWCELL(new_row); - SCM_SETCAR(new_row, head); + new_row = scm_cons(head, SCM_EOL); if (row_head == SCM_EOL) row_head = new_row; else SCM_SETCDR(row_tail, new_row); row_tail = new_row; } - if (row_head != SCM_EOL) - SCM_SETCDR(row_tail, SCM_EOL); return row_head; } -SCM -s_pgsql_query(struct sql_connect *conn, char *query) +static SCM +s_pgsql_query(struct sql_connect *conn, const char *query) { PGconn *pgconn = (PGconn*) conn->data; PGresult *res; SCM cell; ExecStatusType stat; @@ -134,13 +126,13 @@ s_pgsql_query(struct sql_connect *conn, char *query) scm_makfrom0str(PQresStatus(stat)))); } return cell; } -void +static void s_pgsql_close(struct sql_connect *conn) { PGconn *pgconn = (PGconn*) conn->data; if (!pgconn) return; PQfinish(pgconn); |