Attached Files |
db_class_for_large_data_set_512.patch [^] (3,003 bytes) 2011-10-17 08:31
[Show Content]
Index: db_connection.php
===================================================================
--- db_connection.php (revision 155)
+++ db_connection.php (working copy)
@@ -258,7 +258,7 @@
$func = $this->getMetaFunction('error');
$this->errorMessage = $this->connectionID ? $func($this->connectionID) : $func();
$error_msg = 'Database connection failed, please check your connection settings.<br/>Error (' . $this->errorCode . '): ' . $this->errorMessage;
-
+
trigger_error($error_msg, defined('IS_INSTALL') && IS_INSTALL ? E_USER_WARNING : E_USER_ERROR);
}
@@ -475,6 +475,93 @@
return false;
}
+ /**
+ * Retrieves data from database and return resource id on success or false otherwise
+ *
+ * @param string $select_sql
+ * @param string $key_field
+ * @return resource
+ * @see kDBConnection::GetNextRow
+ */
+ function QueryRaw($select_sql)
+ {
+ $this->lastQuery = $select_sql;
+ $this->_queryCount++;
+
+ $query_func = $this->getMetaFunction('query');
+
+ // set 1st checkpoint: begin
+ if ($this->_captureStatistics) {
+ $start_time = getmicrotime();
+ }
+ // set 1st checkpoint: end
+
+ $resource = $query_func($select_sql, $this->connectionID);
+
+ // set 2nd checkpoint: begin
+ if ($this->_captureStatistics) {
+ $query_time = getmicrotime() - $start_time;
+ if ($query_time > DBG_MAX_SQL_TIME) {
+ $this->Application->logSlowQuery($select_sql, $query_time);
+ }
+ $this->_queryTime += $query_time;
+ }
+ // set 2nd checkpoint: end
+
+ if ( is_resource($resource) ) {
+ return $resource;
+ }
+
+ $this->showError($select_sql);
+
+ return false;
+ }
+
+ /**
+ * Returns row count in recordset
+ *
+ * @param resource $resource
+ * @return int
+ */
+ function RowCount($resource)
+ {
+ $count_func = $this->getMetaFunction('num_rows');
+
+ return $count_func($resource);
+ }
+
+ /**
+ * Returns next available row from recordset
+ *
+ * @return Array
+ */
+ function GetNextRow($resource)
+ {
+ $fetch_func = $this->getMetaFunction('fetch_assoc');
+
+ return $fetch_func($resource);
+ }
+
+ /**
+ * Free memory used to hold recordset handle
+ *
+ * @param resource $resource
+ * @access private
+ */
+ function Destroy($resource = null)
+ {
+ if ( !isset($resource) ) {
+ $resource = $this->queryID;
+ }
+
+ if ( $resource ) {
+ $free_func = $this->getMetaFunction('free_result');
+ $free_func($resource);
+
+ $this->queryID = null;
+ }
+ }
+
function ChangeQuery($sql)
{
$this->Query($sql);
@@ -546,21 +633,6 @@
}
/**
- * Free memory used to hold recordset handle
- *
- * @access private
- */
- function Destroy()
- {
- if($this->queryID)
- {
- $free_func = $this->getMetaFunction('free_result');
- $free_func($this->queryID);
- $this->queryID = null;
- }
- }
-
- /**
* Returns auto increment field value from
* insert like operation if any, zero otherwise
*
db_class_for_large_data_set_513.patch [^] (2,873 bytes) 2011-10-17 08:31
[Show Content]
Index: db_connection.php
===================================================================
--- db_connection.php (revision 14476)
+++ db_connection.php (working copy)
@@ -310,7 +310,7 @@
function showError($sql = '', $key_field = null, $no_debug = false)
{
static $retry_count = 0;
-
+
$func = $this->getMetaFunction('errno');
if (!$this->connectionID) {
@@ -546,6 +546,92 @@
return $this->showError($sql, $key_field, $no_debug);
}
+ /**
+ * Retrieves data from database and return resource id on success or false otherwise
+ *
+ * @param string $select_sql
+ * @param string $key_field
+ * @return resource
+ * @see kDBConnection::GetNextRow
+ */
+ function QueryRaw($select_sql)
+ {
+ $this->lastQuery = $select_sql;
+ $this->_queryCount++;
+
+ $query_func = $this->getMetaFunction('query');
+
+ // set 1st checkpoint: begin
+ if ($this->_captureStatistics) {
+ $start_time = getmicrotime();
+ }
+ // set 1st checkpoint: end
+
+ $this->setError(0, ''); // reset error
+ $resource = $query_func($select_sql, $this->connectionID);
+
+ // set 2nd checkpoint: begin
+ if ($this->_captureStatistics) {
+ $query_time = getmicrotime() - $start_time;
+ if ($query_time > DBG_MAX_SQL_TIME) {
+ $this->Application->logSlowQuery($select_sql, $query_time);
+ }
+ $this->_queryTime += $query_time;
+ }
+ // set 2nd checkpoint: end
+
+ if ( is_resource($resource) ) {
+ return $resource;
+ }
+
+ return $this->showError($select_sql);
+ }
+
+ /**
+ * Returns row count in recordset
+ *
+ * @param resource $resource
+ * @return int
+ */
+ function RowCount($resource)
+ {
+ $count_func = $this->getMetaFunction('num_rows');
+
+ return $count_func($resource);
+ }
+
+ /**
+ * Returns next available row from recordset
+ *
+ * @return Array
+ */
+ function GetNextRow($resource)
+ {
+ $fetch_func = $this->getMetaFunction('fetch_assoc');
+
+ return $fetch_func($resource);
+ }
+
+ /**
+ * Free memory used to hold recordset handle
+ *
+ * @param resource $resource
+ * @access private
+ */
+ function Destroy($resource = null)
+ {
+ if ( !isset($resource) ) {
+ $resource = $this->queryID;
+ }
+
+ if ( $resource ) {
+ $free_func = $this->getMetaFunction('free_result');
+ $free_func($resource);
+
+ $this->queryID = null;
+ }
+ }
+
function ChangeQuery($sql)
{
$this->Query($sql);
@@ -618,21 +704,6 @@
}
/**
- * Free memory used to hold recordset handle
- *
- * @access private
- */
- function Destroy()
- {
- if($this->queryID)
- {
- $free_func = $this->getMetaFunction('free_result');
- $free_func($this->queryID);
- $this->queryID = null;
- }
- }
-
- /**
* Returns auto increment field value from
* insert like operation if any, zero otherwise
*
db_class_for_large_data_set_520.patch [^] (3,736 bytes) 2011-12-08 04:14
[Show Content]
Index: kernel/db/db_connection.php
===================================================================
--- kernel/db/db_connection.php (revision 14826)
+++ kernel/db/db_connection.php (working copy)
@@ -638,6 +638,98 @@
}
/**
+ * Retrieves data from database and return resource id on success or false otherwise
+ *
+ * @param string $select_sql
+ * @return resource
+ * @access public
+ * @see kDBConnection::GetNextRow
+ */
+ public function QueryRaw($select_sql)
+ {
+ $this->lastQuery = $select_sql;
+ $this->_queryCount++;
+
+ $query_func = $this->getMetaFunction('query');
+
+ // set 1st checkpoint: begin
+ if ($this->_captureStatistics) {
+ $start_time = microtime(true);
+ }
+ // set 1st checkpoint: end
+
+ $this->setError(0, ''); // reset error
+ $resource = $query_func($select_sql, $this->connectionID);
+
+ // set 2nd checkpoint: begin
+ if ($this->_captureStatistics) {
+ $query_time = microtime(true) - $start_time;
+ if ($query_time > DBG_MAX_SQL_TIME) {
+ $this->Application->logSlowQuery($select_sql, $query_time);
+ }
+ $this->_queryTime += $query_time;
+ }
+ // set 2nd checkpoint: end
+
+ if ( is_resource($resource) ) {
+ return $resource;
+ }
+
+ return $this->showError($select_sql);
+ }
+
+ /**
+ * Returns row count in recordset
+ *
+ * @param resource $resource
+ * @return int
+ * @access public
+ */
+ public function RowCount($resource)
+ {
+ $count_func = $this->getMetaFunction('num_rows');
+
+ return $count_func($resource);
+ }
+
+ /**
+ * Returns next available row from recordset
+ *
+ * @param resource $resource
+ * @param string $fetch_type
+ * @return Array
+ * @access public
+ * @see kDBConnection::QueryRaw
+ */
+ public function GetNextRow($resource, $fetch_type = 'assoc')
+ {
+ $fetch_func = $this->getMetaFunction('fetch_' . $fetch_type);
+
+ return $fetch_func($resource);
+ }
+
+ /**
+ * Free memory used to hold recordset handle
+ *
+ * @param resource $resource
+ * @access public
+ * @see kDBConnection::QueryRaw
+ */
+ public function Destroy($resource = null)
+ {
+ if ( !isset($resource) ) {
+ $resource = $this->queryID;
+ }
+
+ if ( $resource ) {
+ $free_func = $this->getMetaFunction('free_result');
+ $free_func($resource);
+
+ $this->queryID = null;
+ }
+ }
+
+ /**
* Performs sql query, that will change database content
*
* @param string $sql
@@ -725,20 +817,6 @@
}
/**
- * Free memory used to hold recordset handle
- *
- * @access public
- */
- public function Destroy()
- {
- if ( $this->queryID ) {
- $free_func = $this->getMetaFunction('free_result');
- $free_func($this->queryID);
- $this->queryID = null;
- }
- }
-
- /**
* Returns auto increment field value from
* insert like operation if any, zero otherwise
*
@@ -987,7 +1065,7 @@
public function getSlaveLag()
{
// don't use kDBConnection::Query method, since it will create an array of all server processes
- $rs = mysql_query('SHOW PROCESSLIST', $this->connectionID);
+ $rs = $this->QueryRaw('SHOW PROCESSLIST');
$skip_states = Array (
'Waiting for master to send event',
@@ -998,13 +1076,17 @@
);
// find slave SQL thread
- while ( $row = mysql_fetch_array($rs) ) {
+ while ( $row = $this->GetNextRow($rs, 'array') ) {
if ( $row['User'] == 'system user' && !in_array($row['State'], $skip_states) ) {
// this is it, return the time (except -ve)
+ $this->Destroy($rs);
+
return $row['Time'] > 0x7fffffff ? false : $row['Time'];
}
}
+ $this->Destroy($rs);
+
return false;
}
}
\ No newline at end of file
|