From f673d94b23940093f7f1732a9057462177e4184e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Tue, 25 Aug 1998 15:27:20 +0200 Subject: [PATCH] Updated to Postgres 1.0.3 with code from Pike 0.6. Rev: src/modules/Postgres/configure.in:1.7 Rev: src/modules/Postgres/extras/test_notify.pike:1.2 Rev: src/modules/Postgres/extras/test_schema.pike:1.2 Rev: src/modules/Postgres/pg_types.h:1.3 Rev: src/modules/Postgres/pgres_config.h.in:1.3 Rev: src/modules/Postgres/pgresult.c:1.6 Rev: src/modules/Postgres/pgresult.h:1.2 Rev: src/modules/Postgres/postgres.c:1.8 --- .gitattributes | 5 ++ src/modules/Postgres/configure.in | 6 +- src/modules/Postgres/extras/test_notify.pike | 4 +- src/modules/Postgres/extras/test_schema.pike | 2 + src/modules/Postgres/pg_types.h | 1 + src/modules/Postgres/pgres_config.h.in | 7 ++- src/modules/Postgres/pgresult.c | 11 +++- src/modules/Postgres/pgresult.h | 1 + src/modules/Postgres/postgres.c | 66 +++++++++++++++++--- 9 files changed, 88 insertions(+), 15 deletions(-) diff --git a/.gitattributes b/.gitattributes index 812f7c7880..25dcbcb8f0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -130,7 +130,12 @@ testfont binary /src/modules/Pipe/pipe.c foreign_ident /src/modules/Postgres/Makefile.in foreign_ident /src/modules/Postgres/configure.in foreign_ident +/src/modules/Postgres/extras/test_notify.pike foreign_ident +/src/modules/Postgres/extras/test_schema.pike foreign_ident +/src/modules/Postgres/pg_types.h foreign_ident /src/modules/Postgres/pgres_config.h.in foreign_ident +/src/modules/Postgres/pgresult.c foreign_ident +/src/modules/Postgres/pgresult.h foreign_ident /src/modules/Postgres/postgres.c foreign_ident /src/modules/Postgres/version.h foreign_ident /src/modules/Regexp/acconfig.h foreign_ident diff --git a/src/modules/Postgres/configure.in b/src/modules/Postgres/configure.in index e8337a7f4f..40ef9730f7 100644 --- a/src/modules/Postgres/configure.in +++ b/src/modules/Postgres/configure.in @@ -1,4 +1,4 @@ -dnl $Id: configure.in,v 1.6 1998/07/15 18:48:22 grubba Exp $ +dnl $Id: configure.in,v 1.7 1998/08/25 13:27:12 grubba Exp $ dnl (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it> AC_INIT(postgres.c) @@ -136,6 +136,10 @@ dnl last check, just to be sure fi AC_CHECK_LIB(pq,PQclear) fi + AC_CHECK_FUNCS(PQsetdbLogin) + if test x$ac_cv_func_PQsetdbLogin = xno; then + AC_MSG_WARN(No Login-related functions, username and password will be silently ignored) + fi fi if test x$ac_cv_lib_pq_PQclear != xyes; then diff --git a/src/modules/Postgres/extras/test_notify.pike b/src/modules/Postgres/extras/test_notify.pike index 61c5e4e73b..95607ebf0d 100644 --- a/src/modules/Postgres/extras/test_notify.pike +++ b/src/modules/Postgres/extras/test_notify.pike @@ -1,5 +1,7 @@ #include <postgres.h> -/* This simple program connects to the template1 database "template1" +/* $Id: test_notify.pike,v 1.2 1998/08/25 13:27:19 grubba Exp $ + * + * This simple program connects to the template1 database "template1" * (it comes default with postgres95) and sits there waiting for * someone to issue a notify sql command on a table named "prova". * When this happens, it prints a message and exits. diff --git a/src/modules/Postgres/extras/test_schema.pike b/src/modules/Postgres/extras/test_schema.pike index 930b36236d..6fca8d215f 100644 --- a/src/modules/Postgres/extras/test_schema.pike +++ b/src/modules/Postgres/extras/test_schema.pike @@ -1,3 +1,5 @@ +// $Id: test_schema.pike,v 1.2 1998/08/25 13:27:20 grubba Exp $ + //#include "postgres.h" #include <sql.h> diff --git a/src/modules/Postgres/pg_types.h b/src/modules/Postgres/pg_types.h index 4fff04bcde..955af68524 100644 --- a/src/modules/Postgres/pg_types.h +++ b/src/modules/Postgres/pg_types.h @@ -1,3 +1,4 @@ +/* $Id: pg_types.h,v 1.3 1998/08/25 13:27:14 grubba Exp $ */ #ifndef _PG_TYPES_H_ #define _PG_TYPES_H_ diff --git a/src/modules/Postgres/pgres_config.h.in b/src/modules/Postgres/pgres_config.h.in index b3564808a5..3cb6df15e4 100644 --- a/src/modules/Postgres/pgres_config.h.in +++ b/src/modules/Postgres/pgres_config.h.in @@ -1,9 +1,14 @@ -/* $Id: pgres_config.h.in,v 1.2 1997/11/25 20:57:57 grubba Exp $ */ +/* $Id: pgres_config.h.in,v 1.3 1998/08/25 13:27:15 grubba Exp $ */ #undef STDC_HEADERS +/* Define if you have the <postgres.h> header file. */ #undef HAVE_POSTGRES_H +/* Define if you have the <libpq-fe.h> header file. */ #undef HAVE_LIBPQ_FE_H +/* Define if you have the pq library (-lpq). */ #undef HAVE_LIBPQ +/* Define if you have the PQsetdbLogin function. */ +#undef HAVE_PQSETDBLOGIN /* End of autoconfigurable section */ diff --git a/src/modules/Postgres/pgresult.c b/src/modules/Postgres/pgresult.c index ae277a3296..659e2865c9 100644 --- a/src/modules/Postgres/pgresult.c +++ b/src/modules/Postgres/pgresult.c @@ -1,4 +1,6 @@ /* + * $Id: pgresult.c,v 1.6 1998/08/25 13:27:16 grubba Exp $ + * * Postgres95 support for pike/0.5 and up * * (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it> @@ -32,7 +34,6 @@ */ #include "global.h" - #include "pgres_config.h" #ifdef HAVE_POSTGRES @@ -62,6 +63,8 @@ #include "builtin_functions.h" #include "module_support.h" +RCSID("$Id: pgresult.c,v 1.6 1998/08/25 13:27:16 grubba Exp $"); + #ifdef _REENTRANT MUTEX_T pike_postgres_result_mutex; #define PQ_LOCK() mt_lock(&pike_postgres_mutex) @@ -230,7 +233,11 @@ void pgresult_init (void) OPT_EXTERNAL_DEPEND|OPT_RETURN); pgresult_program=end_program(); add_program_constant("postgres_result",pgresult_program,0); - pgresult_program->refs++; + add_ref(pgresult_program); } +#else + +static int place_holder; /* Keep the compiler happy */ + #endif diff --git a/src/modules/Postgres/pgresult.h b/src/modules/Postgres/pgresult.h index cfd6bf1fd3..e62facd3c7 100644 --- a/src/modules/Postgres/pgresult.h +++ b/src/modules/Postgres/pgresult.h @@ -1 +1,2 @@ +/* $Id: pgresult.h,v 1.2 1998/08/25 13:27:17 grubba Exp $ */ void pgresult_init(void); diff --git a/src/modules/Postgres/postgres.c b/src/modules/Postgres/postgres.c index dae5816d0f..dc0290a5ea 100644 --- a/src/modules/Postgres/postgres.c +++ b/src/modules/Postgres/postgres.c @@ -8,7 +8,6 @@ */ #include "global.h" - #include "pgres_config.h" #ifdef HAVE_POSTGRES @@ -63,7 +62,7 @@ static void pgdebug (char * a, ...) {} struct program * postgres_program; -RCSID("$Id: postgres.c,v 1.7 1998/07/15 18:45:52 grubba Exp $"); +RCSID("$Id: postgres.c,v 1.8 1998/08/25 13:27:18 grubba Exp $"); #define THIS ((struct pgres_object_data *) fp->current_storage) @@ -107,14 +106,20 @@ static void pgres_destroy (struct object * o) } } +/* create (host,database,username,password,port) */ static void f_create (INT32 args) { - char * host=NULL, *db=NULL, *port=NULL; + /*port will be used as a string with a sprintf()*/ + char * host=NULL, *db=NULL, *user=NULL, *pass=NULL, *port=NULL; PGconn * conn; check_all_args("postgres->create",args, - BIT_STRING|BIT_VOID,BIT_STRING|BIT_VOID, - BIT_INT|BIT_VOID,0); + BIT_STRING|BIT_VOID, + BIT_STRING|BIT_VOID, + BIT_STRING|BIT_VOID, + BIT_STRING|BIT_VOID, + BIT_INT|BIT_VOID, + 0); if (THIS->dblink) { conn=THIS->dblink; @@ -124,6 +129,35 @@ static void f_create (INT32 args) PQ_UNLOCK(); THREADS_DISALLOW(); } + + /*no break;'s here, it's intentional*/ + switch(args) { + default: + case 5: + if (sp[2-args].type==T_INT && /*this check is maybe redundant*/ + sp[2-args].u.integer <=65535 && + sp[2-args].u.integer >= 0) { + if (sp[2-args].u.integer>0) { + port=xalloc(10*sizeof(char)); /*we only need 6, we just checked.*/ + sprintf(port,"%d",sp[2-args].u.integer); + } + } + case 4: + if (sp[3-args].type==T_STRING && sp[3-args].u.string->len) + pass=sp[3-args].u.string->str; + case 3: + if (sp[2-args].type==T_STRING && sp[2-args].u.string->len) + user=sp[2-args].u.string->str; + case 2: + if (sp[1-args].type==T_STRING && sp[1-args].u.string->len) + db=sp[1-args].u.string->str; + case 1: + if(sp[-args].type==T_STRING && sp[-args].u.string->len) + host=sp[-args].u.string->str; + case 0: + } +#if 0 + /* Old arguments-checking code */ if (args>=1) if(sp[-args].type==T_STRING && sp[-args].u.string->len) host=sp[-args].u.string->str; @@ -144,11 +178,18 @@ static void f_create (INT32 args) } } else - error ("You must specify a TCP/IP port number as argument 5 to Sql.postgres->create().\n"); + error ("You must specify a TCP/IP port number as argument 5 " + "to Sql.postgres->create().\n"); +#endif + pgdebug("f_create(host=%s, port=%s, db=%s, user=%s, pass=%s).\n", + host,port,db,user,pass); THREADS_ALLOW(); PQ_LOCK(); - pgdebug("f_create(host: %s, port: %s, db: %s).\n",host,port,db); +#ifdef HAVE_PQSETDBLOGIN + conn=PQsetdbLogin(host,port,NULL,NULL,db,user,pass); +#else conn=PQsetdb(host,port,NULL,NULL,db); +#endif PQ_UNLOCK(); THREADS_DISALLOW(); if (!conn) @@ -372,7 +413,12 @@ static void f_host_info (INT32 args) if (PQstatus(THIS->dblink)!=CONNECTION_BAD) { push_text("TCP/IP connection to "); - push_text(PQhost(THIS->dblink)); + pgdebug("adding reason\n"); + if(PQhost(THIS->dblink)) + push_text(PQhost(THIS->dblink)); + else + push_text("<unknown>"); + pgdebug("done\n"); f_add(2); return; } @@ -389,7 +435,7 @@ void pike_module_init (void) /* sql-interface compliant functions */ add_function ("create",f_create, - "function(void|string,void|string,int|void:void)", + "function(void|string,void|string,void|string,void|string,int|void:void)", OPT_EXTERNAL_DEPEND); /* That is: create(hostname,database,port) * It depends on the environment variables: @@ -423,7 +469,7 @@ void pike_module_init (void) postgres_program = end_program(); add_program_constant("postgres",postgres_program,0); - postgres_program->refs++; + add_ref(postgres_program); add_string_constant("version",PGSQL_VERSION,0); -- GitLab