From 2740acc03e9ba2200227d4cbbffbe5eed3919041 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 14 Oct 2004 20:35:50 +0000 Subject: [PATCH] fixed the schema-retrival functions for MySql, Postges and MaxDB --- .../inc/adodb/datadict/datadict-mysql.inc.php | 11 ++++++----- .../inc/adodb/datadict/datadict-postgres.inc.php | 11 +++++++---- phpgwapi/inc/adodb/drivers/adodb-mysql.inc.php | 12 ++++++++++-- .../inc/adodb/drivers/adodb-postgres64.inc.php | 15 ++++++++------- phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php | 14 ++++++++++++-- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php b/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php index 0bea9003a7..0094f9139d 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-mysql.inc.php @@ -29,6 +29,7 @@ class ADODB2_mysql extends ADODB_DataDict { $t = $fieldobj->type; $len = $fieldobj->max_length; } + $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment; $len = -1; // mysql max_length is not accurate switch (strtoupper($t)) { @@ -66,11 +67,11 @@ class ADODB2_mysql extends ADODB_DataDict { return 'F'; case 'INT': - case 'INTEGER': return (!empty($fieldobj->primary_key)) ? 'R' : 'I'; - case 'TINYINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I1'; - case 'SMALLINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I2'; - case 'MEDIUMINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I4'; - case 'BIGINT': return (!empty($fieldobj->primary_key)) ? 'R' : 'I8'; + case 'INTEGER': return $is_serial ? 'R' : 'I'; + case 'TINYINT': return $is_serial ? 'R' : 'I1'; + case 'SMALLINT': return $is_serial ? 'R' : 'I2'; + case 'MEDIUMINT': return $is_serial ? 'R' : 'I4'; + case 'BIGINT': return $is_serial ? 'R' : 'I8'; default: return 'N'; } } diff --git a/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php b/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php index 8000a53763..f5c43271fc 100644 --- a/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php +++ b/phpgwapi/inc/adodb/datadict/datadict-postgres.inc.php @@ -29,6 +29,9 @@ class ADODB2_postgres extends ADODB_DataDict { $t = $fieldobj->type; $len = $fieldobj->max_length; } + $is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->unique && + $fieldobj->has_default && substr($fieldobj->default_value,0,8) == 'nextval('; + switch (strtoupper($t)) { case 'INTERVAL': case 'CHAR': @@ -61,12 +64,12 @@ class ADODB2_postgres extends ADODB_DataDict { case 'TIMESTAMPTZ': return 'T'; - case 'INTEGER': return (empty($fieldobj->primary_key) && empty($fieldobj->unique))? 'I' : 'R'; + case 'INTEGER': return !$is_serial ? 'I' : 'R'; case 'SMALLINT': - case 'INT2': return (empty($fieldobj->primary_key) && empty($fieldobj->unique))? 'I2' : 'R'; - case 'INT4': return (empty($fieldobj->primary_key) && empty($fieldobj->unique))? 'I4' : 'R'; + case 'INT2': return !$is_serial ? 'I2' : 'R'; + case 'INT4': return !$is_serial ? 'I4' : 'R'; case 'BIGINT': - case 'INT8': return (empty($fieldobj->primary_key) && empty($fieldobj->unique))? 'I8' : 'R'; + case 'INT8': return !$is_serial ? 'I8' : 'R'; case 'OID': case 'SERIAL': diff --git a/phpgwapi/inc/adodb/drivers/adodb-mysql.inc.php b/phpgwapi/inc/adodb/drivers/adodb-mysql.inc.php index 2d42b523cf..b14c5fac77 100644 --- a/phpgwapi/inc/adodb/drivers/adodb-mysql.inc.php +++ b/phpgwapi/inc/adodb/drivers/adodb-mysql.inc.php @@ -392,7 +392,15 @@ class ADODB_mysql extends ADOConnection { // split type into type(length): $fld->scale = null; - if (strpos($type,',') && preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { + if (preg_match('/^enum\((.+)\)$/',$type,$enum_vals)) { // convert enum to varchar + $fld->type = 'varchar'; + $fld->max_length = 1; + $enum_vals = explode(',',$enum_vals[1]); + foreach($enum_vals as $val) + { + if ($fld->max_length < strlen($val)-2) $fld->max_length = strlen($val)-2; + } + } elseif (strpos($type,',') && preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) { $fld->type = $query_array[1]; $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1; $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1; @@ -668,7 +676,7 @@ class ADORecordSet_mysql extends ADORecordSet{ case 'MEDIUMINT': case 'SMALLINT': - if (!empty($fieldobj->primary_key)) return 'R'; + if (is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment) return 'R'; else return 'I'; default: return 'N'; diff --git a/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php b/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php index 17db1d2f37..1b20eb0b61 100644 --- a/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php +++ b/phpgwapi/inc/adodb/drivers/adodb-postgres64.inc.php @@ -443,10 +443,8 @@ select viewname,'V' from pg_views where viewname like $mask"; $num = $rsdef->fields['num']; $s = $rsdef->fields['def']; if (strpos($s,'::')===false && substr($s, 0, 1) == "'") { /* quoted strings hack... for now... fixme */ - $s = substr($s, 1); - $s = substr($s, 0, strlen($s) - 1); + $s = substr($s, 1,-1); } - $rsdefa[$num] = $s; $rsdef->MoveNext(); } @@ -457,14 +455,17 @@ select viewname,'V' from pg_views where viewname like $mask"; } $retarr = array(); - while (!$rs->EOF) { + while (!$rs->EOF) { $fld = new ADOFieldObject(); $fld->name = $rs->fields[0]; $fld->type = $rs->fields[1]; $fld->max_length = $rs->fields[2]; if ($fld->max_length <= 0) $fld->max_length = $rs->fields[3]-4; if ($fld->max_length <= 0) $fld->max_length = -1; - + if ($fld->type == 'numeric') { + $fld->scale = $fld->max_length & 0xFFFF; + $fld->max_length >>= 16; + } // dannym // 5 hasdefault; 6 num-of-column $fld->has_default = ($rs->fields[5] == 't'); @@ -944,8 +945,8 @@ class ADORecordSet_postgres64 extends ADORecordSet{ case 'INT8': case 'INT4': case 'INT2': - if (isset($fieldobj) && - empty($fieldobj->primary_key) && empty($fieldobj->unique)) return 'I'; + if (!is_object($fieldobj) || !$fieldobj->primary_key || !$fieldobj->unique || + !$fieldobj->has_default || substr($fieldobj->default_value,0,8) != 'nextval(') return 'I'; case 'OID': case 'SERIAL': diff --git a/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php b/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php index 9f200bf726..c3e62d8667 100644 --- a/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php +++ b/phpgwapi/inc/adodb/drivers/adodb-sapdb.inc.php @@ -26,8 +26,8 @@ class ADODB_SAPDB extends ADODB_odbc { var $concat_operator = '||'; var $sysDate = 'DATE'; var $sysTimeStamp = 'TIMESTAMP'; - var $fmtDate = "\\D\\A\\T\\E('Y-m-d')"; /// used by DBDate() as the default date format used by the database - var $fmtTimeStamp = "\\T\\I\\M\\E\\S\\T\\A\\M\\P('Y-m-d','H:i:s')"; /// used by DBTimeStamp as the default timestamp fmt. + var $fmtDate = "'Y-m-d'"; /// used by DBDate() as the default date format used by the database + var $fmtTimeStamp = "'Y-m-d H:i:s'"; /// used by DBTimeStamp as the default timestamp fmt. var $hasInsertId = true; var $_bindInputArray = true; @@ -118,6 +118,16 @@ class ADODB_SAPDB extends ADODB_odbc { $fld->has_default = false; } else { $fld->default_value = $column[6]; + switch($fld->type) { + case 'VARCHAR': + case 'CHARACTER': + case 'LONG': + $fld->default_value = $column[6]; + break; + default: + $fld->default_value = trim($column[6]); + break; + } } } $retarr[$fld->name] = $fld;