1 package com.quantum.sql;
3 import java.sql.Connection;
4 import java.sql.SQLException;
6 import com.quantum.adapters.DatabaseAdapter;
7 import com.quantum.view.LogProxy;
9 public class SQLHelper {
11 public static int getSize(Connection connection, String tableName, DatabaseAdapter adapter) throws SQLException {
12 SQLResults results = MultiSQLServer.getInstance().execute(
13 connection, adapter.getCountQuery(tableName));
14 if (results.getRowCount() > 0 && results.getColumnCount() > 0) {
15 return Integer.parseInt(results.getElement(1, 1).toString());
21 public static SQLResults getResults(Connection connection, String query, int start, int end, int maxLength, String encoding) {
23 return MultiSQLServer.getInstance().execute(connection,
24 query, start, end, maxLength, encoding);
25 } catch (SQLException e) {
26 LogProxy log = LogProxy.getInstance();
29 "Error Executing: " + query + ":" + e.toString(), e); //$NON-NLS-1$ //$NON-NLS-2$
31 SQLResults results = new SQLResults();
32 results.setIsError(true);
37 * True if the type is Real (numeric and with decimal part) according to java.sql.Types
41 public static boolean isReal(int type) {
42 return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT ||
43 type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL );
47 * True if the type is Numeric according to java.sql.Types
51 public static boolean isNumeric(int type) {
52 return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT ||
53 type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL || type == java.sql.Types.BIGINT ||
54 type == java.sql.Types.TINYINT || type == java.sql.Types.SMALLINT || type == java.sql.Types.INTEGER );
57 * True if the type is textual according to java.sql.Types
61 public static boolean isText(int type) {
62 return (type == java.sql.Types.CLOB || type == java.sql.Types.VARBINARY || type ==java.sql.Types.VARCHAR
63 || type == java.sql.Types.CHAR || type == java.sql.Types.LONGVARCHAR );
66 public static String getQualifiedName(String schema, String name) {
67 return (schema != null && schema.length() > 0) ? schema + "." + name : name;