3.x RC1 compatibility show and refresh browser preview
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / adapters / OracleAdapter.java
1 package com.quantum.adapters;
2
3 import com.quantum.Messages;
4 import com.quantum.sql.SQLHelper;
5 import com.quantum.util.QuantumUtil;
6
7
8
9 public class OracleAdapter extends DatabaseAdapter {
10         public String getShowSequenceQuery(String qualifier, boolean isDefault) {
11         return "SELECT SEQUENCE_OWNER, SEQUENCE_NAME FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + qualifier + "'"; //$NON-NLS-1$
12         }
13         public String getPrevValue(String sequence, String owner) {
14         return "SELECT LAST_NUMBER FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '" + owner + "' AND SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$
15         }       
16         public String getNextValue(String sequence, String owner) {
17                 return "SELECT " + SQLHelper.getQualifiedName(owner, sequence) + ".NEXTVAL FROM DUAL";
18         }
19         public String getCommentsQuery(String tableName, String column) {
20                 String query = "SELECT COMMENTS FROM ALL_COL_COMMENTS WHERE TABLE_NAME = '"; 
21                 query += QuantumUtil.getTableName(tableName) + "' AND COLUMN_NAME = '" + column + "'" ;
22                 if (!(QuantumUtil.getSchemaName(tableName).equals("")))
23                         query += " AND OWNER = '" + QuantumUtil.getSchemaName(tableName) + "'";
24                 return query;
25         }
26         /**
27          * Quotes a string according to the type of the column 
28          * @param string to be quoted
29          * @param type according to java.sql.Types
30          * @return
31          */
32         public String quote(String string, int type, String typeString) {
33                 if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) {
34                         string = string.trim();
35                         String sub = string.substring(string.length()-2, string.length()-1);
36                         if (string.length() > 1 &&  sub.equals(Messages.getString("OracleAdapter.._3"))) //$NON-NLS-1$
37                                 string = string.substring(0,string.length()-2);
38                         return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$
39                 }
40                 // use the default (upper type)
41                 return super.quote(string, type, typeString);
42         }
43
44         /* (non-Javadoc)
45          * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
46          */
47         public String filterTableName(String tableName) {
48                 // If there is no mixed case, better not quote, it's prettier on display
49                 if (tableName.equals(tableName.toUpperCase())) return tableName;
50                 // We quote the table name (and only the table name) because it has mixed case
51                 if (QuantumUtil.getSchemaName(tableName).equals(""))
52                         return "\"" + tableName +"\""; //$NON-NLS-1$
53                 else
54                         return QuantumUtil.getSchemaName(tableName) + ".\"" + 
55                                         QuantumUtil.getTableName(tableName) + "\"";
56 }
57
58     /**
59      * The default schema for Oracle is the upper-case userid.
60      * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
61      */
62     public String getDefaultSchema(String userid) {
63         return super.getDefaultSchema(userid).toUpperCase();
64     }
65   
66
67 }