summaryrefslogtreecommitdiffabout
path: root/src/pgsql.c
Unidiff
Diffstat (limited to 'src/pgsql.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/pgsql.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/pgsql.c b/src/pgsql.c
index 44b1fa6..011a4b7 100644
--- a/src/pgsql.c
+++ b/src/pgsql.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 Sergey Poznyakoff 2 Copyright (C) 2002 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>
@@ -22,13 +21,13 @@
22#include <guile-sql.h> 21#include <guile-sql.h>
23#include <libpq-fe.h> 22#include <libpq-fe.h>
24 23
25SCM 24static SCM
26s_pgsql_mark(struct sql_connect *conn) 25s_pgsql_mark(struct sql_connect *conn)
27{ 26{
28 return SCM_BOOL_F; 27 return SCM_BOOL_F;
29} 28}
30 29
31scm_sizet 30static scm_sizet
32s_pgsql_free(struct sql_connect *conn) 31s_pgsql_free(struct sql_connect *conn)
33{ 32{
34 PGconn *pgconn = (PGconn*) conn->data; 33 PGconn *pgconn = (PGconn*) conn->data;
@@ -38,9 +37,10 @@ s_pgsql_free(struct sql_connect *conn)
38 return sizeof(pgconn); 37 return sizeof(pgconn);
39} 38}
40 39
41SCM 40static SCM
42s_pgsql_connect (char *hostname, int port, 41s_pgsql_connect (const char *hostname, int port,
43 char *dbname, char *user, char *pass, const char *why) 42 const char *dbname, const char *user, const char *pass,
43 const char *why)
44{ 44{
45 PGconn *pgconn; 45 PGconn *pgconn;
46 char buf[24]; 46 char buf[24];
@@ -62,7 +62,7 @@ s_pgsql_connect (char *hostname, int port,
62 return smob; 62 return smob;
63} 63}
64 64
65SCM 65static SCM
66result_to_list(PGresult *res) 66result_to_list(PGresult *res)
67{ 67{
68 int i, j; 68 int i, j;
@@ -75,10 +75,8 @@ result_to_list(PGresult *res)
75 SCM head = SCM_EOL, tail; 75 SCM head = SCM_EOL, tail;
76 76
77 for (j = 0; j < nfields; j++) { 77 for (j = 0; j < nfields; j++) {
78 SCM new_elt;
79 char *val = PQgetvalue(res, i, j); 78 char *val = PQgetvalue(res, i, j);
80 SCM_NEWCELL(new_elt); 79 SCM new_elt = scm_cons(scm_makfrom0str(val), SCM_EOL);
81 SCM_SETCAR(new_elt, scm_makfrom0str(val));
82 if (head == SCM_EOL) 80 if (head == SCM_EOL)
83 head = new_elt; 81 head = new_elt;
84 else 82 else
@@ -86,11 +84,7 @@ result_to_list(PGresult *res)
86 tail = new_elt; 84 tail = new_elt;
87 } 85 }
88 86
89 if (head != SCM_EOL) 87 new_row = scm_cons(head, SCM_EOL);
90 SCM_SETCDR(tail, SCM_EOL);
91
92 SCM_NEWCELL(new_row);
93 SCM_SETCAR(new_row, head);
94 88
95 if (row_head == SCM_EOL) 89 if (row_head == SCM_EOL)
96 row_head = new_row; 90 row_head = new_row;
@@ -98,13 +92,11 @@ result_to_list(PGresult *res)
98 SCM_SETCDR(row_tail, new_row); 92 SCM_SETCDR(row_tail, new_row);
99 row_tail = new_row; 93 row_tail = new_row;
100 } 94 }
101 if (row_head != SCM_EOL)
102 SCM_SETCDR(row_tail, SCM_EOL);
103 return row_head; 95 return row_head;
104} 96}
105 97
106SCM 98static SCM
107s_pgsql_query(struct sql_connect *conn, char *query) 99s_pgsql_query(struct sql_connect *conn, const char *query)
108{ 100{
109 PGconn *pgconn = (PGconn*) conn->data; 101 PGconn *pgconn = (PGconn*) conn->data;
110 PGresult *res; 102 PGresult *res;
@@ -137,7 +129,7 @@ s_pgsql_query(struct sql_connect *conn, char *query)
137 return cell; 129 return cell;
138} 130}
139 131
140void 132static void
141s_pgsql_close(struct sql_connect *conn) 133s_pgsql_close(struct sql_connect *conn)
142{ 134{
143 PGconn *pgconn = (PGconn*) conn->data; 135 PGconn *pgconn = (PGconn*) conn->data;

Return to:

Send suggestions and report system problems to the System administrator.