Refactory: smarty.ui plugin.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / sql / SQLHelper.java
1 package net.sourceforge.phpdt.sql.sql;
2
3 import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
4
5 public class SQLHelper {
6         
7         public static int getSize(Bookmark current, String tableName) {
8                 SQLResults results = MultiSQLServer.getInstance().execute(
9             current.getConnection(), "SELECT COUNT(*) FROM " + tableName); //$NON-NLS-1$
10                 return Integer.parseInt(results.getElement(1, 1).toString());
11         }
12         public static SQLResults getResults(Bookmark current, String query, int start, int end, int maxLength, String encoding) {
13                 return MultiSQLServer.getInstance().execute(current.getConnection(), 
14             query, start, end, maxLength, encoding);
15         }
16         public static String getFullTableName(Bookmark current, String table) {
17                 String schema = current.getSchema();
18                 if (schema == null) return table;
19                 if (schema.equals("")) return table; //$NON-NLS-1$
20                 return schema + "." + table; //$NON-NLS-1$
21         }
22
23         /**
24          * True if the type is Real (numeric and with decimal part) according to java.sql.Types
25          * @param type
26          * @return
27          */
28         public static boolean isReal(int type) {
29                 return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT || 
30                         type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL );
31         }
32
33         /**
34          * True if the type is Numeric according to java.sql.Types
35          * @param type
36          * @return
37          */
38         public static boolean isNumeric(int type) {
39                 return (type == java.sql.Types.DECIMAL || type == java.sql.Types.DOUBLE || type ==java.sql.Types.FLOAT || 
40                         type == java.sql.Types.NUMERIC || type == java.sql.Types.REAL || type == java.sql.Types.BIGINT ||
41                         type == java.sql.Types.TINYINT || type == java.sql.Types.SMALLINT || type == java.sql.Types.INTEGER );
42         }
43         /**
44          * True if the type is textual according to java.sql.Types
45          * @param type
46          * @return
47          */
48         public static boolean isText(int type) {
49                 return (type == java.sql.Types.CLOB || type == java.sql.Types.VARBINARY || type ==java.sql.Types.VARCHAR );
50         }
51
52 }