initial quantum version
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / sql / SQLHelper.java
diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLHelper.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/SQLHelper.java
new file mode 100644 (file)
index 0000000..7a050d1
--- /dev/null
@@ -0,0 +1,73 @@
+package com.quantum.sql;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Vector;
+
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.view.LogProxy;
+
+public class SQLHelper {
+       
+       public static Vector getSchemas(Connection connection) {
+               return MultiSQLServer.getInstance().getSchemas(connection);
+       }
+    public static int getSize(Connection connection, String tableName, DatabaseAdapter adapter) throws SQLException {
+        SQLResults results = MultiSQLServer.getInstance().execute( 
+                connection, adapter.getCountQuery(tableName));
+        if (results.getRowCount() > 0 && results.getColumnCount() > 0) {
+            return Integer.parseInt(results.getElement(1, 1).toString());
+        } else {
+            return -1;
+        }
+    }
+       
+       public static SQLResults getResults(Connection connection, String query, int start, int end, int maxLength, String encoding) {
+               try {
+                       return MultiSQLServer.getInstance().execute(connection, 
+                           query, start, end, maxLength, encoding);
+               } catch (SQLException e) {
+                       LogProxy log = LogProxy.getInstance();
+                       log.addText(
+                               LogProxy.ERROR,
+                               "Error Executing: " + query + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
+               }
+               SQLResults results = new SQLResults();
+               results.setIsError(true);
+               return results;
+       }
+       
+       /**
+        * True if the type is Real (numeric and with decimal part) according to java.sql.Types
+        * @param type
+        * @return
+        */
+       public static boolean isReal(int type) {
+               return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT || 
+                       type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL );
+       }
+
+       /**
+        * True if the type is Numeric according to java.sql.Types
+        * @param type
+        * @return
+        */
+       public static boolean isNumeric(int type) {
+               return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT || 
+                       type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL || type == java.sql.Types.BIGINT ||
+                       type == java.sql.Types.TINYINT || type == java.sql.Types.SMALLINT || type == java.sql.Types.INTEGER );
+       }
+       /**
+        * True if the type is textual according to java.sql.Types
+        * @param type
+        * @return
+        */
+       public static boolean isText(int type) {
+               return (type == java.sql.Types.CLOB || type == java.sql.Types.VARBINARY || type ==java.sql.Types.VARCHAR
+                               || type == java.sql.Types.CHAR || type == java.sql.Types.LONGVARCHAR );
+       }
+       
+       public static String getQualifiedName(String schema, String name) {
+               return (schema != null && schema.length() > 0) ? schema + "." + name : name;
+       }
+}