|
@@ -37,7 +37,8 @@ class Core_Pdo extends PDO {
|
|
|
|
|
|
|
|
public function identifierQuote($identifier) {
|
|
public function identifierQuote($identifier) {
|
|
|
switch (strtolower($this->_type)) {
|
|
switch (strtolower($this->_type)) {
|
|
|
- case 'pgsql': return $identifier; // "'{$identifier}'";
|
|
|
|
|
|
|
+ // case 'pgsql': return $identifier;
|
|
|
|
|
+ case 'pgsql': return "\"{$identifier}\""; // https://www.postgresql.org/docs/9.1/sql-syntax-lexical.html
|
|
|
case 'mysql': return "`{$identifier}`";
|
|
case 'mysql': return "`{$identifier}`";
|
|
|
}
|
|
}
|
|
|
return $identifier;
|
|
return $identifier;
|
|
@@ -659,19 +660,33 @@ EOF_STRUCT_MYSQL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function execSql($sql, $values = []) {
|
|
public function execSql($sql, $values = []) {
|
|
|
- if (empty($values)) {
|
|
|
|
|
- DBG::log($sql, 'sql');
|
|
|
|
|
- return $this->exec($sql);
|
|
|
|
|
- }
|
|
|
|
|
- $sth = $this->prepare($sql);
|
|
|
|
|
- if (!empty($values)) {
|
|
|
|
|
- $this->bindValues($sth, $values);
|
|
|
|
|
- DBG::log($this->getRawSql($sth), 'sql');
|
|
|
|
|
- } else {
|
|
|
|
|
- DBG::log($sql, 'sql');
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (empty($values)) {
|
|
|
|
|
+ DBG::log($sql, 'sql');
|
|
|
|
|
+ $retAffected = $this->exec($sql);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $sth = $this->prepare($sql);
|
|
|
|
|
+ if (!empty($values)) {
|
|
|
|
|
+ $this->bindValues($sth, $values);
|
|
|
|
|
+ DBG::log($this->getRawSql($sth), 'sql');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DBG::log($sql, 'sql');
|
|
|
|
|
+ }
|
|
|
|
|
+ $sth->execute();
|
|
|
|
|
+ $retAffected = $sth->rowCount();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception $e) {
|
|
|
|
|
+ DBG::log($e);
|
|
|
|
|
+ $dbType = $this->getType();
|
|
|
|
|
+ $duplicateRegexp = "/SQLSTATE\[23000\]\: Integrity constraint violation: 1062 Duplicate entry '([0-9]+)' for key '(.*)'/";
|
|
|
|
|
+ if ('mysql' == $dbType && false !== preg_match_all($duplicateRegexp, $e->getMessage(), $matches)) {
|
|
|
|
|
+ DBG::nicePrint($matches, '$matches duplicate test');
|
|
|
|
|
+ throw new MysqlDuplicateEntryException("Duplicate entry '{$matches[1][0]}'", 1062, null, $matches[1][0], $matches[2][0]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw $e;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- $sth->execute();
|
|
|
|
|
- return $sth->rowCount();
|
|
|
|
|
|
|
+ return $retAffected;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getBlob($tableName, $fieldName, $pkField, $primaryKey) {
|
|
public function getBlob($tableName, $fieldName, $pkField, $primaryKey) {
|
|
@@ -707,3 +722,13 @@ EOF_STRUCT_MYSQL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class MysqlDuplicateEntryException extends DatabaseDuplicateEntryException {}
|
|
|
|
|
+class DatabaseDuplicateEntryException extends Exception {
|
|
|
|
|
+ public function __construct($message, $code = 0, Exception $previous = null, $sqlPrimaryKey = '', $sqlKeyName = '') {
|
|
|
|
|
+ $this->keyName = $sqlKeyName;
|
|
|
|
|
+ $this->primaryKey = $sqlPrimaryKey;
|
|
|
|
|
+ parent::__construct($message, $code, $previous);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|