New function for affected rows
This commit is contained in:
parent
a056afd566
commit
a7526f1291
|
@ -21,6 +21,8 @@ class dba {
|
||||||
private $driver;
|
private $driver;
|
||||||
public $connected = false;
|
public $connected = false;
|
||||||
public $error = false;
|
public $error = false;
|
||||||
|
public $errorno = 0;
|
||||||
|
public $affected_rows = 0;
|
||||||
private $_server_info = '';
|
private $_server_info = '';
|
||||||
private static $in_transaction = false;
|
private static $in_transaction = false;
|
||||||
private static $dbo;
|
private static $dbo;
|
||||||
|
@ -551,6 +553,7 @@ class dba {
|
||||||
|
|
||||||
self::$dbo->error = '';
|
self::$dbo->error = '';
|
||||||
self::$dbo->errorno = 0;
|
self::$dbo->errorno = 0;
|
||||||
|
self::$dbo->affected_rows = 0;
|
||||||
|
|
||||||
switch (self::$dbo->driver) {
|
switch (self::$dbo->driver) {
|
||||||
case 'pdo':
|
case 'pdo':
|
||||||
|
@ -573,6 +576,7 @@ class dba {
|
||||||
$retval = false;
|
$retval = false;
|
||||||
} else {
|
} else {
|
||||||
$retval = $stmt;
|
$retval = $stmt;
|
||||||
|
self::$dbo->affected_rows = $retval->rowCount();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'mysqli':
|
case 'mysqli':
|
||||||
|
@ -612,6 +616,7 @@ class dba {
|
||||||
} else {
|
} else {
|
||||||
$stmt->store_result();
|
$stmt->store_result();
|
||||||
$retval = $stmt;
|
$retval = $stmt;
|
||||||
|
self::$dbo->affected_rows = $retval->affected_rows;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'mysql':
|
case 'mysql':
|
||||||
|
@ -620,6 +625,8 @@ class dba {
|
||||||
if (mysql_errno(self::$dbo->db)) {
|
if (mysql_errno(self::$dbo->db)) {
|
||||||
self::$dbo->error = mysql_error(self::$dbo->db);
|
self::$dbo->error = mysql_error(self::$dbo->db);
|
||||||
self::$dbo->errorno = mysql_errno(self::$dbo->db);
|
self::$dbo->errorno = mysql_errno(self::$dbo->db);
|
||||||
|
} else {
|
||||||
|
self::$dbo->affected_rows = mysql_affected_rows($retval);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -754,6 +761,15 @@ class dba {
|
||||||
return $retval;
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the number of affected rows of the last statement
|
||||||
|
*
|
||||||
|
* @return int Number of rows
|
||||||
|
*/
|
||||||
|
static public function affected_rows() {
|
||||||
|
return self::$dbo->affected_rows;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the number of rows of a statement
|
* @brief Returns the number of rows of a statement
|
||||||
*
|
*
|
||||||
|
|
|
@ -612,36 +612,33 @@ function find_worker_processes() {
|
||||||
|
|
||||||
if (poller_passing_slow($highest_priority)) {
|
if (poller_passing_slow($highest_priority)) {
|
||||||
// Are there waiting processes with a higher priority than the currently highest?
|
// Are there waiting processes with a higher priority than the currently highest?
|
||||||
$result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
|
$result = dba::e("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
|
||||||
WHERE `executed` <= ? AND `priority` < ?
|
WHERE `executed` <= ? AND `priority` < ?
|
||||||
ORDER BY `priority`, `created` LIMIT 5",
|
ORDER BY `priority`, `created` LIMIT 5",
|
||||||
datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
|
datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
|
||||||
if (dbm::is_result($result)) {
|
if ($result) {
|
||||||
$found = (dba::num_rows($result) > 0);
|
$found = (dba::affected_rows() > 0);
|
||||||
}
|
}
|
||||||
dba::close($result);
|
|
||||||
|
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
// Give slower processes some processing time
|
// Give slower processes some processing time
|
||||||
$result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
|
$result = dba::e("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
|
||||||
WHERE `executed` <= ? AND `priority` > ?
|
WHERE `executed` <= ? AND `priority` > ?
|
||||||
ORDER BY `priority`, `created` LIMIT 1",
|
ORDER BY `priority`, `created` LIMIT 1",
|
||||||
datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
|
datetime_convert(), getmypid(), NULL_DATE, $highest_priority);
|
||||||
if (dbm::is_result($result)) {
|
if ($result) {
|
||||||
$found = (dba::num_rows($result) > 0);
|
$found = (dba::affected_rows() > 0);
|
||||||
}
|
}
|
||||||
dba::close($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
$result = dba::p("UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `executed` <= ? ORDER BY `priority`, `created` LIMIT 5",
|
$result = dba::e("UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `executed` <= ? ORDER BY `priority`, `created` LIMIT 5",
|
||||||
datetime_convert(), getmypid(), NULL_DATE);
|
datetime_convert(), getmypid(), NULL_DATE);
|
||||||
if (dbm::is_result($result)) {
|
if ($result) {
|
||||||
$found = (dba::num_rows($result) > 0);
|
$found = (dba::affected_rows() > 0);
|
||||||
}
|
}
|
||||||
dba::close($result);
|
|
||||||
}
|
}
|
||||||
return $found;
|
return $found;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue