Changeset 901 for trunk/Packages/Common/Database.php
- Timestamp:
- Feb 17, 2021, 9:27:32 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Database.php
r900 r901 49 49 { 50 50 $this->Prefix = ''; 51 $this->Functions = array('NOW( )', 'CURDATE()', 'CURTIME()', 'UUID()');51 $this->Functions = array('NOW(', 'CURDATE(', 'CURTIME(', 'UUID(', 'SHA1('); 52 52 $this->Type = 'mysql'; // mysql, pgsql 53 53 $this->Error = ''; … … 141 141 } 142 142 143 function IsFunction(string $Text): bool 144 { 145 $Pos = strpos($Text, '('); 146 return ($Pos !== false) && in_array(substr($Text, 0, $Pos + 1), $this->Functions); 147 } 148 143 149 function GetInsert(string $Table, array $Data): string 144 150 { … … 148 154 { 149 155 $Name .= ',`'.$Key.'`'; 150 if (!in_array($Value, $this->Functions)) 156 if (is_null($Value)) $Value = 'NULL'; 157 else if (!$this->IsFunction($Value)) 151 158 { 152 if (is_null($Value)) $Value = 'NULL'; 153 else $Value = $this->PDO->quote($Value); 159 $Value = $this->PDO->quote($Value); 154 160 } 155 161 $Values .= ','.$Value; … … 170 176 foreach ($Data as $Key => $Value) 171 177 { 172 if (!in_array($Value, $this->Functions)) 178 if (is_null($Value)) $Value = 'NULL'; 179 else if (!$this->IsFunction($Value)) 173 180 { 174 if (is_null($Value)) $Value = 'NULL'; 175 else $Value = $this->PDO->quote($Value); 181 $Value = $this->PDO->quote($Value); 176 182 } 177 183 $Values .= ', `'.$Key.'`='.$Value; … … 187 193 foreach ($Data as $Key => $Value) 188 194 { 189 if (!in_array($Value, $this->Functions)) 195 if (is_null($Value)) $Value = 'NULL'; 196 else if (!$this->IsFunction($Value)) 190 197 { 191 if (is_null($Value)) $Value = 'NULL'; 192 else $Value = $this->PDO->quote($Value); 198 $Value = $this->PDO->quote($Value); 193 199 } 194 200 $Name .= ',`'.$Key.'`';
Note:
See TracChangeset
for help on using the changeset viewer.