Skip to content
Snippets Groups Projects
Commit 67755029 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Updated to Postgres 1.0.3 level.

Rev: lib/modules/Sql.pmod/postgres.pike:1.4
Rev: src/modules/Postgres/configure.in:1.7
Rev: src/modules/Postgres/pgres_config.h.in:1.3
Rev: src/modules/Postgres/postgres.c:1.9
parent d86cd760
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* This is part of the Postgres module for Pike. * This is part of the Postgres module for Pike.
* (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it> * (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
* *
* $Id: postgres.pike,v 1.3 1998/07/15 19:04:18 grubba Exp $ * $Id: postgres.pike,v 1.4 1998/08/25 13:11:21 grubba Exp $
* *
*/ */
...@@ -31,7 +31,7 @@ void create(void|string host, void|string database, void|string user, ...@@ -31,7 +31,7 @@ void create(void|string host, void|string database, void|string user,
if (sscanf(host,"%s:%d",real_host,port)!=2) if (sscanf(host,"%s:%d",real_host,port)!=2)
ERROR("Error in parsing the hostname argument.\n"); ERROR("Error in parsing the hostname argument.\n");
mo::create(real_host||"",real_db||"",port); mo::create(real_host||"",real_db||"",user||"",pass||"",port);
} }
static void poll (int delay) static void poll (int delay)
......
dnl $Id: configure.in,v 1.6 1998/07/15 19:02:17 grubba Exp $ dnl $Id: configure.in,v 1.7 1998/08/25 13:11:50 grubba Exp $
dnl (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it> dnl (C) 1997 Francesco Chemolli <kinkie@kame.usr.dsi.unimi.it>
AC_INIT(postgres.c) AC_INIT(postgres.c)
...@@ -136,6 +136,10 @@ dnl last check, just to be sure ...@@ -136,6 +136,10 @@ dnl last check, just to be sure
fi fi
AC_CHECK_LIB(pq,PQclear) AC_CHECK_LIB(pq,PQclear)
fi 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 fi
if test x$ac_cv_lib_pq_PQclear != xyes; then if test x$ac_cv_lib_pq_PQclear != xyes; then
......
/* $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:11:51 grubba Exp $ */
#undef STDC_HEADERS #undef STDC_HEADERS
/* Define if you have the <postgres.h> header file. */
#undef HAVE_POSTGRES_H #undef HAVE_POSTGRES_H
/* Define if you have the <libpq-fe.h> header file. */
#undef HAVE_LIBPQ_FE_H #undef HAVE_LIBPQ_FE_H
/* Define if you have the pq library (-lpq). */
#undef HAVE_LIBPQ #undef HAVE_LIBPQ
/* Define if you have the PQsetdbLogin function. */
#undef HAVE_PQSETDBLOGIN
/* End of autoconfigurable section */ /* End of autoconfigurable section */
......
...@@ -62,7 +62,7 @@ static void pgdebug (char * a, ...) {} ...@@ -62,7 +62,7 @@ static void pgdebug (char * a, ...) {}
struct program * postgres_program; struct program * postgres_program;
RCSID("$Id: postgres.c,v 1.8 1998/07/15 18:52:28 grubba Exp $"); RCSID("$Id: postgres.c,v 1.9 1998/08/25 13:11:52 grubba Exp $");
#define THIS ((struct pgres_object_data *) fp->current_storage) #define THIS ((struct pgres_object_data *) fp->current_storage)
...@@ -106,14 +106,20 @@ static void pgres_destroy (struct object * o) ...@@ -106,14 +106,20 @@ static void pgres_destroy (struct object * o)
} }
} }
/* create (host,database,username,password,port) */
static void f_create (INT32 args) 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; PGconn * conn;
check_all_args("postgres->create",args, check_all_args("postgres->create",args,
BIT_STRING|BIT_VOID,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_INT|BIT_VOID,
0);
if (THIS->dblink) { if (THIS->dblink) {
conn=THIS->dblink; conn=THIS->dblink;
...@@ -123,6 +129,35 @@ static void f_create (INT32 args) ...@@ -123,6 +129,35 @@ static void f_create (INT32 args)
PQ_UNLOCK(); PQ_UNLOCK();
THREADS_DISALLOW(); 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 (args>=1)
if(sp[-args].type==T_STRING && sp[-args].u.string->len) if(sp[-args].type==T_STRING && sp[-args].u.string->len)
host=sp[-args].u.string->str; host=sp[-args].u.string->str;
...@@ -143,11 +178,18 @@ static void f_create (INT32 args) ...@@ -143,11 +178,18 @@ static void f_create (INT32 args)
} }
} }
else 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(); THREADS_ALLOW();
PQ_LOCK(); 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); conn=PQsetdb(host,port,NULL,NULL,db);
#endif
PQ_UNLOCK(); PQ_UNLOCK();
THREADS_DISALLOW(); THREADS_DISALLOW();
if (!conn) if (!conn)
...@@ -371,7 +413,12 @@ static void f_host_info (INT32 args) ...@@ -371,7 +413,12 @@ static void f_host_info (INT32 args)
if (PQstatus(THIS->dblink)!=CONNECTION_BAD) { if (PQstatus(THIS->dblink)!=CONNECTION_BAD) {
push_text("TCP/IP connection to "); 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); f_add(2);
return; return;
} }
...@@ -388,7 +435,7 @@ void pike_module_init (void) ...@@ -388,7 +435,7 @@ void pike_module_init (void)
/* sql-interface compliant functions */ /* sql-interface compliant functions */
add_function ("create",f_create, 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); OPT_EXTERNAL_DEPEND);
/* That is: create(hostname,database,port) /* That is: create(hostname,database,port)
* It depends on the environment variables: * It depends on the environment variables:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment