diff options
| author | Damien Regad <dregad@mantisbt.org> | 2021-08-17 01:08:57 +0200 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2021-08-17 01:08:57 +0200 |
| commit | 2595a935bc272a451595d27939ba4aaddc4ee68e (patch) | |
| tree | d5455991ea11e61648ccefb352ebd6a3eb6ccd21 /adodb-active-record.inc.php | |
| parent | d558d101c514beeb8c91f65ae61d106b201dc472 (diff) | |
| download | adodb-2595a935bc272a451595d27939ba4aaddc4ee68e.tar.gz adodb-2595a935bc272a451595d27939ba4aaddc4ee68e.tar.bz2 adodb-2595a935bc272a451595d27939ba4aaddc4ee68e.zip | |
Redo Merge tag 'v5.21.1'
# Conflicts:
# adodb.inc.php
# docs/changelog.md
# drivers/adodb-mssqlnative.inc.php
# drivers/adodb-mysqli.inc.php
Fixes #751
Diffstat (limited to 'adodb-active-record.inc.php')
| -rw-r--r-- | adodb-active-record.inc.php | 105 |
1 files changed, 38 insertions, 67 deletions
diff --git a/adodb-active-record.inc.php b/adodb-active-record.inc.php index 3c418bf8..8f3b0053 100644 --- a/adodb-active-record.inc.php +++ b/adodb-active-record.inc.php @@ -19,6 +19,8 @@ * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community */ +include_once(ADODB_DIR.'/adodb-lib.inc.php'); + global $_ADODB_ACTIVE_DBS; global $ADODB_ACTIVE_CACHESECS; // set to true to enable caching of metadata such as field info global $ACTIVE_RECORD_SAFETY; // set to false to disable safety checks @@ -74,10 +76,9 @@ function ADODB_SetDatabaseAdapter(&$db, $index=false) class ADODB_Active_Record { static $_changeNames = true; // dynamically pluralize table names - /* - * Optional parameter that duplicates the ADODB_QUOTE_FIELDNAMES - */ - static $_quoteNames = false; + + /** @var bool|string Allows override of global $ADODB_QUOTE_FIELDNAMES */ + public $_quoteNames; static $_foreignSuffix = '_id'; // var $_dbat; // associative index pointing to ADODB_Active_DB eg. $ADODB_Active_DBS[_dbat] @@ -117,7 +118,12 @@ class ADODB_Active_Record { // php5 constructor function __construct($table = false, $pkeyarr=false, $db=false) { - global $_ADODB_ACTIVE_DBS; + global $_ADODB_ACTIVE_DBS, $ADODB_QUOTE_FIELDNAMES; + + // Set the local override for field quoting, only if not defined yet + if (!isset($this->_quoteNames)) { + $this->_quoteNames = $ADODB_QUOTE_FIELDNAMES; + } if ($db == false && is_object($pkeyarr)) { $db = $pkeyarr; @@ -880,7 +886,7 @@ class ADODB_Active_Record { $cnt += 1; } } - + $tableName = $this->nameQuoter($db,$this->_table); $sql = sprintf('INSERT INTO %s (%s) VALUES (%s)', $tableName, @@ -919,7 +925,7 @@ class ADODB_Active_Record { $where = $this->GenWhere($db,$table); $tableName = $this->nameQuoter($db,$this->_table); - + $sql = sprintf('DELETE FROM %s WHERE %s', $tableName, $where @@ -995,19 +1001,19 @@ class ADODB_Active_Record { } break; } - + $newArr = array(); foreach($arr as $k=>$v) $newArr[$this->nameQuoter($db,$k)] = $v; $arr = $newArr; - + $newPkey = array(); foreach($pkey as $k=>$v) $newPkey[$k] = $this->nameQuoter($db,$v); $pkey = $newPkey; - + $tableName = $this->nameQuoter($db,$this->_table); - + $ok = $db->Replace($tableName,$arr,$pkey); if ($ok) { $this->_saved = true; // 1= update 2=insert @@ -1095,7 +1101,7 @@ class ADODB_Active_Record { $tableName, implode(',',$pairs), $where); - + $ok = $db->Execute($sql,$valarr); if ($ok) { $this->_original = $neworig; @@ -1114,62 +1120,27 @@ class ADODB_Active_Record { } /** - * Quotes the table and column and field names - * - * this honours the ADODB_QUOTE_FIELDNAMES directive. The routines that - * use it should really just call _adodb_getinsertsql and _adodb_getupdatesql - * which is a nice easy project if you are interested - * - * @param obj $db The database connection - * @param string $name The table or column name to quote - * - * @return string The quoted name - */ - private function nameQuoter($db,$string) + * Quotes the table, column and field names. + * + * This honours the internal {@see $_quoteNames} property, which overrides + * the global $ADODB_QUOTE_FIELDNAMES directive. + * + * @param ADOConnection $db The database connection + * @param string $name The table or column name to quote + * + * @return string The quoted name + */ + private function nameQuoter($db, $name) { global $ADODB_QUOTE_FIELDNAMES; - - if (!$ADODB_QUOTE_FIELDNAMES && !$this->_quoteNames) - /* - * Nothing to be done - */ - return $string; - - if ($this->_quoteNames == 'NONE') - /* - * Force no quoting when ADODB_QUOTE_FIELDNAMES is set - */ - return $string; - - if ($this->_quoteNames) - /* - * Internal setting takes precedence - */ - $quoteMethod = $this->_quoteNames; - - else - $quoteMethod = $ADODB_QUOTE_FIELDNAMES; - - switch ($quoteMethod) - { - case 'LOWER': - $string = strtolower($string); - break; - case 'NATIVE': - /* - * Nothing to be done - */ - break; - case 'UPPER': - default: - $string = strtoupper($string); - } - - $string = sprintf( '%s%s%s', - $db->nameQuote, - $string, - $db->nameQuote - ); + + $save = $ADODB_QUOTE_FIELDNAMES; + $ADODB_QUOTE_FIELDNAMES = $this->_quoteNames; + + $string = _adodb_quote_fieldname($db, $name); + + $ADODB_QUOTE_FIELDNAMES = $save; + return $string; } @@ -1182,7 +1153,7 @@ global $_ADODB_ACTIVE_DBS; $save = $db->SetFetchMode(ADODB_FETCH_NUM); - + $qry = "select * from ".$table; if (!empty($whereOrderBy)) { |
