|
|
@@ -7,12 +7,14 @@ class Core_Pdo extends PDO {
|
|
|
protected $_database_name;
|
|
|
protected $_zasob_id;
|
|
|
protected $_type;
|
|
|
+ protected $_schema;
|
|
|
|
|
|
// public PDO::__construct ( string $dsn [, string $username [, string $password [, array $options ]]] )
|
|
|
public function __construct($dsn, $username, $password, $options = array()) {
|
|
|
$this->_database_name = $options['database'];
|
|
|
$this->_zasob_id = $options['zasob_id'];
|
|
|
$this->_type = $options['type'];
|
|
|
+ $this->_schema = (!empty($options['schema'])) ? $options['schema'] : null;
|
|
|
unset($options['database']);
|
|
|
unset($options['zasob_id']);
|
|
|
parent::__construct($dsn, $username, $password, $options);
|
|
|
@@ -40,6 +42,14 @@ class Core_Pdo extends PDO {
|
|
|
return $identifier;
|
|
|
}
|
|
|
|
|
|
+ public function tableNameQuote($tableName) {
|
|
|
+ switch (strtolower($this->_type)) {
|
|
|
+ case 'pgsql': return ($this->_schema) ? "{$this->_schema}.{$tableName}" : $tableName; // "'{$identifier}'";
|
|
|
+ case 'mysql': return "`{$tableName}`";
|
|
|
+ }
|
|
|
+ return $tableName;
|
|
|
+ }
|
|
|
+
|
|
|
public function getTableStruct($tblName) {// TODO: mved to Core_Storage_*
|
|
|
$sth = $this->prepare("
|
|
|
-- show fields from {$tblName}
|
|
|
@@ -561,12 +571,14 @@ EOF_STRUCT_MYSQL;
|
|
|
$sqlPrimaryKey = $this->quote($primaryKey, PDO::PARAM_STR);
|
|
|
$sqlUpdateSet = [];
|
|
|
foreach ($item as $field => $val) {
|
|
|
- $sqlUpdateSet[] = "`{$field}` = " . $this->convertValueToSqlSafe($val, V::get($field, null, $sqlSchema));
|
|
|
+ $sqlUpdateSet[] = $this->identifierQuote($field) . " = " . $this->convertValueToSqlSafe($val, V::get($field, null, $sqlSchema));
|
|
|
}
|
|
|
+ $sqlTableName = $this->identifierQuote($tableName);
|
|
|
+ $sqlPkName = $this->identifierQuote($primaryKeyName);
|
|
|
$sql = "
|
|
|
- update `{$tableName}`
|
|
|
+ update {$sqlTableName}
|
|
|
set " . implode("\n , ", $sqlUpdateSet) . "
|
|
|
- where `{$primaryKeyName}` = {$sqlPrimaryKey}
|
|
|
+ where {$sqlPkName} = {$sqlPrimaryKey}
|
|
|
";
|
|
|
return $this->execSql($sql);
|
|
|
}
|