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 protected PostgresAdapter() {
10 super(AdapterFactory.POSTGRES);
12 public String getShowTableQuery(String qualifier) {
13 return "SELECT SCHEMANAME, TABLENAME FROM PG_TABLES WHERE SCHEMANAME = '"
16 public String getShowViewQuery(String qualifier) {
17 return "SELECT SCHEMANAME, VIEWNAME FROM PG_VIEWS WHERE SCHEMANAME = '"
20 public String getShowSequenceQuery(String qualifier) {
21 return "select pg_namespace.nspname, relname " +
22 "from pg_class, pg_namespace where relkind = 'S' " +
23 "and relnamespace = pg_namespace.oid " +
24 "and pg_namespace.nspname = '" + qualifier + "'";
26 public String getNextValue(String sequence, String owner) {
27 return "SELECT NEXTVAL('" + SQLHelper.getQualifiedName(owner, sequence) + "')";
29 public String getPrevValue(String sequence, String owner) {
30 return "SELECT * FROM " + SQLHelper.getQualifiedName(owner, sequence);
34 * Quotes a string according to the type of the column
35 * @param string to be quoted
36 * @param type according to java.sql.Types
39 public String quote(String string, int type, String typeString) {
40 // Booleans in PostgreSQL are queried "t" or "f", but require "true" or "false" when inputed.
41 if (type == TypesHelper.BIT || type == TypesHelper.BOOLEAN ) // Postgresql seems to identify booleans as BITs
43 if (string.indexOf('t') >= 0 || string.indexOf('T') >= 0 )
45 else if (string.indexOf('f') >= 0 || string.indexOf('F') >= 0 )
50 // use the default (upper type)
51 return super.quote(string, type, typeString);
55 * @see com.quantum.adapters.DatabaseAdapter#filterTableName(java.lang.String)
57 public String filterTableName(String tableName) {
58 // If there is no mixed case, better not quote, it's prettier on display
59 if (tableName.equals(tableName.toUpperCase())) return tableName;
60 // We quote the table name (and only the table name) because it has mixed case
61 if (QuantumUtil.getSchemaName(tableName).equals("")) {
62 return "\"" + tableName +"\""; //$NON-NLS-1$
64 return QuantumUtil.getSchemaName(tableName) + ".\"" +
65 QuantumUtil.getTableName(tableName) + "\"";
69 * @see com.quantum.adapters.DatabaseAdapter#getDefaultSchema(java.lang.String)
71 public String getDefaultSchema(String userid) {