comparison src/postgresql.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 501cfd01ee6d
children
comparison
equal deleted inserted replaced
409:301b9ebbdf3b 410:de805c49cfc1
90 interface to lcrecord handling has changed with 21.2, so unfortunately 90 interface to lcrecord handling has changed with 21.2, so unfortunately
91 we will need a few snippets of backwards compatibility code. 91 we will need a few snippets of backwards compatibility code.
92 */ 92 */
93 #if (EMACS_MAJOR_VERSION == 21) && (EMACS_MINOR_VERSION < 2) 93 #if (EMACS_MAJOR_VERSION == 21) && (EMACS_MINOR_VERSION < 2)
94 #define RUNNING_XEMACS_21_1 1 94 #define RUNNING_XEMACS_21_1 1
95 #define POSTGRES_INCLUDE(file) <file>
96 #endif 95 #endif
97 96
98 /* #define POSTGRES_LO_IMPORT_IS_VOID 1 */ 97 /* #define POSTGRES_LO_IMPORT_IS_VOID 1 */
99 98
100 #include "lisp.h" 99 #include "lisp.h"
101 #include "sysdep.h" 100 #include "sysdep.h"
102 #include "buffer.h" 101 #include "buffer.h"
103
104 #include POSTGRES_INCLUDE (libpq-fe.h)
105 #include "postgresql.h" 102 #include "postgresql.h"
106 103
107 #ifdef RUNNING_XEMACS_21_1 /* handle interface changes */ 104 #ifdef RUNNING_XEMACS_21_1 /* handle interface changes */
108 #define I_HATE_CONST CONST
109 #define PG_OS_CODING FORMAT_FILENAME 105 #define PG_OS_CODING FORMAT_FILENAME
110 #define TO_EXTERNAL_FORMAT(a,from,b,to,c) GET_C_STRING_EXT_DATA_ALLOCA(from,FORMAT_FILENAME,to) 106 #define TO_EXTERNAL_FORMAT(a,from,b,to,c) GET_C_STRING_EXT_DATA_ALLOCA(from,FORMAT_FILENAME,to)
111 #else 107 #else
112 #define I_HATE_CONST const
113 #ifdef MULE 108 #ifdef MULE
114 #define PG_OS_CODING Fget_coding_system(Vpg_coding_system) 109 #define PG_OS_CODING Fget_coding_system(Vpg_coding_system)
115 #else 110 #else
116 #define PG_OS_CODING Qnative 111 #define PG_OS_CODING Qnative
117 #endif 112 #endif
394 389
395 /***********************/ 390 /***********************/
396 391
397 /* notices */ 392 /* notices */
398 static void 393 static void
399 xemacs_notice_processor (void *arg, I_HATE_CONST char *msg) 394 xemacs_notice_processor (void *arg, const char *msg)
400 { 395 {
401 warn_when_safe (Qpostgresql, Qnotice, "%s", msg); 396 warn_when_safe (Qpostgresql, Qnotice, "%s", msg);
402 } 397 }
403 398
404 /* There are four ways (as of PostgreSQL v7) to connect to a database. 399 /* There are four ways (as of PostgreSQL v7) to connect to a database.
723 error ("libpq: %s", e); 718 error ("libpq: %s", e);
724 } 719 }
725 } 720 }
726 721
727 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /* 722 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /*
728 Poll an asynchronous reset for completion 723 Poll an asynchronous reset for completion.
729 */ 724 */
730 (conn)) 725 (conn))
731 { 726 {
732 PGconn *P; 727 PGconn *P;
733 PostgresPollingStatusType polling_status; 728 PostgresPollingStatusType polling_status;
844 char *PQoptions(PGconn *conn) 839 char *PQoptions(PGconn *conn)
845 */ 840 */
846 return build_ext_string (PQoptions(P), PG_OS_CODING); 841 return build_ext_string (PQoptions(P), PG_OS_CODING);
847 else if (EQ (field, Qpqstatus)) 842 else if (EQ (field, Qpqstatus))
848 { 843 {
849 ExecStatusType est; 844 ConnStatusType cst;
850 /* PQstatus Returns the status of the connection. The status can be 845 /* PQstatus Returns the status of the connection. The status can be
851 CONNECTION_OK or CONNECTION_BAD. 846 CONNECTION_OK or CONNECTION_BAD.
852 ConnStatusType PQstatus(PGconn *conn) 847 ConnStatusType PQstatus(PGconn *conn)
853 */ 848 */
854 switch ((est = PQstatus (P))) 849 switch ((cst = PQstatus (P)))
855 { 850 {
856 case CONNECTION_OK: return Qpg_connection_ok; 851 case CONNECTION_OK: return Qpg_connection_ok;
857 case CONNECTION_BAD: return Qpg_connection_bad; 852 case CONNECTION_BAD: return Qpg_connection_bad;
858 #ifdef HAVE_POSTGRESQLV7 853 #ifdef HAVE_POSTGRESQLV7
859 case CONNECTION_STARTED: return Qpg_connection_started; 854 case CONNECTION_STARTED: return Qpg_connection_started;
862 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok; 857 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok;
863 case CONNECTION_SETENV: return Qpg_connection_setenv; 858 case CONNECTION_SETENV: return Qpg_connection_setenv;
864 #endif /* HAVE_POSTGRESQLV7 */ 859 #endif /* HAVE_POSTGRESQLV7 */
865 default: 860 default:
866 /* they've added a new field we don't know about */ 861 /* they've added a new field we don't know about */
867 error ("Help! Unknown exec status code %08x from backend!", est); 862 error ("Help! Unknown connection status code %08x from backend!", cst);
868 } 863 }
869 } 864 }
870 else if (EQ (field, Qpqerrormessage)) 865 else if (EQ (field, Qpqerrormessage))
871 /* PQerrorMessage Returns the error message most recently generated 866 /* PQerrorMessage Returns the error message most recently generated
872 by an operation on the connection. 867 by an operation on the connection.
1255 1250
1256 return build_ext_string (PQcmdStatus (R), PG_OS_CODING); 1251 return build_ext_string (PQcmdStatus (R), PG_OS_CODING);
1257 } 1252 }
1258 1253
1259 DEFUN ("pq-cmd-tuples", Fpq_cmd_tuples, 1, 1, 0, /* 1254 DEFUN ("pq-cmd-tuples", Fpq_cmd_tuples, 1, 1, 0, /*
1260 Returns the number of rows affected by the SQL command 1255 Returns the number of rows affected by the SQL command.
1261 */ 1256 */
1262 (result)) 1257 (result))
1263 { 1258 {
1264 PGresult *R; 1259 PGresult *R;
1265 1260
1307 1302
1308 return make_int (PQsetnonblocking (P, !NILP (arg))); 1303 return make_int (PQsetnonblocking (P, !NILP (arg)));
1309 } 1304 }
1310 1305
1311 DEFUN ("pq-is-nonblocking", Fpq_is_nonblocking, 1, 1, 0, /* 1306 DEFUN ("pq-is-nonblocking", Fpq_is_nonblocking, 1, 1, 0, /*
1312 Return the blocking status of the database connection 1307 Return the blocking status of the database connection.
1313 */ 1308 */
1314 (conn)) 1309 (conn))
1315 { 1310 {
1316 PGconn *P; 1311 PGconn *P;
1317 1312
1321 1316
1322 return PQisnonblocking (P) ? Qt : Qnil; 1317 return PQisnonblocking (P) ? Qt : Qnil;
1323 } 1318 }
1324 1319
1325 DEFUN ("pq-flush", Fpq_flush, 1, 1, 0, /* 1320 DEFUN ("pq-flush", Fpq_flush, 1, 1, 0, /*
1326 Force the write buffer to be written (or at least try) 1321 Force the write buffer to be written (or at least try).
1327 */ 1322 */
1328 (conn)) 1323 (conn))
1329 { 1324 {
1330 PGconn *P; 1325 PGconn *P;
1331 1326
1541 ret = PQgetlineAsync (P, buffer, sizeof (buffer)); 1536 ret = PQgetlineAsync (P, buffer, sizeof (buffer));
1542 1537
1543 if (ret == -1) return Qt; /* done! */ 1538 if (ret == -1) return Qt; /* done! */
1544 else if (!ret) return Qnil; /* no data yet */ 1539 else if (!ret) return Qnil; /* no data yet */
1545 else return Fcons (make_int (ret), 1540 else return Fcons (make_int (ret),
1546 make_ext_string (buffer, ret, PG_OS_CODING)); 1541 make_ext_string ((Extbyte *) buffer, ret, PG_OS_CODING));
1547 } 1542 }
1548 1543
1549 DEFUN ("pq-put-nbytes", Fpq_put_nbytes, 2, 2, 0, /* 1544 DEFUN ("pq-put-nbytes", Fpq_put_nbytes, 2, 2, 0, /*
1550 Asynchronous copy out. 1545 Asynchronous copy out.
1551 */ 1546 */