diff --git a/lib/Connection.php b/lib/Connection.php index c32311bcb..6341db5e2 100644 --- a/lib/Connection.php +++ b/lib/Connection.php @@ -245,6 +245,10 @@ protected function __construct($info) } else $host = "unix_socket=$info->host"; + // PDO driver redshift == pgsql + if ($info->protocol == 'redshift') { + $info->protocol = 'pgsql'; + } $this->connection = new PDO("$info->protocol:$host;dbname=$info->db", $info->user, $info->pass, static::$PDO_OPTIONS); } catch (PDOException $e) { diff --git a/lib/adapters/PgsqlAdapter.php b/lib/adapters/PgsqlAdapter.php index 72da44182..56d9e8e2d 100644 --- a/lib/adapters/PgsqlAdapter.php +++ b/lib/adapters/PgsqlAdapter.php @@ -6,7 +6,7 @@ /** * Adapter for Postgres (not completed yet) - * + * * @package ActiveRecord */ class PgsqlAdapter extends Connection @@ -47,7 +47,7 @@ public function query_column_info($table) WHERE c.oid = pg_index.indrelid AND a.attnum = ANY (pg_index.indkey) AND pg_index.indisprimary = 't' - ) IS NOT NULL AS pk, + ) IS NOT NULL AS pk, REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE((SELECT pg_attrdef.adsrc FROM pg_attrdef WHERE c.oid = pg_attrdef.adrelid @@ -75,7 +75,7 @@ public function create_column(&$column) $c->inflected_name = Inflector::instance()->variablize($column['field']); $c->name = $column['field']; $c->nullable = ($column['not_nullable'] ? false : true); - $c->pk = ($column['pk'] ? true : false); + $c->pk = ($column['pk'] == 't'); $c->auto_increment = false; if (substr($column['type'],0,9) == 'timestamp') diff --git a/lib/adapters/RedshiftAdapter.php b/lib/adapters/RedshiftAdapter.php new file mode 100644 index 000000000..000b78225 --- /dev/null +++ b/lib/adapters/RedshiftAdapter.php @@ -0,0 +1,56 @@ + 0 + AND a.attrelid = c.oid + AND a.atttypid = t.oid +ORDER BY a.attnum +SQL; + $values = array($table); + return $this->query($sql,$values); + } +}