- new capability 'name_case'

- docu update
- removed some depricated stuff from the last release
This commit is contained in:
Ralf Becker 2005-11-20 15:40:28 +00:00
parent 5ad806fdb7
commit 9320913b9e
2 changed files with 93 additions and 107 deletions

View File

@ -73,11 +73,6 @@
*/ */
var $Password = ''; var $Password = '';
/**
* @var bool $auto_stripslashes automatically remove slashes when returning field values - default False
*/
var $auto_stripslashes = False;
/** /**
* @var int $Auto_Free automatically free results - 0 no, 1 yes * @var int $Auto_Free automatically free results - 0 no, 1 yes
*/ */
@ -93,11 +88,6 @@
*/ */
var $Halt_On_Error = 'yes'; var $Halt_On_Error = 'yes';
/**
* @var string $Seq_Table table for storing sequences ????
*/
var $Seq_Table = 'db_sequence';
/** /**
* @var array $Record current record * @var array $Record current record
*/ */
@ -132,6 +122,7 @@
'sub_queries' => true, // will be set to false for mysql < 4.1 'sub_queries' => true, // will be set to false for mysql < 4.1
'distinct_on_text' => true, // is the DB able to use DISTINCT with a text or blob column 'distinct_on_text' => true, // is the DB able to use DISTINCT with a text or blob column
'like_on_text' => true, // is the DB able to use LIKE with text columns 'like_on_text' => true, // is the DB able to use LIKE with text columns
'name_case' => 'upper', // case of returned column- and table-names: upper, lower(pgSql), preserv(MySQL)
'order_on_text' => true, // is the DB able to order by a given text column, boolean or 'order_on_text' => true, // is the DB able to order by a given text column, boolean or
); // string for sprintf for a cast (eg. 'CAST(%s AS varchar)') ); // string for sprintf for a cast (eg. 'CAST(%s AS varchar)')
@ -335,10 +326,16 @@
switch($adodb_driver) switch($adodb_driver)
{ {
case 'mysql': case 'mysql':
case 'mysqlt':
case 'mysqli': case 'mysqli':
$this->capabilities['sub_queries'] = (float) $db_version >= 4.1; $this->capabilities['sub_queries'] = (float) $db_version >= 4.1;
$this->capabilities['name_case'] = 'preserv';
break; break;
case 'postgres':
$this->capabilities['name_case'] = 'lower';
break;
case 'mssql': case 'mssql':
$this->capabilities['distinct_on_text'] = false; $this->capabilities['distinct_on_text'] = false;
$this->capabilities['order_on_text'] = 'CAST (%s AS varchar)'; $this->capabilities['order_on_text'] = 'CAST (%s AS varchar)';
@ -370,6 +367,7 @@
/** /**
* Escape strings before sending them to the database * Escape strings before sending them to the database
* *
* @deprecated use quote($value,$type='') instead
* @param string $str the string to be escaped * @param string $str the string to be escaped
* @return string escaped sting * @return string escaped sting
*/ */
@ -416,6 +414,17 @@
} }
return $this->Link_ID->UnixTimeStamp($timestamp); return $this->Link_ID->UnixTimeStamp($timestamp);
} }
/**
* convert a rdbms specific boolean value
*
* @param string $val boolean value in db-specfic notation
* @return boolean
*/
function from_bool($val)
{
return $val && $val{0} !== 'f'; // everthing other then 0 or f[alse] is returned as true
}
/** /**
* Discard the current query result * Discard the current query result
@ -529,45 +538,24 @@
{ {
return False; return False;
} }
switch ($this->Type) if ($this->capabilities['name_case'] == 'upper') // maxdb, oracle, ...
{ {
case 'sapdb': switch($fetch_mode)
case 'maxdb': {
case 'oracle': case ADODB_FETCH_ASSOC:
foreach($this->Record as $column => $value) $this->Record = array_change_key_case($this->Record);
{ break;
// add a lowercase version case ADODB_FETCH_NUM:
$this->Record[strtolower($column)] = $value; $this->Record = array_values($this->Record);
// add a numeric version break;
$this->Record[] = $value; default:
} $this->Record = array_change_key_case($this->Record);
if (!function_exists('array_change_key_case')) if (!isset($this->Record[0]))
{
define('CASE_LOWER',0);
define('CASE_UPPER',1);
function array_change_key_case($arr,$mode=CASE_LOWER)
{ {
foreach($arr as $key => $val)
{
$changed[$mode == CASE_LOWER ? strtolower($key) : strtoupper($key)] = $val;
}
return $changed;
}
}
switch($fetch_mode)
{
case ADODB_FETCH_ASSOC:
$this->Record = array_change_key_case($this->Record);
break;
case ADODB_FETCH_NUM:
$this->Record = array_values($this->Record);
break;
default:
$this->Record = array_change_key_case($this->Record);
$this->Record += array_values($this->Record); $this->Record += array_values($this->Record);
break; }
} break;
break; }
} }
return True; return True;
} }
@ -662,6 +650,7 @@
/** /**
* Lock a table * Lock a table
* *
* @deprecated not used anymore as it costs to much performance, use transactions if needed
* @param string $table name of table to lock * @param string $table name of table to lock
* @param string $mode type of lock required (optional), default write * @param string $mode type of lock required (optional), default write
* @return bool True if sucessful, False if fails * @return bool True if sucessful, False if fails
@ -672,13 +661,14 @@
/** /**
* Unlock a table * Unlock a table
* *
* @deprecated not used anymore as it costs to much performance, use transactions if needed
* @return bool True if sucessful, False if fails * @return bool True if sucessful, False if fails
*/ */
function unlock() function unlock()
{} {}
/** /**
* Get the number of rows affected by last update * Get the number of rows affected by last update or delete
* *
* @return int number of rows * @return int number of rows
*/ */
@ -712,7 +702,7 @@
} }
/** /**
* short hand for @see num_rows() * @deprecated use num_rows()
*/ */
function nf() function nf()
{ {
@ -720,7 +710,7 @@
} }
/** /**
* short hand for print @see num_rows * @deprecated use print num_rows()
*/ */
function np() function np()
{ {
@ -732,18 +722,16 @@
* *
* @param string/integer $Name name of field or positional index starting from 0 * @param string/integer $Name name of field or positional index starting from 0
* @param bool $strip_slashes string escape chars from field(optional), default false * @param bool $strip_slashes string escape chars from field(optional), default false
* depricated param, as correctly quoted values dont need any stripslashes!
* @return string the field value * @return string the field value
*/ */
function f($Name, $strip_slashes = False) function f($Name, $strip_slashes = False)
{ {
if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes)) if ($strip_slashes)
{ {
return stripslashes($this->Record[$Name]); return stripslashes($this->Record[$Name]);
} }
else return $this->Record[$Name];
{
return $this->Record[$Name];
}
} }
/** /**
@ -751,6 +739,7 @@
* *
* @param string $Name name of field to print * @param string $Name name of field to print
* @param bool $strip_slashes string escape chars from field(optional), default false * @param bool $strip_slashes string escape chars from field(optional), default false
* depricated param, as correctly quoted values dont need any stripslashes!
*/ */
function p($Name, $strip_slashes = True) function p($Name, $strip_slashes = True)
{ {
@ -761,7 +750,7 @@
* Returns a query-result-row as an associative array (no numerical keys !!!) * Returns a query-result-row as an associative array (no numerical keys !!!)
* *
* @param bool $do_next_record should next_record() be called or not (default not) * @param bool $do_next_record should next_record() be called or not (default not)
* @param string $strip string to strip of the column-name, default '' * @param string $strip='' string to strip of the column-name, default ''
* @return array/bool the associative array or False if no (more) result-row is availible * @return array/bool the associative array or False if no (more) result-row is availible
*/ */
function row($do_next_record=False,$strip='') function row($do_next_record=False,$strip='')
@ -783,19 +772,6 @@
return $result; return $result;
} }
/**
* Get the id for the next sequence - not implemented!
*
* This seems not to be used anywhere in eGroupWhere !!!
*
* @param string $seq_name name of the sequence
* @return int sequence id
*/
function nextid($seq_name)
{
echo "<p>db::nextid(sequence='$seq_name') not yet implemented</p>\n";
}
/** /**
* Error handler * Error handler
* *
@ -925,13 +901,9 @@
{ {
foreach($tables as $table) foreach($tables as $table)
{ {
switch ($this->Type) if ($this->capabilities['name_case'] == 'upper')
{ {
case 'sapdb': $table = strtolower($table);
case 'maxdb':
case 'oracle':
$table = strtolower($table);
break;
} }
$result[] = array( $result[] = array(
'table_name' => $table, 'table_name' => $table,
@ -1481,8 +1453,8 @@
* The function has a variable number of arguments, from which the expession gets constructed * The function has a variable number of arguments, from which the expession gets constructed
* eg. db::expression('my_table','(',array('name'=>"test'ed",'lang'=>'en'),') OR ',array('owner'=>array('',4,10))) * eg. db::expression('my_table','(',array('name'=>"test'ed",'lang'=>'en'),') OR ',array('owner'=>array('',4,10)))
* gives "(name='test\'ed' AND lang='en') OR 'owner' IN (0,4,5,6,10)" if name,lang are strings and owner is an integer * gives "(name='test\'ed' AND lang='en') OR 'owner' IN (0,4,5,6,10)" if name,lang are strings and owner is an integer
* @param $table string name of the table * @param string $table name of the table
* @param $args mixed variable number of arguments of the following types: * @param mixed $args variable number of arguments of the following types:
* string: get's as is into the result * string: get's as is into the result
* array: column-name / value pairs: the value gets quoted according to the type of the column and prefixed * array: column-name / value pairs: the value gets quoted according to the type of the column and prefixed
* with column-name=, multiple pairs are AND'ed together, see db::column_data_implode * with column-name=, multiple pairs are AND'ed together, see db::column_data_implode
@ -1491,7 +1463,7 @@
*/ */
function expression($table,$args) function expression($table,$args)
{ {
$table_def = $this->get_table_definitions($app,$table); $table_def = $this->get_table_definitions('',$table);
$sql = ''; $sql = '';
$ignore_next = 0; $ignore_next = 0;
foreach(func_get_args() as $n => $arg) foreach(func_get_args() as $n => $arg)

View File

@ -27,18 +27,49 @@
*/ */
class schema_proc class schema_proc
{ {
/**
* @deprecated formerly used translator class, now a reference to ourself
*/
var $m_oTranslator; var $m_oTranslator;
/**
* @var egw_db-object $m_odb db-object
*/
var $m_odb; var $m_odb;
var $m_bDeltaOnly; /**
var $debug = 0; // 0=Off, 1=some, eg. primary function calls, 2=lots incl. the SQL used * @var adodb-object $adodb reference to the global ADOdb object
var $max_index_length=array( // if known */
var $adodb;
/**
* @var datadictionary-object $dict adodb's datadictionary object for the used db-type
*/
var $dict;
/**
* @var $debug=0 0=Off, 1=some, eg. primary function calls, 2=lots incl. the SQL used
*/
var $debug = 0;
/**
* @var array $max_index_length db => max. length of indexes pairs (if there is a considerable low limit for a db)
*/
var $max_index_length=array(
'sapdb' => 32, 'sapdb' => 32,
'oracle' => 30, 'oracle' => 30,
); );
var $sType; // type of the database, set by the the constructor /**
var $max_varchar_length = 255; // maximum length of a varchar column, everything above get converted to text * @var string $sType type of the database, set by the the constructor
*/
var $sType;
/**
* @var int $max_varchar_length maximum length of a varchar column, everything above get converted to text
*/
var $max_varchar_length = 255;
/**
* @var string $system_charset system-charset if set
*/
var $system_charset; var $system_charset;
/**
* @var array $capabilities reference to the array of the db-class
*/
var $capabilities;
/** /**
* Constructor of schema-processor * Constructor of schema-processor
@ -49,6 +80,7 @@
{ {
$this->m_odb = is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db; $this->m_odb = is_object($GLOBALS['egw']->db) ? $GLOBALS['egw']->db : $GLOBALS['egw_setup']->db;
$this->m_odb->connect(); $this->m_odb->connect();
$this->capabilities =& $this->m_odb->capabilities;
$this->sType = $dbms ? $dmbs : $this->m_odb->Type; $this->sType = $dbms ? $dmbs : $this->m_odb->Type;
@ -929,7 +961,7 @@
} }
if (isset($col_data['default'])) if (isset($col_data['default']))
{ {
$ado_col .= " DEFAULT '$col_data[default]'"; $ado_col .= ' DEFAULT '.$this->m_odb->quote($col_data['default'],$col_data['type']);
} }
if (in_array($col,$aTableDef['pk'])) if (in_array($col,$aTableDef['pk']))
{ {
@ -984,17 +1016,7 @@
//echo "$sTableName: <pre>".print_r($columns,true)."</pre>"; //echo "$sTableName: <pre>".print_r($columns,true)."</pre>";
foreach($columns as $column) foreach($columns as $column)
{ {
switch($this->sType) $name = $this->capabilities['name_case'] == 'upper' ? strtolower($column->name) : $column->name;
{
case 'sapdb':
case 'maxdb':
case 'oracle':
$name = strtolower($column->name);
break;
default:
$name = $column->name;
break;
}
$type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type); $type = method_exists($this->dict,'MetaType') ? $this->dict->MetaType($column) : strtoupper($column->type);
@ -1108,13 +1130,9 @@
if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') && if (!count($definition['pk']) && method_exists($this->dict,'MetaPrimaryKeys') &&
is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary)) is_array($primary = $this->dict->MetaPrimaryKeys($sTableName)) && count($primary))
{ {
switch($this->sType) if($this->capabilities['name_case'] == 'upper')
{ {
case 'sapdb': array_walk($primary,create_function('&$s','$s = strtolower($s);'));
case 'maxdb':
case 'oracle':
array_walk($primary,create_function('&$s','$s = strtolower($s);'));
break;
} }
$definition['pk'] = $primary; $definition['pk'] = $primary;
} }
@ -1125,13 +1143,9 @@
{ {
foreach($indexes as $index) foreach($indexes as $index)
{ {
switch($this->sType) if($this->capabilities['name_case'] == 'upper')
{ {
case 'sapdb': array_walk($index['columns'],create_function('&$s','$s = strtolower($s);'));
case 'maxdb':
case 'oracle':
array_walk($index['columns'],create_function('&$s','$s = strtolower($s);'));
break;
} }
if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) || if (count($definition['pk']) && (implode(':',$definition['pk']) == implode(':',$index['columns']) ||
$index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk']))) $index['unique'] && count(array_intersect($definition['pk'],$index['columns'])) == count($definition['pk'])))