diff options
| author | Damien Regad <dregad@mantisbt.org> | 2025-11-22 15:42:02 +0100 |
|---|---|---|
| committer | Damien Regad <dregad@mantisbt.org> | 2025-11-22 15:55:32 +0100 |
| commit | 7441699b9c2fde0ade85c23acb1f519f6b54fbf3 (patch) | |
| tree | 37b1036ffdae2c683cd71fc02f764b18ca172191 | |
| parent | f44e474d39ec24f6b0cb0a5d656bb371ce7acd12 (diff) | |
| parent | c6f8078b252084b17094e7183b7cea290d8ea960 (diff) | |
| download | adodb-7441699b9c2fde0ade85c23acb1f519f6b54fbf3.tar.gz adodb-7441699b9c2fde0ade85c23acb1f519f6b54fbf3.tar.bz2 adodb-7441699b9c2fde0ade85c23acb1f519f6b54fbf3.zip | |
PR #1074: ActiveRecord doQuote and follow-up fixes
| -rw-r--r-- | adodb-active-record.inc.php | 76 | ||||
| -rw-r--r-- | adodb-active-recordx.inc.php | 54 |
2 files changed, 62 insertions, 68 deletions
diff --git a/adodb-active-record.inc.php b/adodb-active-record.inc.php index 08f7ca8d..ea1d4ed3 100644 --- a/adodb-active-record.inc.php +++ b/adodb-active-record.inc.php @@ -717,35 +717,36 @@ class ADODB_Active_Record { } // quote data in where clause - function doquote(&$db, $val,$t) + function doQuote($db, $val, $t) { - switch($t) { - case 'L': - if (strpos($db->databaseType,'postgres') !== false) { - return $db->qstr($val); - } - case 'D': - case 'T': - if (empty($val)) { - return 'null'; - } - case 'B': - case 'N': - case 'C': - case 'X': - if (is_null($val)) { - return 'null'; - } - - if (strlen($val)>0 && - (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'") - ) { - return $db->qstr($val); - break; - } - default: - return $val; - break; + switch ($t) { + /** @noinspection PhpMissingBreakStatementInspection */ + case 'L': + if (strpos($db->databaseType, 'postgres') !== false) { + return $db->qstr($val); + } + case 'D': + /** @noinspection PhpMissingBreakStatementInspection */ + case 'T': + if (empty($val)) { + return 'null'; + } + case 'B': + case 'N': + case 'C': + /** @noinspection PhpMissingBreakStatementInspection */ + case 'X': + if (is_null($val)) { + return 'null'; + } + if ('' === (string)$val) { + return "''"; + } + if (substr($val, 0, 1) != "'" || substr($val,-1) != "'") { + return $db->qstr($val); + } + default: + return $val; } } @@ -759,27 +760,12 @@ class ADODB_Active_Record { $f = $table->flds[$k]; if ($f) { $columnName = $this->nameQuoter($db,$k); - $parr[] = $columnName.' = '.$this->doquote($db,$this->$k,$db->MetaType($f->type)); + $parr[] = $columnName . ' = ' . $this->doQuote($db, $this->$k, $db->MetaType($f->type)); } } return implode(' AND ', $parr); } - - function _QName($n,$db=false) - { - if (!ADODB_Active_Record::$_quoteNames) { - return $n; - } - if (!$db) { - $db = $this->DB(); - if (!$db) { - return false; - } - } - return $db->nameQuote.$n.$db->nameQuote; - } - //------------------------------------------------------------ Public functions below function Load($where=null,$bindarr=false, $lock = false) @@ -983,7 +969,7 @@ class ADODB_Active_Record { } $t = $db->MetaType($fld->type); - $arr[$name] = $this->doquote($db,$val,$t); + $arr[$name] = $this->doQuote($db, $val, $t); $valarr[] = $val; } diff --git a/adodb-active-recordx.inc.php b/adodb-active-recordx.inc.php index 18e2a189..789c9930 100644 --- a/adodb-active-recordx.inc.php +++ b/adodb-active-recordx.inc.php @@ -762,28 +762,36 @@ class ADODB_Active_Record { } // quote data in where clause - function doquote(&$db, $val,$t) + function doQuote($db, $val, $t) { - switch($t) { - case 'D': - case 'T': - if (empty($val)) { - return 'null'; - } - case 'C': - case 'X': - if (is_null($val)) { - return 'null'; - } - if (strlen($val)>0 && - (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'") - ) { - return $db->qstr($val); - break; - } - default: - return $val; - break; + switch ($t) { + /** @noinspection PhpMissingBreakStatementInspection */ + case 'L': + if (strpos($db->databaseType, 'postgres') !== false) { + return $db->qstr($val); + } + case 'D': + /** @noinspection PhpMissingBreakStatementInspection */ + case 'T': + if (empty($val)) { + return 'null'; + } + case 'B': + case 'N': + case 'C': + /** @noinspection PhpMissingBreakStatementInspection */ + case 'X': + if (is_null($val)) { + return 'null'; + } + if ('' === (string)$val) { + return "''"; + } + if (substr($val, 0, 1) != "'" || substr($val,-1) != "'") { + return $db->qstr($val); + } + default: + return $val; } } @@ -796,7 +804,7 @@ class ADODB_Active_Record { foreach($keys as $k) { $f = $table->flds[$k]; if ($f) { - $parr[] = $k.' = '.$this->doquote($db,$this->$k,$db->MetaType($f->type)); + $parr[] = $k . ' = ' . $this->doQuote($db, $this->$k, $db->MetaType($f->type)); } } return implode(' and ', $parr); @@ -1081,7 +1089,7 @@ class ADODB_Active_Record { continue; } $t = $db->MetaType($fld->type); - $arr[$name] = $this->doquote($db,$val,$t); + $arr[$name] = $this->doQuote($db, $val, $t); $valarr[] = $val; } |
