$owner = $db->dsn['username'];
}
- $query = 'SELECT column_name name,
- data_type "type",
- nullable,
- data_default "default",
- COALESCE(data_precision, data_length) "length",
- data_scale "scale"
+ $query = 'SELECT column_name AS "name",
+ data_type AS "type",
+ nullable AS "nullable",
+ data_default AS "default",
+ COALESCE(data_precision, data_length) AS "length",
+ data_scale AS "scale"
FROM all_tab_columns
WHERE (table_name=? OR table_name=?)
AND (owner=? OR owner=?)
if ($default === 'NULL') {
$default = null;
}
+ //ugly hack, but works for the reverse direction
+ if ($default == "''") {
+ $default = '';
+ }
if ((null === $default) && $notnull) {
$default = '';
}
$owner = $db->dsn['username'];
}
- $query = "SELECT aic.column_name,
- aic.column_position,
- aic.descend,
- aic.table_owner,
- alc.constraint_type
+ $query = 'SELECT aic.column_name AS "column_name",
+ aic.column_position AS "column_position",
+ aic.descend AS "descend",
+ aic.table_owner AS "table_owner",
+ alc.constraint_type AS "constraint_type"
FROM all_ind_columns aic
LEFT JOIN all_constraints alc
ON aic.index_name = alc.constraint_name
WHERE (aic.table_name=? OR aic.table_name=?)
AND (aic.index_name=? OR aic.index_name=?)
AND (aic.table_owner=? OR aic.table_owner=?)
- ORDER BY column_position";
+ ORDER BY column_position';
$stmt = $db->prepare($query);
if (PEAR::isError($stmt)) {
return $stmt;
\'SIMPLE\' "match",
CASE alc.deferrable WHEN \'NOT DEFERRABLE\' THEN 0 ELSE 1 END "deferrable",
CASE alc.deferred WHEN \'IMMEDIATE\' THEN 0 ELSE 1 END "initiallydeferred",
- alc.search_condition,
+ alc.search_condition AS "search_condition",
alc.table_name,
- cols.column_name,
+ cols.column_name AS "column_name",
cols.position,
r_alc.table_name "references_table",
r_cols.column_name "references_field",
return $db;
}
- $query = 'SELECT trigger_name,
- table_name,
- trigger_body,
- trigger_type,
- triggering_event trigger_event,
- description trigger_comment,
- 1 trigger_enabled,
- when_clause
+ $query = 'SELECT trigger_name AS "trigger_name",
+ table_name AS "table_name",
+ trigger_body AS "trigger_body",
+ trigger_type AS "trigger_type",
+ triggering_event AS "trigger_event",
+ description AS "trigger_comment",
+ 1 AS "trigger_enabled",
+ when_clause AS "when_clause"
FROM user_triggers
WHERE trigger_name = \''. strtoupper($trigger).'\'';
$types = array(
return $query;
}
+ /**
+ * Obtain DBMS specific SQL code portion needed to declare a generic type
+ * field to be used in statement like CREATE TABLE, without the field name
+ * and type values (ie. just the character set, default value, if the
+ * field is permitted to be NULL or not, and the collation options).
+ *
+ * @param array $field associative array with the name of the properties
+ * of the field being declared as array indexes. Currently, the types
+ * of supported field properties are as follows:
+ *
+ * default
+ * Text value to be used as default for this field.
+ * notnull
+ * Boolean flag that indicates whether this field is constrained
+ * to not be set to null.
+ * charset
+ * Text value with the default CHARACTER SET for this field.
+ * collation
+ * Text value with the default COLLATION for this field.
+ * @return string DBMS specific SQL code portion that should be used to
+ * declare the specified field's options.
+ * @access protected
+ */
+ function _getDeclarationOptions($field)
+ {
+ $charset = empty($field['charset']) ? '' :
+ ' '.$this->_getCharsetFieldDeclaration($field['charset']);
+
+ $notnull = empty($field['notnull']) ? ' NULL' : ' NOT NULL';
+ $default = '';
+ if (array_key_exists('default', $field)) {
+ if ($field['default'] === '') {
+ $db = $this->getDBInstance();
+ if (PEAR::isError($db)) {
+ return $db;
+ }
+ $valid_default_values = $this->getValidTypes();
+ $field['default'] = $valid_default_values[$field['type']];
+ if ($field['default'] === '' && ($db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL)) {
+ $field['default'] = ' ';
+ }
+ }
+ if (null !== $field['default']) {
+ $default = ' DEFAULT ' . $this->quote($field['default'], $field['type']);
+ }
+ }
+
+ $collation = empty($field['collation']) ? '' :
+ ' '.$this->_getCollationFieldDeclaration($field['collation']);
+
+ return $charset.$default.$notnull.$collation;
+ }
+
// }}}
// {{{ _doQuery()