Mercurial > hg > xemacs-beta
comparison src/postgresql.c @ 563:183866b06e0b
[xemacs-hg @ 2001-05-24 07:50:48 by ben]
Makefile.in.in, abbrev.c, alloc.c, buffer.c, bytecode.c, callint.c, callproc.c, casetab.c, chartab.c, cmdloop.c, cmds.c, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console.c, data.c, database.c, debug.c, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, dired.c, doc.c, doprnt.c, dragdrop.c, editfns.c, eldap.c, eldap.h, elhash.c, emacs-widget-accessors.c, emacs.c, emodules.c, esd.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, filelock.c, floatfns.c, fns.c, font-lock.c, frame-gtk.c, frame-x.c, frame.c, general-slots.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-gtk.c, gui-x.c, gui.c, gutter.c, hpplay.c, indent.c, input-method-xlib.c, insdel.c, intl.c, keymap.c, libsst.c, libsst.h, linuxplay.c, lisp.h, lread.c, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, miscplay.c, miscplay.h, mule-ccl.c, mule-charset.c, mule-wnnfns.c, mule.c, nas.c, ntplay.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, ralloc.c, rangetab.c, redisplay.c, scrollbar.c, search.c, select-gtk.c, select-x.c, select.c, sgiplay.c, sheap.c, sound.c, specifier.c, sunplay.c, symbols.c, symeval.h, symsinit.h, syntax.c, sysdep.c, toolbar-msw.c, toolbar.c, tooltalk.c, ui-byhand.c, ui-gtk.c, undo.c, unexaix.c, unexapollo.c, unexconvex.c, unexec.c, widget.c, win32.c, window.c:
-- defsymbol -> DEFSYMBOL.
-- add an error type to all errors.
-- eliminate the error functions in eval.c that let you just
use Qerror as the type.
-- redo the error API to be more consistent, sensibly named,
and easier to use.
-- redo the error hierarchy somewhat. create new errors:
structure-formation-error, gui-error, invalid-constant,
stack-overflow, out-of-memory, process-error, network-error,
sound-error, printing-unreadable-object, base64-conversion-
error; coding-system-error renamed to text-conversion error;
some others.
-- fix Mule problems in error strings in emodules.c, tooltalk.c.
-- fix error handling in mswin open-network-stream.
-- Mule-ize all sound files and clean up the headers.
-- nativesound.h -> sound.h and used for all sound files.
-- move some shared stuff into glyphs-shared.c: first attempt
at eliminating some of the massive GTK code duplication.
xemacs.mak: add glyphs-shared.c.
xemacs-faq.texi: document how to debug X errors
subr.el: fix doc string to reflect reality
author | ben |
---|---|
date | Thu, 24 May 2001 07:51:33 +0000 |
parents | 1ccc32a20af4 |
children | 943eaba38521 |
comparison
equal
deleted
inserted
replaced
562:c775bd016b32 | 563:183866b06e0b |
---|---|
111 #define PG_OS_CODING Qnative | 111 #define PG_OS_CODING Qnative |
112 #endif | 112 #endif |
113 Lisp_Object Vpg_coding_system; | 113 Lisp_Object Vpg_coding_system; |
114 #endif | 114 #endif |
115 | 115 |
116 #define CHECK_LIVE_CONNECTION(P) { \ | 116 #define CHECK_LIVE_CONNECTION(P) do { \ |
117 if (!P || (PQstatus (P) != CONNECTION_OK)) { \ | 117 if (!P || (PQstatus (P) != CONNECTION_OK)) { \ |
118 char *e = "bad value"; \ | 118 char *e = "bad value"; \ |
119 if (P) e = PQerrorMessage (P); \ | 119 if (P) e = PQerrorMessage (P); \ |
120 error ("dead connection [%s]", e); \ | 120 signal_ferror (Qprocess_error, "dead connection [%s]", e); \ |
121 } } | 121 } } while (0) |
122 #define PUKE_IF_NULL(p) { \ | 122 #define PUKE_IF_NULL(p) do { \ |
123 if (!p) error ("bad value"); \ | 123 if (!p) signal_error (Qinvalid_argument, "bad value", Qunbound); \ |
124 } | 124 } while (0) |
125 | 125 |
126 static Lisp_Object VXPGHOST; | 126 static Lisp_Object VXPGHOST; |
127 static Lisp_Object VXPGUSER; | 127 static Lisp_Object VXPGUSER; |
128 static Lisp_Object VXPGOPTIONS; | 128 static Lisp_Object VXPGOPTIONS; |
129 static Lisp_Object VXPGPORT; | 129 static Lisp_Object VXPGPORT; |
218 strcpy (buf, "#<PGconn BAD>"); /* evil! */ | 218 strcpy (buf, "#<PGconn BAD>"); /* evil! */ |
219 else | 219 else |
220 strcpy (buf, "#<PGconn connecting>"); /* evil! */ | 220 strcpy (buf, "#<PGconn connecting>"); /* evil! */ |
221 | 221 |
222 if (print_readably) | 222 if (print_readably) |
223 error ("printing unreadable object %s", buf); | 223 printing_unreadable_object ("%s", buf); |
224 else | 224 else |
225 write_c_string (buf, printcharfun); | 225 write_c_string (buf, printcharfun); |
226 } | 226 } |
227 | 227 |
228 static Lisp_PGconn * | 228 static Lisp_PGconn * |
243 finalize_pgconn (void *header, int for_disksave) | 243 finalize_pgconn (void *header, int for_disksave) |
244 { | 244 { |
245 Lisp_PGconn *pgconn = (Lisp_PGconn *)header; | 245 Lisp_PGconn *pgconn = (Lisp_PGconn *)header; |
246 | 246 |
247 if (for_disksave) | 247 if (for_disksave) |
248 signal_simple_error ("Can't dump an emacs containing PGconn objects", | 248 invalid_operation ("Can't dump an emacs containing PGconn objects", |
249 make_pgconn (pgconn)); | 249 make_pgconn (pgconn)); |
250 | 250 |
251 if (pgconn->pgconn) | 251 if (pgconn->pgconn) |
252 { | 252 { |
253 PQfinish (pgconn->pgconn); | 253 PQfinish (pgconn->pgconn); |
254 pgconn->pgconn = (PGconn *)NULL; | 254 pgconn->pgconn = (PGconn *)NULL; |
333 } | 333 } |
334 else | 334 else |
335 strcpy (buf, "#<PGresult DEAD>"); /* evil! */ | 335 strcpy (buf, "#<PGresult DEAD>"); /* evil! */ |
336 | 336 |
337 if (print_readably) | 337 if (print_readably) |
338 error ("printing unreadable object %s", buf); | 338 printing_unreadable_object ("%s", buf); |
339 else | 339 else |
340 write_c_string (buf, printcharfun); | 340 write_c_string (buf, printcharfun); |
341 } | 341 } |
342 | 342 |
343 #undef RESULT_TUPLES_FMT | 343 #undef RESULT_TUPLES_FMT |
362 finalize_pgresult (void *header, int for_disksave) | 362 finalize_pgresult (void *header, int for_disksave) |
363 { | 363 { |
364 Lisp_PGresult *pgresult = (Lisp_PGresult *)header; | 364 Lisp_PGresult *pgresult = (Lisp_PGresult *)header; |
365 | 365 |
366 if (for_disksave) | 366 if (for_disksave) |
367 signal_simple_error ("Can't dump an emacs containing PGresult objects", | 367 invalid_operation ("Can't dump an emacs containing PGresult objects", |
368 make_pgresult (pgresult)); | 368 make_pgresult (pgresult)); |
369 | 369 |
370 if (pgresult->pgresult) | 370 if (pgresult->pgresult) |
371 { | 371 { |
372 PQclear (pgresult->pgresult); | 372 PQclear (pgresult->pgresult); |
373 pgresult->pgresult = (PGresult *)NULL; | 373 pgresult->pgresult = (PGresult *)NULL; |
480 /* so we must temporarily stash it somewhere */ | 480 /* so we must temporarily stash it somewhere */ |
481 strncpy (buf, PQerrorMessage (P), sizeof (buf)); | 481 strncpy (buf, PQerrorMessage (P), sizeof (buf)); |
482 buf[sizeof (buf) - 1] = '\0'; | 482 buf[sizeof (buf) - 1] = '\0'; |
483 PQfinish (P); | 483 PQfinish (P); |
484 } | 484 } |
485 error ("libpq: %s", buf); | 485 signal_ferror (Qprocess_error, "libpq: %s", buf); |
486 } | 486 } |
487 } | 487 } |
488 | 488 |
489 /* PQconnectStart Makes a new asynchronous connection to a backend. | 489 /* PQconnectStart Makes a new asynchronous connection to a backend. |
490 PGconn *PQconnectStart(const char *conninfo) | 490 PGconn *PQconnectStart(const char *conninfo) |
523 { | 523 { |
524 strncpy (buf, PQerrorMessage (P), sizeof (buf)); | 524 strncpy (buf, PQerrorMessage (P), sizeof (buf)); |
525 buf[sizeof (buf) - 1] = '\0'; | 525 buf[sizeof (buf) - 1] = '\0'; |
526 PQfinish (P); | 526 PQfinish (P); |
527 } | 527 } |
528 error ("libpq: %s", buf); | 528 signal_ferror (Qprocess_error, "libpq: %s", buf); |
529 } | 529 } |
530 } | 530 } |
531 | 531 |
532 DEFUN ("pq-connect-poll", Fpq_connect_poll, 1, 1, 0, /* | 532 DEFUN ("pq-connect-poll", Fpq_connect_poll, 1, 1, 0, /* |
533 Poll an asynchronous connection for completion | 533 Poll an asynchronous connection for completion |
547 { | 547 { |
548 case PGRES_POLLING_FAILED: | 548 case PGRES_POLLING_FAILED: |
549 /* Something Bad has happened */ | 549 /* Something Bad has happened */ |
550 { | 550 { |
551 char *e = PQerrorMessage (P); | 551 char *e = PQerrorMessage (P); |
552 error ("libpq: %s", e); | 552 signal_ferror (Qprocess_error, "libpq: %s", e); |
553 } | 553 } |
554 case PGRES_POLLING_OK: | 554 case PGRES_POLLING_OK: |
555 return Qpgres_polling_ok; | 555 return Qpgres_polling_ok; |
556 case PGRES_POLLING_READING: | 556 case PGRES_POLLING_READING: |
557 return Qpgres_polling_reading; | 557 return Qpgres_polling_reading; |
559 return Qpgres_polling_writing; | 559 return Qpgres_polling_writing; |
560 case PGRES_POLLING_ACTIVE: | 560 case PGRES_POLLING_ACTIVE: |
561 return Qpgres_polling_active; | 561 return Qpgres_polling_active; |
562 default: | 562 default: |
563 /* they've added a new field we don't know about */ | 563 /* they've added a new field we don't know about */ |
564 error ("Help! Unknown status code %08x from backend!", polling_status); | 564 signal_ferror (Qprocess_error, "Help! Unknown status code %08x from backend!", polling_status); |
565 } | 565 } |
566 } | 566 } |
567 | 567 |
568 #ifdef MULE | 568 #ifdef MULE |
569 DEFUN ("pq-client-encoding", Fpq_client_encoding, 1, 1, 0, /* | 569 DEFUN ("pq-client-encoding", Fpq_client_encoding, 1, 1, 0, /* |
597 | 597 |
598 TO_EXTERNAL_FORMAT (LISP_STRING, encoding, | 598 TO_EXTERNAL_FORMAT (LISP_STRING, encoding, |
599 C_STRING_ALLOCA, c_encoding, Qnative); | 599 C_STRING_ALLOCA, c_encoding, Qnative); |
600 | 600 |
601 if ((rc = PQsetClientEncoding (P, c_encoding)) < 0) | 601 if ((rc = PQsetClientEncoding (P, c_encoding)) < 0) |
602 error ("bad encoding"); | 602 signal_error (Qinvalid_argument, "bad encoding", Qunbound); |
603 else | 603 else |
604 return make_int (rc); | 604 return make_int (rc); |
605 } | 605 } |
606 | 606 |
607 #endif | 607 #endif |
713 CHECK_LIVE_CONNECTION (P); | 713 CHECK_LIVE_CONNECTION (P); |
714 | 714 |
715 if (PQresetStart (P)) return Qt; | 715 if (PQresetStart (P)) return Qt; |
716 { | 716 { |
717 char *e = PQerrorMessage (P); | 717 char *e = PQerrorMessage (P); |
718 error ("libpq: %s", e); | 718 signal_ferror (Qprocess_error, "libpq: %s", e); |
719 } | 719 } |
720 } | 720 } |
721 | 721 |
722 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /* | 722 DEFUN ("pq-reset-poll", Fpq_reset_poll, 1, 1, 0, /* |
723 Poll an asynchronous reset for completion. | 723 Poll an asynchronous reset for completion. |
737 { | 737 { |
738 case PGRES_POLLING_FAILED: | 738 case PGRES_POLLING_FAILED: |
739 /* Something Bad has happened */ | 739 /* Something Bad has happened */ |
740 { | 740 { |
741 char *e = PQerrorMessage (P); | 741 char *e = PQerrorMessage (P); |
742 error ("libpq: %s", e); | 742 signal_ferror (Qprocess_error, "libpq: %s", e); |
743 } | 743 } |
744 case PGRES_POLLING_OK: | 744 case PGRES_POLLING_OK: |
745 return Qpgres_polling_ok; | 745 return Qpgres_polling_ok; |
746 case PGRES_POLLING_READING: | 746 case PGRES_POLLING_READING: |
747 return Qpgres_polling_reading; | 747 return Qpgres_polling_reading; |
749 return Qpgres_polling_writing; | 749 return Qpgres_polling_writing; |
750 case PGRES_POLLING_ACTIVE: | 750 case PGRES_POLLING_ACTIVE: |
751 return Qpgres_polling_active; | 751 return Qpgres_polling_active; |
752 default: | 752 default: |
753 /* they've added a new field we don't know about */ | 753 /* they've added a new field we don't know about */ |
754 error ("Help! Unknown status code %08x from backend!", polling_status); | 754 signal_ferror (Qprocess_error, "Help! Unknown status code %08x from backend!", polling_status); |
755 } | 755 } |
756 } | 756 } |
757 #endif | 757 #endif |
758 | 758 |
759 DEFUN ("pq-request-cancel", Fpq_request_cancel, 1, 1, 0, /* | 759 DEFUN ("pq-request-cancel", Fpq_request_cancel, 1, 1, 0, /* |
857 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok; | 857 case CONNECTION_AUTH_OK: return Qpg_connection_auth_ok; |
858 case CONNECTION_SETENV: return Qpg_connection_setenv; | 858 case CONNECTION_SETENV: return Qpg_connection_setenv; |
859 #endif /* HAVE_POSTGRESQLV7 */ | 859 #endif /* HAVE_POSTGRESQLV7 */ |
860 default: | 860 default: |
861 /* they've added a new field we don't know about */ | 861 /* they've added a new field we don't know about */ |
862 error ("Help! Unknown connection status code %08x from backend!", cst); | 862 signal_ferror (Qprocess_error, "Help! Unknown connection status code %08x from backend!", cst); |
863 } | 863 } |
864 } | 864 } |
865 else if (EQ (field, Qpqerrormessage)) | 865 else if (EQ (field, Qpqerrormessage)) |
866 /* PQerrorMessage Returns the error message most recently generated | 866 /* PQerrorMessage Returns the error message most recently generated |
867 by an operation on the connection. | 867 by an operation on the connection. |
873 this connection. | 873 this connection. |
874 int PQbackendPID(PGconn *conn); | 874 int PQbackendPID(PGconn *conn); |
875 */ | 875 */ |
876 return make_int (PQbackendPID(P)); | 876 return make_int (PQbackendPID(P)); |
877 else | 877 else |
878 error ("bad PGconn accessor"); | 878 signal_error (Qinvalid_argument, "bad PGconn accessor", Qunbound); |
879 } | 879 } |
880 | 880 |
881 /* Query functions */ | 881 /* Query functions */ |
882 DEFUN ("pq-exec", Fpq_exec, 2, 2, 0, /* | 882 DEFUN ("pq-exec", Fpq_exec, 2, 2, 0, /* |
883 Submit a query to Postgres and wait for the result. | 883 Submit a query to Postgres and wait for the result. |
900 | 900 |
901 R = PQexec (P, c_query); | 901 R = PQexec (P, c_query); |
902 { | 902 { |
903 char *tag, buf[BLCKSZ]; | 903 char *tag, buf[BLCKSZ]; |
904 | 904 |
905 if (!R) error ("query: out of memory"); | 905 if (!R) out_of_memory ("query: out of memory", Qunbound); |
906 else | 906 else |
907 switch (PQresultStatus (R)) | 907 switch (PQresultStatus (R)) |
908 { | 908 { |
909 case PGRES_BAD_RESPONSE: | 909 case PGRES_BAD_RESPONSE: |
910 tag = "bad response [%s]"; | 910 tag = "bad response [%s]"; |
916 tag = "fatal error [%s]"; | 916 tag = "fatal error [%s]"; |
917 err: | 917 err: |
918 strncpy (buf, PQresultErrorMessage (R), sizeof (buf)); | 918 strncpy (buf, PQresultErrorMessage (R), sizeof (buf)); |
919 buf [sizeof (buf) - 1] = '\0'; | 919 buf [sizeof (buf) - 1] = '\0'; |
920 PQclear (R); | 920 PQclear (R); |
921 error (tag, buf); | 921 signal_ferror (Qprocess_error, tag, buf); |
922 /*NOTREACHED*/ | 922 /*NOTREACHED*/ |
923 default: | 923 default: |
924 break; | 924 break; |
925 } | 925 } |
926 } | 926 } |
949 | 949 |
950 TO_EXTERNAL_FORMAT (LISP_STRING, query, | 950 TO_EXTERNAL_FORMAT (LISP_STRING, query, |
951 C_STRING_ALLOCA, c_query, Qnative); | 951 C_STRING_ALLOCA, c_query, Qnative); |
952 | 952 |
953 if (PQsendQuery (P, c_query)) return Qt; | 953 if (PQsendQuery (P, c_query)) return Qt; |
954 else error ("async query: %s", PQerrorMessage (P)); | 954 else signal_ferror (Qprocess_error, "async query: %s", PQerrorMessage (P)); |
955 } | 955 } |
956 | 956 |
957 DEFUN ("pq-get-result", Fpq_get_result, 1, 1, 0, /* | 957 DEFUN ("pq-get-result", Fpq_get_result, 1, 1, 0, /* |
958 Retrieve an asynchronous result from a query. | 958 Retrieve an asynchronous result from a query. |
959 NIL is returned when no more query work remains. | 959 NIL is returned when no more query work remains. |
987 tag = "fatal error [%s]"; | 987 tag = "fatal error [%s]"; |
988 err: | 988 err: |
989 strncpy (buf, PQresultErrorMessage (R), sizeof (buf)); | 989 strncpy (buf, PQresultErrorMessage (R), sizeof (buf)); |
990 buf[sizeof (buf) - 1] = '\0'; | 990 buf[sizeof (buf) - 1] = '\0'; |
991 PQclear (R); | 991 PQclear (R); |
992 error (tag, buf); | 992 signal_ferror (Qprocess_error, tag, buf); |
993 /*NOTREACHED*/ | 993 /*NOTREACHED*/ |
994 default: | 994 default: |
995 break; | 995 break; |
996 } | 996 } |
997 } | 997 } |
1023 case PGRES_BAD_RESPONSE: return Qpgres_bad_response; | 1023 case PGRES_BAD_RESPONSE: return Qpgres_bad_response; |
1024 case PGRES_NONFATAL_ERROR: return Qpgres_nonfatal_error; | 1024 case PGRES_NONFATAL_ERROR: return Qpgres_nonfatal_error; |
1025 case PGRES_FATAL_ERROR: return Qpgres_fatal_error; | 1025 case PGRES_FATAL_ERROR: return Qpgres_fatal_error; |
1026 default: | 1026 default: |
1027 /* they've added a new field we don't know about */ | 1027 /* they've added a new field we don't know about */ |
1028 error ("Help! Unknown exec status code %08x from backend!", est); | 1028 signal_ferror (Qprocess_error, "Help! Unknown exec status code %08x from backend!", est); |
1029 } | 1029 } |
1030 } | 1030 } |
1031 | 1031 |
1032 DEFUN ("pq-res-status", Fpq_res_status, 1, 1, 0, /* | 1032 DEFUN ("pq-res-status", Fpq_res_status, 1, 1, 0, /* |
1033 Return stringified result status of the query. | 1033 Return stringified result status of the query. |
1432 else if (EQ (status, Qpgres_copy_out)) est = PGRES_COPY_OUT; | 1432 else if (EQ (status, Qpgres_copy_out)) est = PGRES_COPY_OUT; |
1433 else if (EQ (status, Qpgres_copy_in)) est = PGRES_COPY_IN; | 1433 else if (EQ (status, Qpgres_copy_in)) est = PGRES_COPY_IN; |
1434 else if (EQ (status, Qpgres_bad_response)) est = PGRES_BAD_RESPONSE; | 1434 else if (EQ (status, Qpgres_bad_response)) est = PGRES_BAD_RESPONSE; |
1435 else if (EQ (status, Qpgres_nonfatal_error)) est = PGRES_NONFATAL_ERROR; | 1435 else if (EQ (status, Qpgres_nonfatal_error)) est = PGRES_NONFATAL_ERROR; |
1436 else if (EQ (status, Qpgres_fatal_error)) est = PGRES_FATAL_ERROR; | 1436 else if (EQ (status, Qpgres_fatal_error)) est = PGRES_FATAL_ERROR; |
1437 else signal_simple_error ("bad status symbol", status); | 1437 else invalid_constant ("bad status symbol", status); |
1438 | 1438 |
1439 R = PQmakeEmptyPGresult (P, est); | 1439 R = PQmakeEmptyPGresult (P, est); |
1440 if (!R) error ("out of memory?"); | 1440 if (!R) out_of_memory (0, Qunbound); |
1441 | 1441 |
1442 lpgr = allocate_pgresult (); | 1442 lpgr = allocate_pgresult (); |
1443 lpgr->pgresult = R; | 1443 lpgr->pgresult = R; |
1444 | 1444 |
1445 return make_pgresult (lpgr); | 1445 return make_pgresult (lpgr); |
1580 { | 1580 { |
1581 #ifndef RUNNING_XEMACS_21_1 | 1581 #ifndef RUNNING_XEMACS_21_1 |
1582 INIT_LRECORD_IMPLEMENTATION (pgconn); | 1582 INIT_LRECORD_IMPLEMENTATION (pgconn); |
1583 INIT_LRECORD_IMPLEMENTATION (pgresult); | 1583 INIT_LRECORD_IMPLEMENTATION (pgresult); |
1584 #endif | 1584 #endif |
1585 defsymbol (&Qpostgresql, "postgresql"); | 1585 DEFSYMBOL (Qpostgresql); |
1586 | 1586 |
1587 /* opaque exported types */ | 1587 /* opaque exported types */ |
1588 defsymbol (&Qpgconnp, "pgconnp"); | 1588 DEFSYMBOL (Qpgconnp); |
1589 defsymbol (&Qpgresultp, "pgresultp"); | 1589 DEFSYMBOL (Qpgresultp); |
1590 | 1590 |
1591 /* connection status types */ | 1591 /* connection status types */ |
1592 defsymbol (&Qpg_connection_ok, "pg::connection-ok"); | 1592 defsymbol (&Qpg_connection_ok, "pg::connection-ok"); |
1593 defsymbol (&Qpg_connection_bad, "pg::connection-bad"); | 1593 defsymbol (&Qpg_connection_bad, "pg::connection-bad"); |
1594 defsymbol (&Qpg_connection_started, "pg::connection-started"); | 1594 defsymbol (&Qpg_connection_started, "pg::connection-started"); |