*** empty log message ***
authorMichael Meskes <meskes@postgresql.org>
Fri, 17 Sep 1999 18:28:15 +0000 (18:28 +0000)
committerMichael Meskes <meskes@postgresql.org>
Fri, 17 Sep 1999 18:28:15 +0000 (18:28 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/lib/Makefile.in
src/interfaces/ecpg/lib/ecpglib.c
src/interfaces/ecpg/test/test2.pgc
src/interfaces/ecpg/test/test3.pgc

index 53c81753edc898462ef8a32ca3b72922b5dbbf59..8a7253dae53d088ad0aa3e5df8cac3167e6fcc61 100644 (file)
@@ -638,3 +638,8 @@ Fri Sep 17 07:43:55 CEST 1999
        - Fixed bug in parsing operators.
        - Set ecpg version to 2.6.4
 
+Fri Sep 17 18:16:34 CEST 1999
+
+       - Made sure sqlca is initialized everytime.
+       - Set library version to 3.0.3
+
index 005ed0d8a13af53197ab87b50d359f3f48a07b83..8436a63b6fd85c2e74d52feb7bf82028a7604570 100644 (file)
@@ -6,13 +6,13 @@
 # Copyright (c) 1994, Regents of the University of California
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.46 1999/09/15 08:29:14 meskes Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.47 1999/09/17 18:28:10 meskes Exp $
 #
 #-------------------------------------------------------------------------
 
 NAME= ecpg
 SO_MAJOR_VERSION= 3
-SO_MINOR_VERSION= 0.2
+SO_MINOR_VERSION= 0.3
 
 SRCDIR= @top_srcdir@
 include $(SRCDIR)/Makefile.global
index ea2ec7a6508aba4ab4f3d8d3616b367ae283ddc9..de093895e0c1ef1c753f2ceb663a4687ce2e05c1 100644 (file)
@@ -140,12 +140,25 @@ get_connection(const char *connection_name)
                return NULL;
 }
 
+static bool
+ecpg_init(const struct connection *con, const char * connection_name, const int lineno)
+{
+       memcpy((char *) &sqlca, (char *) &sqlca_init, sizeof(sqlca));
+       if (con == NULL)
+       {
+               register_error(ECPG_NO_CONN, "No such connection %s in line %d.", connection_name ? connection_name : "NULL", lineno);
+               return (false);
+       }
+       
+       return (true);
+}
+
 static void
-ECPGfinish(struct connection * act)
+ecpg_finish(struct connection * act)
 {
        if (act != NULL)
        {
-               ECPGlog("ECPGfinish: finishing %s.\n", act->name);
+               ECPGlog("ecpg_finish: finishing %s.\n", act->name);
                PQfinish(act->connection);
                /* remove act from the list */
                if (act == all_connections)
@@ -166,7 +179,7 @@ ECPGfinish(struct connection * act)
                free(act);
        }
        else
-               ECPGlog("ECPGfinish: called an extra time.\n");
+               ECPGlog("ecpg_finish: called an extra time.\n");
 }
 
 static char *
@@ -383,8 +396,6 @@ ECPGexecute(struct statement * stmt)
        PGnotify   *notify;
        struct variable *var;
 
-       memcpy((char *) &sqlca, (char *) &sqlca_init, sizeof(sqlca));
-
        copiedquery = ecpg_strdup(stmt->command, stmt->lineno);
 
        /*
@@ -1029,11 +1040,8 @@ ECPGdo(int lineno, const char *connection_name, char *query,...)
        struct connection *con = get_connection(connection_name);
        bool            status;
 
-       if (con == NULL)
-       {
-               register_error(ECPG_NO_CONN, "No such connection %s in line %d.", connection_name ? connection_name : "NULL", lineno);
-               return (false);
-       }
+       if (!ecpg_init(con, connection_name, lineno))
+               return(false);
 
        va_start(args, query);
        if (create_statement(lineno, con, &stmt, query, args) == false)
@@ -1058,11 +1066,8 @@ ECPGstatus(int lineno, const char *connection_name)
 {
        struct connection *con = get_connection(connection_name);
 
-       if (con == NULL)
-       {
-               register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
-               return (false);
-       }
+       if (!ecpg_init(con, connection_name, lineno))
+               return(false);
 
        /* are we connected? */
        if (con->connection == NULL)
@@ -1081,11 +1086,8 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction)
        PGresult   *res;
        struct connection *con = get_connection(connection_name);
 
-       if (con == NULL)
-       {
-               register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
-               return (false);
-       }
+       if (!ecpg_init(con, connection_name, lineno))
+               return(false);
 
        ECPGlog("ECPGtrans line %d action = %s connection = %s\n", lineno, transaction, con->name);
 
@@ -1124,41 +1126,36 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
        struct connection *con = get_connection(connection_name);
        PGresult   *results;
 
-       if (con)
+       if (!ecpg_init(con, connection_name, lineno))
+               return(false);
+
+       if (con->autocommit == true && strncmp(mode, "OFF", strlen("OFF")) == 0)
        {
-               if (con->autocommit == true && strncmp(mode, "OFF", strlen("OFF")) == 0)
+               if (con->committed)
                {
-                       if (con->committed)
+                       if ((results = PQexec(con->connection, "begin transaction")) == NULL)
                        {
-                               if ((results = PQexec(con->connection, "begin transaction")) == NULL)
-                               {
-                                       register_error(ECPG_TRANS, "Error in transaction processing line %d.", lineno);
-                                       return false;
-                               }
-                               PQclear(results);
-                               con->committed = false;
+                               register_error(ECPG_TRANS, "Error in transaction processing line %d.", lineno);
+                               return false;
                        }
-                       con->autocommit = false;
+                       PQclear(results);
+                       con->committed = false;
                }
-               else if (con->autocommit == false && strncmp(mode, "ON", strlen("ON")) == 0)
+               con->autocommit = false;
+       }
+       else if (con->autocommit == false && strncmp(mode, "ON", strlen("ON")) == 0)
+       {
+               if (!con->committed)
                {
-                       if (!con->committed)
+                       if ((results = PQexec(con->connection, "commit")) == NULL)
                        {
-                               if ((results = PQexec(con->connection, "commit")) == NULL)
-                               {
-                                       register_error(ECPG_TRANS, "Error in transaction processing line %d.", lineno);
-                                       return false;
-                               }
-                               PQclear(results);
-                               con->committed = true;
+                               register_error(ECPG_TRANS, "Error in transaction processing line %d.", lineno);
+                               return false;
                        }
-                       con->autocommit = true;
+                       PQclear(results);
+                       con->committed = true;
                }
-       }
-       else
-       {
-               register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
-               return false;
+               con->autocommit = true;
        }
 
        return true;
@@ -1169,24 +1166,22 @@ ECPGsetconn(int lineno, const char *connection_name)
 {
        struct connection *con = get_connection(connection_name);
 
-       if (con)
-       {
-               actual_connection = con;
-               return true;
-       }
-       else
-       {
-               register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
-               return false;
-       }
+       if (!ecpg_init(con, connection_name, lineno))
+               return(false);
+
+       actual_connection = con;
+       return true;
 }
 
 bool
 ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd, const char *connection_name, int autocommit)
 {
-       struct connection *this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno);
+       struct connection *this;
 
-       if (!this)
+
+       memcpy((char *) &sqlca, (char *) &sqlca_init, sizeof(sqlca));
+       
+       if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL)
                return false;
 
        if (dbname == NULL && connection_name == NULL)
@@ -1213,7 +1208,7 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd
 
        if (PQstatus(this->connection) == CONNECTION_BAD)
        {
-               ECPGfinish(this);
+               ecpg_finish(this);
                ECPGlog("connect: could not open database %s %s%s in line %d\n", dbname ? dbname : "<DEFAULT>", user ? "for user " : "", user ? user : "", lineno);
                register_error(ECPG_CONNECT, "connect: could not open database %s.", dbname ? dbname : "<DEFAULT>");
                return false;
@@ -1237,21 +1232,17 @@ ECPGdisconnect(int lineno, const char *connection_name)
                        struct connection *f = con;
 
                        con = con->next;
-                       ECPGfinish(f);
+                       ecpg_finish(f);
                }
        }
        else
        {
                con = get_connection(connection_name);
 
-               if (con == NULL)
-               {
-                       ECPGlog("disconnect: not connected to connection %s\n", connection_name ? connection_name : "NULL");
-                       register_error(ECPG_NO_CONN, "No such connection %s in line %d", connection_name ? connection_name : "NULL", lineno);
-                       return false;
-               }
+               if (!ecpg_init(con, connection_name, lineno))
+                       return(false);
                else
-                       ECPGfinish(con);
+                       ecpg_finish(con);
        }
 
        return true;
index 360dee3b34f6d3d904d4f0ca0da96ac217805fc1..3dc3603d5423fdc0f6d887562138b8afa2ef241d 100644 (file)
@@ -117,8 +117,8 @@ exec sql end declare section;
        exec sql commit;
 
        strcpy(msg, "disconnect"); 
-
        exec sql disconnect;
+
        if (dbgs != NULL)
                 fclose(dbgs);
 
index 13786518f05e5b162936d66a78ef4d0bb6713fe5..12e3e07dd21fdc65a097fecd92f6ec7576f57762 100644 (file)
@@ -109,8 +109,8 @@ exec sql end declare section;
        exec sql commit;
 
        strcpy(msg, "disconnect"); 
-
        exec sql disconnect;
+
        if (dbgs != NULL)
                 fclose(dbgs);