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