return (SQLPTR *)sql;
#undef OPEP
}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to closed previously establish link */
+/* with the designated SQL server. */
+/* */
+/********************************************************/
+PUBLIC SQLPTR *sql_closesql(SQLPTR *sqlptr)
+
+{
+#define OPEP "devsql.c:sql_closesql,"
+
+SQLTYP *sql;
+int phase;
+_Bool proceed;
+
+sql=(SQLPTR *)sqlptr;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //check if database available
+ if (sql==(SQLTYP *)0) {
+ (void) rou_alert(0,"%s %s Datbase pointer null (bug?)",OPEP);
+ phase=999;
+ }
+ break;
+ case 1 : //opening specific database
+ switch (sql->sqldb) {
+ case db_postgres :
+ sql->db.psql=pos_closesql(sql->db.psql);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected type='%d' (bug?)",
+ OPEP,(int)sql->sqldb);
+ break;
+ }
+ break;
+ case 2 : //freeing memory used by SQL
+ (void) free(sql);
+ sql=(SQLTYP *)0;
+ break;
+ default : //SAFE guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return (SQLPTR *)sql;
+#undef OPEP
+}
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Low level subroutine implementation */
+/* to handle POSTGRES SQL request */
+/* */
+/********************************************************/
+#include <libpq-fe.h>
+#include "subrou.h"
+#include "unipos.h"
+
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to establish a link with the */
+/* postgresq SQL server. */
+/* */
+/********************************************************/
+PUBLIC POSPTR *pos_opensql(const char *host,const char *sqlport,const char *dbname)
+
+{
+#define OPEP "unipos.c:pos_opensql,"
+
+PGconn *pf;
+char *z; //parameter null
+
+z=(char *)0;
+pf=PQsetdbLogin(host,sqlport,z,z,dbname,z,z);
+// Check if the connection is successful
+if (PQstatus(pf)!=CONNECTION_OK) {
+ (void) rou_alert(0,"%s Connection to database '%s' failed, cause '%s'",
+ OPEP,dbname,PQerrorMessage(pf));
+ (void) PQfinish(pf);
+ pf=(PGconn *)0;
+ }
+return (POSPTR *)pf;
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to close the link with the designated */
+/* postgresql SQL server. */
+/* */
+/********************************************************/
+PUBLIC POSPTR *pos_closesql(POSPTR *posptr)
+
+{
+#define OPEP "unipos.c:pos_closesql,"
+
+PGconn *pf;
+
+pf=(PGconn *)posptr;
+if (pf==(PGconn *)0) {
+ (void) rou_alert(0,"%s Database link already closedi (Bug?)",OPEP);
+ (void) PQfinish(pf);
+ }
+else {
+ (void) PQfinish((PGconn *)pf);
+ pf=(PGconn *)0;
+ }
+return (POSPTR *)pf;
+#undef OPEP
+}
+
+