package net.sourceforge.phpdt.sql.adapters;
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+
+
public class OracleAdapter extends DatabaseAdapter {
- public String getShowTableQuery(DatabaseInfo info) {
- return "SELECT TABLE_NAME FROM USER_TABLES";
- }
- public String getShowViewQuery(DatabaseInfo info) {
- return "SELECT VIEW_NAME FROM USER_VIEWS";
- }
- public String getShowSequenceQuery(DatabaseInfo info) {
- return "SELECT SEQUENCE_NAME FROM USER_SEQUENCES";
- }
- public String getNextValue(String sequence) {
- return "SELECT LAST_NUMBER FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '" + sequence + "'";
- }
- public DatabaseAdapter getInstance() {
- return new OracleAdapter();
+ public String getShowTableQuery(DatabaseInfo info) {
+ return "SELECT TABLE_NAME FROM USER_TABLES"; //$NON-NLS-1$
+ }
+ public String getShowViewQuery(DatabaseInfo info) {
+ return "SELECT VIEW_NAME FROM USER_VIEWS"; //$NON-NLS-1$
+ }
+ public String getShowSequenceQuery(DatabaseInfo info) {
+ return "SELECT SEQUENCE_NAME FROM USER_SEQUENCES"; //$NON-NLS-1$
+ }
+ public String getNextValue(String sequence) {
+ return "SELECT LAST_NUMBER FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '" + sequence + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ /**
+ * Quotes a string according to the type of the column
+ * @param string to be quoted
+ * @param type according to java.sql.Types
+ * @return
+ */
+ public String quote(String string, int type) {
+ if (SQLHelper.isText(type)) {
+ if (string.indexOf('\'') >= 0)
+ return '"' + string + '"';
+ else
+ return "'" + string + "'"; //$NON-NLS-1$ //$NON-NLS-2$
+
+ } else if (type == java.sql.Types.DATE || type == java.sql.Types.TIMESTAMP) {
+ string = string.trim();
+ String sub = string.substring(string.length()-2, string.length()-1);
+ if (string.length() > 1 && sub.equals(Messages.getString("OracleAdapter.._3"))) //$NON-NLS-1$
+ string = string.substring(0,string.length()-2);
+ return "TO_DATE('" + string + "','yyyy-mm-dd hh24:mi:ss')"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return string;
}
}
\ No newline at end of file