Log Message:
-----------
fix type quoting

Modified Files:
--------------
    pgadmin3/src/include:
        misc.h (r1.44 -> r1.45)
        pgDatatype.h (r1.10 -> r1.11)
        version.h (r1.9 -> r1.10)
    pgadmin3/src/schema:
        pgOperator.cpp (r1.23 -> r1.24)
    pgadmin3/src/utils:
        misc.cpp (r1.56 -> r1.57)

Index: misc.h
===================================================================
RCS file: /projects/pgadmin3/src/include/misc.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -Lsrc/include/misc.h -Lsrc/include/misc.h -u -w -r1.44 -r1.45
--- src/include/misc.h
+++ src/include/misc.h
@@ -94,18 +94,13 @@
 // Quoting
 wxString qtString(const wxString& value);   // add ' and escape if necessary
 wxString qtIdent(const wxString& value);    // add " if necessary
+wxString qtTypeIdent(const wxString& value);    // add " if necessary
 wxString qtStringDollar(const wxString &value);
 wxString qtStrip(const wxString& value);    // remove \"
 
 // check if size/pos have reasonable values
 void CheckOnScreen(wxPoint &pos, wxSize &size, const int w0=100, const int h0=70);
 
-// Keith 2003.03.11
-// We need an identifier validation function
-
-// Validation
-bool IsValidIdentifier(wxString ident);
-
 // string build helper
 void AppendIfFilled(wxString &str, const wxString &delimiter, const wxString &what);
 
Index: version.h
===================================================================
RCS file: /projects/pgadmin3/src/include/version.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -Lsrc/include/version.h -Lsrc/include/version.h -u -w -r1.9 -r1.10
--- src/include/version.h
+++ src/include/version.h
@@ -11,9 +11,9 @@
 
 
 // Application Versions
-#define VERSION_STR     wxT("1.2.0 Beta 1")
+#define VERSION_STR     wxT("1.2.0 Post Beta 1")
 #define VERSION_NUM     1,2,0,0
-#define VERSION_PACKAGE 1.2.0-beta1
+#define VERSION_PACKAGE 1.2.0-post-beta1
 
 #define PRERELEASE 1
 // #define BUILD "..."
Index: pgDatatype.h
===================================================================
RCS file: /projects/pgadmin3/src/include/pgDatatype.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -Lsrc/include/pgDatatype.h -Lsrc/include/pgDatatype.h -u -w -r1.10 -r1.11
--- src/include/pgDatatype.h
+++ src/include/pgDatatype.h
@@ -29,7 +29,7 @@
     wxString LengthString() const { return length; }
     wxString Array() const { return array; }
     wxString FullName() const { return name + length + array; }
-    wxString QuotedFullName() const { return qtIdent(name) + length + array; }
+    wxString QuotedFullName() const { return qtTypeIdent(name) + length + array; }
     wxString GetSchemaPrefix(pgDatabase *db) const;
     wxString GetQuotedSchemaPrefix(pgDatabase *db) const;
     long Length() const { return len; }
Index: pgOperator.cpp
===================================================================
RCS file: /projects/pgadmin3/src/schema/pgOperator.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -Lsrc/schema/pgOperator.cpp -Lsrc/schema/pgOperator.cpp -u -w -r1.23 -r1.24
--- src/schema/pgOperator.cpp
+++ src/schema/pgOperator.cpp
@@ -34,12 +34,12 @@
     wxString sql = wxT("DROP OPERATOR ") + GetFullIdentifier();
     
     if (GetLeftType().Length() > 0)
-        sql += wxT(" (") + qtIdent(GetLeftType());
+        sql += wxT(" (") + qtTypeIdent(GetLeftType());
     else
         sql += wxT(") (NONE");
 
     if (GetRightType().Length() > 0)
-        sql += wxT(", ") + qtIdent(GetLeftType()) + wxT(")");
+        sql += wxT(", ") + qtTypeIdent(GetLeftType()) + wxT(")");
     else
         sql += wxT(", NONE)");
 
@@ -56,8 +56,8 @@
            + wxT("(") + GetOperands() + wxT(");\n\n")
               wxT("CREATE OPERATOR ") + GetFullIdentifier()
             + wxT("(\n  PROCEDURE = ") + qtIdent(GetOperatorFunction());
-        AppendIfFilled(sql, wxT(",\n  LEFTARG = "), qtIdent(GetLeftType()));
-        AppendIfFilled(sql, wxT(",\n  RIGHTARG = "), qtIdent(GetRightType()));
+        AppendIfFilled(sql, wxT(",\n  LEFTARG = "), qtTypeIdent(GetLeftType()));
+        AppendIfFilled(sql, wxT(",\n  RIGHTARG = "), qtTypeIdent(GetRightType()));
         AppendIfFilled(sql, wxT(",\n  COMMUTATOR = "), GetCommutator());
         AppendIfFilled(sql, wxT(",\n  RESTRICT = "), qtIdent(GetRestrictFunction()));
         AppendIfFilled(sql, wxT(",\n  JOIN = "), qtIdent(GetJoinFunction()));
Index: misc.cpp
===================================================================
RCS file: /projects/pgadmin3/src/utils/misc.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -Lsrc/utils/misc.cpp -Lsrc/utils/misc.cpp -u -w -r1.56 -r1.57
--- src/utils/misc.cpp
+++ src/utils/misc.cpp
@@ -39,7 +39,10 @@
 
 extern "C"
 {
+#define YYSTYPE
+#define DECIMAL DECIMAL_P
 #include "parser/keywords.h"
+#include "parser/parse.h"
 }
 
 // we dont have an appropriate wxLongLong method
@@ -246,41 +249,94 @@
 }
 
 
-wxString qtIdent(const wxString& value)
-{
-    wxString result = value;
-    bool needQuoting=false;
-
-    if (result.Length() == 0)
-        return result;
-
-    int pos = 0;
 
+static bool needsQuoting(wxString& value, bool forTypes)
+{
     // Replace Double Quotes
-    result.Replace(wxT("\""), wxT("\"\""));
+    if (value.Replace(wxT("\""), wxT("\"\"")) > 0)
+        return true;
        
     // Is it a number?
-    if (result.IsNumber()) 
-        needQuoting = true;
+    if (value.IsNumber()) 
+        return true;
     else
     {
-        while (pos < (int)result.length())
+        int pos = 0;
+        while (pos < (int)value.length())
         {
-            if (!((result.GetChar(pos) >= '0') && (result.GetChar(pos) <= '9')) && 
-                !((result.GetChar(pos)  >= 'a') && (result.GetChar(pos)  <= 'z')) && 
-                !(result.GetChar(pos)  == '_'))
+            wxChar c=value.GetChar(pos);
+            if (!(c >= '0' && c <= '9') && 
+                !(c >= 'a' && c  <= 'z') && 
+                !(c == '_'))
             {
-                needQuoting = true;
-                break;
+                return true;
             }
             pos++;
         }
     }  
 
-    if (!needQuoting && ScanKeywordLookup(value.ToAscii()))
-        needQuoting = true;
+    // is it a keyword?
+    const ScanKeyword *sk=ScanKeywordLookup(value.ToAscii());
+    if (sk)
+    {
+        if (forTypes)
+        {
+            switch (sk->value)
+            {
+                case ANY:
+                case BIGINT:
+                case BIT:
+                case BOOLEAN_P:
+                case CHAR_P:
+                case CHARACTER:
+                case DECIMAL:
+                case DOUBLE_P:
+                case FLOAT_P:
+                case INT_P:
+                case INTEGER:
+                case INTERVAL:
+                case NUMERIC:
+                case SET:
+                case SMALLINT:
+                case TIME:
+                case TIMESTAMP:
+                case TRIGGER:
+                case VARCHAR:
+                    break;
+                default:
+                    return true;
+            }
+        }
+        else
+            return true;
+    }
+
+    return false;
+}
+
+
+wxString qtTypeIdent(const wxString& value)
+{
+    if (value.Length() == 0)
+        return value;
 
-    if (needQuoting)
+    wxString result = value;
+
+    if (needsQuoting(result, true))
+        return wxT("\"") + result + wxT("\"");
+    else
+        return result;
+}
+
+
+wxString qtIdent(const wxString& value)
+{
+    if (value.Length() == 0)
+        return value;
+
+    wxString result = value;
+
+    if (needsQuoting(result, false))
         return wxT("\"") + result + wxT("\"");
     else
         return result;
@@ -344,34 +400,6 @@
 }
 
 
-// Keith 2003.03.11
-// We need an identifier validation function
-bool IsValidIdentifier(wxString ident)
-{
-    // compiler complains if not unsigned
-       unsigned int len = ident.length();
-       if (!len)
-               return false;
-
-       wxString first = 
-               wxT("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
-       wxString second = 
-               wxT("_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
-
-       if (!first.Contains(ident.Left(1)))
-               return false;
-
-       unsigned int si;
-       for ( si = 1; si < len; si++)
-       {
-           if (!second.Contains(ident.Mid(si, 1)))
-                   return false;
-       }
-
-       return true;
-}
-
-
 queryTokenizer::queryTokenizer(const wxString& str, const wxChar delim)
 : wxStringTokenizer()
 {
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to