1 package com.quantum.adapters;
3 import com.quantum.sql.SQLHelper;
4 import com.quantum.util.QuantumUtil;
5 import com.quantum.util.sql.TypesHelper;
8 public class PostgresAdapter extends DatabaseAdapter {
9 public String getShowTableQuery(String qualifier, boolean isDefault) {
10 return "SELECT SCHEMANAME, TABLENAME FROM PG_TABLES WHERE SCHEMANAME = '"
13 public String getShowViewQuery(String qualifier, boolean isDefault) {
14 return "SELECT SCHEMANAME, VIEWNAME FROM PG_VIEWS WHERE SCHEMANAME = '"
17 public String getShowSequenceQuery(String qualifier, boolean isDefault) {
18 return "SELECT SCHEMANAME, relname FROM pg_class WHERE relkind = 'S'" +
19 "AND SCHEMANAME = '" + qualifier + "'";
21 public String getNextValue(String sequence, String owner) {
22 return "SELECT NEXTVAL('" + SQLHelper.getQualifiedName(owner, sequence) + "')";
24 public String getPrevValue(String sequence, String owner) {
25 return "SELECT * FROM " + SQLHelper.getQualifiedName(owner, sequence);
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
34 public String quote(String string, int type, String typeString) {
35 // Booleans in PostgreSQL are queried "t" or "f", but require "true" or "false" when inputed.
36 if (type == TypesHelper.BIT || type == TypesHelper.BOOLEAN ) // Postgresql seems to identify booleans as BITs
38 if (string.indexOf('t') >= 0 || string.indexOf('T') >= 0 )
40 else if (string.indexOf('f') >= 0 || string.indexOf('F') >= 0 )
45 // use the default (upper type)
46 return super.quote(string, type, typeString);
50 * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
52 public String filterTableName(String tableName) {
53 // If there is no mixed case, better not quote, it's prettier on display
54 if (tableName.equals(tableName.toUpperCase())) return tableName;
55 // We quote the table name (and only the table name) because it has mixed case
56 if (QuantumUtil.getSchemaName(tableName).equals("")) {
57 return "\"" + tableName +"\""; //$NON-NLS-1$
59 return QuantumUtil.getSchemaName(tableName) + ".\"" +
60 QuantumUtil.getTableName(tableName) + "\"";
64 * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
66 public String getDefaultSchema(String userid) {