36 lines
729 B
C
36 lines
729 B
C
/* test program for libpq (postgresql) */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <memory.h>
|
|
|
|
#include <libpq-fe.h>
|
|
|
|
//void memmove(char *,char *,int);
|
|
|
|
void
|
|
sql_connect_db( char *dbname, int *dbhandle, int *status ) {
|
|
char *server, *user, *passwd;
|
|
|
|
server = (char *) getenv("PGSQL_SERVER");
|
|
user = (char *) getenv("PGSQL_USER");
|
|
passwd = (char *) getenv("PGSQL_PASSWD");
|
|
|
|
PGconn *conn;
|
|
char db[81];
|
|
char *s;
|
|
/* trim right spaces on the buffer */
|
|
memmove(db,dbname,80);
|
|
db[80]=0;
|
|
s = db+79;
|
|
while ((s >= db) && (*s == ' ')) s--;
|
|
if (s >= db)
|
|
*(s+1)=0;
|
|
// conn = PQsetdb("","","","",db);
|
|
conn = PQsetdbLogin(server, "", "", "", db, user, passwd);
|
|
|
|
*status = PQstatus(conn);
|
|
*dbhandle = (int)conn;
|
|
|
|
}
|