empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r691328 - in /incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db: DBDatabaseDriver.java hsql/DBDatabaseDriverHSql.java
Date Tue, 02 Sep 2008 17:55:27 GMT
Author: doebele
Date: Tue Sep  2 10:55:27 2008
New Revision: 691328

URL: http://svn.apache.org/viewvc?rev=691328&view=rev
Log: (empty)

Modified:
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
    incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java?rev=691328&r1=691327&r2=691328&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/DBDatabaseDriver.java
Tue Sep  2 10:55:27 2008
@@ -27,6 +27,8 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -101,8 +103,19 @@
     // Logger
     protected static Log log = LogFactory.getLog(DBDatabaseDriver.class);
     
-    // Flag wether or not to set column defaults when crating dll statements
+    // Flag whether or not to set column defaults when crating DDL statements
     protected boolean ddlColumnDefaults = false;
+
+    // Illegal Name Chars and Reserved SQL Keywords
+    private static final char[]   illegalNameChars   = new char[] { '@', '?', '>', '=',
'<', ';', ':', 
+                                                                    '/', '.', '-', ',', '+',
'*', ')', '(',
+                                                                    '\'', '&', '%', '!'
+                                                                  };        
+    private static final String[] generalSQLKeywords = new String[] { "count", "user", "on",
"off",
+                                                           "table", "column", "view", "index",
"constraint", 
+                                                           "select", "udpate", "insert",
"alter", "delete" };        
+    protected final Set<String> reservedSQLKeywords;
+
     
     // DBSeqTable
     public static class DBSeqTable extends DBTable
@@ -194,6 +207,17 @@
             }
         }
     }
+    
+    /**
+     * Constructor
+     */
+    public DBDatabaseDriver()
+    {
+        // Initialize List of reserved Keywords
+        reservedSQLKeywords = new HashSet<String>(generalSQLKeywords.length);
+        for (int i=0; i<generalSQLKeywords.length; i++)
+             reservedSQLKeywords.add(generalSQLKeywords[i]);
+    }
 
     /**
      * This function creates a DBCommand derived object this database
@@ -211,15 +235,29 @@
 
     /**
      * Checks wether a table or column name needs to be quoted or not<BR/>
-     * By default names containing a "-", "+" or " " require quoting.<BR/>
+     * By default all reserved SQL keywords as well as names 
+     * containing a "-", "/", "+" or " " require quoting.<BR/>
      * Overrides this function to add database specific keywords like "user" or "count" 

      */
     protected boolean quoteElementName(String name)
     {
-        // Check for any of the characters - +  and space
-        return (name.indexOf(' ')>0)
-            || (name.indexOf('-')>0)
-            || (name.indexOf('+')>0); 
+        // Check for reserved names
+        if (reservedSQLKeywords.contains(name.toLowerCase()))
+            return true;
+        // Check for illegalNameChars
+        int len = name.length();
+        for (int i=0; i<len; i++)
+        {   char c = name.charAt(i);
+            for (int j=0; j<illegalNameChars.length; j++)
+            {   char ic = illegalNameChars[j]; 
+                if (c>ic)
+                    break;
+                if (c==ic)
+                    return true;
+            }    
+        }
+        // Quoting not necessary
+        return false;
     }
 
     /**

Modified: incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java?rev=691328&r1=691327&r2=691328&view=diff
==============================================================================
--- incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
(original)
+++ incubator/empire-db/trunk/core/Empire-db/src/org/apache/empire/db/hsql/DBDatabaseDriverHSql.java
Tue Sep  2 10:55:27 2008
@@ -68,7 +68,8 @@
      */
     public DBDatabaseDriverHSql()
     {
-        // Default Constructor
+        // Add "count" to list of reserved Keywords
+        reservedSQLKeywords.add("count");
     }
 
     /**
@@ -693,17 +694,6 @@
         // done
         return script.addStmt(sql.toString());
     }
-    
-    /**
-     * Checks wether a table or column name needs to be quoted or not<BR/>
-     * By default names containing a "-", "+" or " " require quoting.<BR/>
-     * Overrides this function to add database specific keywords like "user" or "count" 

-     */
-    @Override
-    protected boolean quoteElementName(String name)
-    {
-        return (name.toUpperCase().equals("COUNT") || super.quoteElementName(name));
-    }
 
     /**
      * Returns true if the object has been dropped successfully.



Mime
View raw message