Created
December 24, 2019 20:50
-
-
Save seamuslee001/18f00226850f3b3293d6ac54b205b286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /home/seamus/DB-1.9.3/DB.php 2018-12-06 07:32:46.000000000 +1100 | |
+++ DB.php 2019-12-25 07:28:48.866726270 +1100 | |
@@ -180,8 +180,22 @@ | |
* Tried to insert a null value into a column that doesn't allow nulls | |
*/ | |
define('DB_ERROR_CONSTRAINT_NOT_NULL',-29); | |
-/**#@-*/ | |
+/** | |
+ * Invalid view or no permissions | |
+ */ | |
+define('DB_ERROR_INVALID_VIEW', -100); | |
+ | |
+/** | |
+ * Database lock timeout exceeded. | |
+ */ | |
+define('DB_ERROR_LOCK_TIMEOUT', -30); | |
+ | |
+/** | |
+ * Database deadlock encountered. | |
+ */ | |
+define('DB_ERROR_DEADLOCK', -31); | |
+/**#@-*/ | |
// }}} | |
// {{{ prepared statement-related | |
@@ -633,7 +647,9 @@ | |
. 'LOAD DATA|SELECT .* INTO .* FROM|COPY|' | |
. 'ALTER|GRANT|REVOKE|' | |
. 'LOCK|UNLOCK'; | |
- if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $query)) { | |
+ // First strip any leading comments | |
+ $queryString = (substr($query, 0, 2) === '/*') ? substr($query, strpos($query, '*/') + 2) : $query; | |
+ if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $queryString)) { | |
return true; | |
} | |
return false; | |
@@ -669,6 +685,7 @@ | |
DB_ERROR_INVALID_DATE => 'invalid date or time', | |
DB_ERROR_INVALID_DSN => 'invalid DSN', | |
DB_ERROR_INVALID_NUMBER => 'invalid number', | |
+ DB_ERROR_INVALID_VIEW => 'invalid view', | |
DB_ERROR_MISMATCH => 'mismatch', | |
DB_ERROR_NEED_MORE_DATA => 'insufficient data supplied', | |
DB_ERROR_NODBSELECTED => 'no database selected', | |
@@ -683,6 +700,8 @@ | |
DB_ERROR_TRUNCATED => 'truncated', | |
DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row', | |
DB_OK => 'no error', | |
+ DB_ERROR_DEADLOCK => 'deadlock', | |
+ DB_ERROR_LOCK_TIMEOUT => 'database lock timeout', | |
); | |
} | |
@@ -733,6 +752,16 @@ | |
*/ | |
public static function parseDSN($dsn) | |
{ | |
+ | |
+ if (defined('DB_DSN_MODE') && DB_DSN_MODE === 'auto') { | |
+ if (extension_loaded('mysqli')) { | |
+ $dsn = preg_replace('/^mysql:/', 'mysqli:', $dsn); | |
+ } | |
+ else { | |
+ $dsn = preg_replace('/^mysqli:/', 'mysql:', $dsn); | |
+ } | |
+ } | |
+ | |
$parsed = array( | |
'phptype' => false, | |
'dbsyntax' => false, | |
--- /home/seamus/DB-1.9.3/DB/common.php 2018-12-06 07:32:46.000000000 +1100 | |
+++ DB/common.php 2019-12-25 07:42:35.573588744 +1100 | |
@@ -1147,7 +1147,20 @@ | |
*/ | |
function modifyQuery($query) | |
{ | |
- return $query; | |
+ // This section of code may run hundreds or thousands of times in a given request. | |
+ // Consequently, it is micro-optimized to use single lookup in typical case. | |
+ if (!isset(Civi::$statics['db_common_dispatcher'])) { | |
+ if (class_exists('Civi\Core\Container') && \Civi\Core\Container::isContainerBooted()) { | |
+ Civi::$statics['db_common_dispatcher'] = Civi\Core\Container::singleton()->get('dispatcher'); | |
+ } | |
+ else { | |
+ return $query; | |
+ } | |
+ } | |
+ | |
+ $e = new \Civi\Core\Event\QueryEvent($query); | |
+ Civi::$statics['db_common_dispatcher']->dispatch('civi.db.query', $e); | |
+ return $e->query; | |
} | |
// }}} | |
@@ -1879,7 +1892,7 @@ | |
* | |
* @see PEAR_Error | |
*/ | |
- function &raiseError($code = DB_ERROR, $mode = null, $options = null, | |
+ function raiseError($code = DB_ERROR, $mode = null, $options = null, | |
$userinfo = null, $nativecode = null, $dummy1 = null, | |
$dummy2 = null) | |
{ | |
@@ -2252,6 +2265,20 @@ | |
} | |
// }}} | |
+ // {{{ lastInsertId() | |
+ | |
+ /** | |
+ * Get the most recently inserted Id | |
+ * | |
+ * @throws RuntimeException | |
+ */ | |
+ function lastInsertId() | |
+ { | |
+ throw new \RuntimeException("Not implemented: " . get_class($this) . '::lastInsertId'); | |
+ } | |
+ | |
+ // }}} | |
+ | |
} | |
/* | |
--- /home/seamus/DB-1.9.3/DB/mysqli.php 2018-12-06 07:32:46.000000000 +1100 | |
+++ DB/mysqli.php 2019-12-25 07:40:57.417018167 +1100 | |
@@ -112,9 +112,12 @@ | |
1136 => DB_ERROR_VALUE_COUNT_ON_ROW, | |
1142 => DB_ERROR_ACCESS_VIOLATION, | |
1146 => DB_ERROR_NOSUCHTABLE, | |
+ 1205 => DB_ERROR_LOCK_TIMEOUT, | |
+ 1213 => DB_ERROR_DEADLOCK, | |
1216 => DB_ERROR_CONSTRAINT, | |
1217 => DB_ERROR_CONSTRAINT, | |
- 1356 => DB_ERROR_DIVZERO, | |
+ 1356 => DB_ERROR_INVALID_VIEW, | |
+ 1365 => DB_ERROR_DIVZERO, | |
1451 => DB_ERROR_CONSTRAINT, | |
1452 => DB_ERROR_CONSTRAINT, | |
); | |
@@ -1087,6 +1090,14 @@ | |
} | |
// }}} | |
+ // {{{ lastInsertId() | |
+ | |
+ function lastInsertId() | |
+ { | |
+ return mysqli_insert_id($this->connection); | |
+ } | |
+ | |
+ // }}} | |
} | |
--- /home/seamus/DB-1.9.3/DB/mysql.php 2018-12-06 07:32:46.000000000 +1100 | |
+++ DB/mysql.php 2019-12-25 07:41:04.761056985 +1100 | |
@@ -109,9 +109,12 @@ | |
1136 => DB_ERROR_VALUE_COUNT_ON_ROW, | |
1142 => DB_ERROR_ACCESS_VIOLATION, | |
1146 => DB_ERROR_NOSUCHTABLE, | |
+ 1205 => DB_ERROR_LOCK_TIMEOUT, | |
+ 1213 => DB_ERROR_DEADLOCK, | |
1216 => DB_ERROR_CONSTRAINT, | |
1217 => DB_ERROR_CONSTRAINT, | |
- 1356 => DB_ERROR_DIVZERO, | |
+ 1356 => DB_ERROR_INVALID_VIEW, | |
+ 1365 => DB_ERROR_DIVZERO, | |
1451 => DB_ERROR_CONSTRAINT, | |
1452 => DB_ERROR_CONSTRAINT, | |
); | |
@@ -1021,6 +1024,14 @@ | |
} | |
// }}} | |
+ // {{{ lastInsertId() | |
+ | |
+ function lastInsertId() | |
+ { | |
+ return mysql_insert_id($this->connection); | |
+ } | |
+ | |
+ // }}} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment