Add basic support for savepoints [Hiroshi Saito/Dave Page]
authorDave Page <dpage@pgadmin.org>
Fri, 2 Sep 2005 08:40:59 +0000 (08:40 +0000)
committerDave Page <dpage@pgadmin.org>
Fri, 2 Sep 2005 08:40:59 +0000 (08:40 +0000)
connection.c
misc.c
misc.h

index c47273e5f3e27dce9017638d8c5a7bf7c3f600dc..4630ce8f785b1d3e4fa003483fcdd486b2f9e880 100644 (file)
@@ -1822,7 +1822,14 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi, UDWORD flag)
                    else if (strnicmp(cmdbuffer, "COMMIT", 6) == 0)
                        CC_on_commit(self);
                    else if (strnicmp(cmdbuffer, "ROLLBACK", 8) == 0)
-                       CC_on_abort(self, NO_TRANS);
+                   {
+                       /* 
+                          The method of ROLLBACK an original form ....
+                          ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name
+                        */
+                       if (PG_VERSION_LT(self, 8.0) || !(contains_token(query, " TO ")))
+                           CC_on_abort(self, NO_TRANS);
+                   }
                    else if (strnicmp(cmdbuffer, "END", 3) == 0)
                        CC_on_commit(self);
                    else if (strnicmp(cmdbuffer, "ABORT", 5) == 0)
@@ -3195,7 +3202,14 @@ LIBPQ_execute_query(ConnectionClass *self,char *query)
    else if (strnicmp(cmdbuffer, "COMMIT", 6) == 0)
        CC_on_commit(self);
    else if (strnicmp(cmdbuffer, "ROLLBACK", 8) == 0)
-       CC_on_abort(self, NO_TRANS);
+   {
+       /* 
+          The method of ROLLBACK an original form ....
+          ROLLBACK [ WORK | TRANSACTION ] TO [ SAVEPOINT ] savepoint_name
+        */
+       if (PG_VERSION_LT(self, 8.0) || !(contains_token(query, " TO ")))
+           CC_on_abort(self, NO_TRANS);
+   }
    else if (strnicmp(cmdbuffer, "END", 3) == 0)
        CC_on_commit(self);
    else if (strnicmp(cmdbuffer, "ABORT", 5) == 0)
diff --git a/misc.c b/misc.c
index 35d67567d7f4b95ba4dd905afe96afd68707fbba..5e78949c76402575286bdc40b83f13a1aa6124e8 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -447,3 +447,20 @@ schema_strcat1(char *buf, const char *fmt, const char *s1, const char *s, int le
    }
    return my_strcat1(buf, fmt, s1, s, len);
 }
+
+int 
+contains_token(char *data, char *token)
+{
+   int i, tlen, dlen;
+
+   dlen = strlen(data);
+   tlen = strlen(token);
+
+   for (i = 0; i < dlen-tlen+1; i++)
+   {
+       if (!strnicmp((const char *)data+i, token, tlen))
+           return 1;
+   }
+
+   return 0;
+}
diff --git a/misc.h b/misc.h
index 96c764112d74200c43e9823d2bd74a03781a4c02..0dc5e02a912152483077d6e37c2b063243d95fce 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -116,16 +116,16 @@ int   get_mylog(void);
 #endif
 
 
-void       remove_newlines(char *string);
-char      *strncpy_null(char *dst, const char *src, int len);
-char      *trim(char *string);
-char      *make_string(const char *s, int len, char *buf, size_t bufsize);
-char      *make_lstring_ifneeded(ConnectionClass *, const char *s, int len, BOOL);
-char      *my_strcat(char *buf, const char *fmt, const char *s, int len);
-char      *schema_strcat(char *buf, const char *fmt, const char *s, int len,
+void   remove_newlines(char *string);
+char   *strncpy_null(char *dst, const char *src, int len);
+char   *trim(char *string);
+char   *make_string(const char *s, int len, char *buf, size_t bufsize);
+char   *make_lstring_ifneeded(ConnectionClass *, const char *s, int len, BOOL);
+char   *my_strcat(char *buf, const char *fmt, const char *s, int len);
+char   *schema_strcat(char *buf, const char *fmt, const char *s, int len,
        const char *, int, ConnectionClass *conn);
-char      *my_strcat1(char *buf, const char *fmt, const char *s1, const char *s, int len);
-char      *schema_strcat1(char *buf, const char *fmt, const char *s1,
+char   *my_strcat1(char *buf, const char *fmt, const char *s1, const char *s, int len);
+char   *schema_strcat1(char *buf, const char *fmt, const char *s1,
                const char *s, int len,
                const char *, int, ConnectionClass *conn);
 /* #define GET_SCHEMA_NAME(nspname)    (stricmp(nspname, "public") ? nspname : "") */
@@ -137,9 +137,10 @@ char      *schema_strcat1(char *buf, const char *fmt, const char *s1,
 #define STRCPY_TRUNCATED   (-1)
 #define STRCPY_NULL            (-2)
 
-int            my_strcpy(char *dst, int dst_len, const char *src, int src_len);
-\r
-/* Define a type for defining a constant string expression */\r
-#define CSTR static const char * const\r
+int    my_strcpy(char *dst, int dst_len, const char *src, int src_len);
+int    contains_token(char *data, char *token);
+
+/* Define a type for defining a constant string expression */
+#define CSTR static const char * const
 
 #endif