Commit dce75449 authored by Alexander Butenko's avatar Alexander Butenko

Merge pull request #309 from avbdr/master

fixes
parents acaf0d1c e4b060d6
......@@ -139,6 +139,19 @@ class MysqliDb
*/
protected $_nestJoin = false;
private $_tableName = '';
/**
* FOR UPDATE flag
* @var boolean
*/
protected $_forUpdate = false;
/**
* LOCK IN SHARE MODE flag
* @var boolean
*/
protected $_lockInShareMode = false;
/**
* Variables for query execution tracing
*
......@@ -247,6 +260,8 @@ class MysqliDb
$this->_queryOptions = array();
$this->returnType = 'Array';
$this->_nestJoin = false;
$this->_forUpdate = false;
$this->_lockInShareMode = false;
$this->_tableName = '';
$this->_lastInsertId = null;
$this->_updateColumns = null;
......@@ -401,7 +416,7 @@ class MysqliDb
public function setQueryOption ($options) {
$allowedOptions = Array ('ALL','DISTINCT','DISTINCTROW','HIGH_PRIORITY','STRAIGHT_JOIN','SQL_SMALL_RESULT',
'SQL_BIG_RESULT','SQL_BUFFER_RESULT','SQL_CACHE','SQL_NO_CACHE', 'SQL_CALC_FOUND_ROWS',
'LOW_PRIORITY','IGNORE','QUICK', 'MYSQLI_NESTJOIN');
'LOW_PRIORITY','IGNORE','QUICK', 'MYSQLI_NESTJOIN', 'FOR UPDATE', 'LOCK IN SHARE MODE');
if (!is_array ($options))
$options = Array ($options);
......@@ -412,6 +427,10 @@ class MysqliDb
if ($option == 'MYSQLI_NESTJOIN')
$this->_nestJoin = true;
else if ($option == 'MYSQLI_FOR_UPDATE')
$this->_forUpdate = true;
else if ($option == 'MYSQLI_LOCK_IN_SHARE_MODE')
$this->_lockInShareMode = true;
else
$this->_queryOptions[] = $option;
}
......@@ -632,6 +651,7 @@ class MysqliDb
{
$this->_lastInsertId = $_lastInsertId;
$this->_updateColumns = $_updateColumns;
return $this;
}
/**
......@@ -883,6 +903,10 @@ class MysqliDb
$this->_buildOrderBy();
$this->_buildLimit ($numRows);
$this->_buildOnDuplicate($tableData);
if ($this->_forUpdate)
$this->_query .= ' FOR UPDATE';
if ($this->_lockInShareMode)
$this->_query .= ' LOCK IN SHARE MODE';
$this->_lastQuery = $this->replacePlaceHolders ($this->_query, $this->_bindParams);
......
......@@ -351,23 +351,25 @@ echo "Showing {$count} from {$db->totalCount}";
```
### Query Keywords
To add LOW PRIORITY | DELAYED | HIGH PRIORITY | IGNORE and the rest of the mysql keywords to INSERT (), REPLACE (), GET (), UPDATE (), DELETE() method:
To add LOW PRIORITY | DELAYED | HIGH PRIORITY | IGNORE and the rest of the mysql keywords to INSERT (), REPLACE (), GET (), UPDATE (), DELETE() method or FOR UPDATE | LOCK IN SHARE MODE into SELECT ():
```php
$db->setQueryOption('LOW_PRIORITY');
$db->insert ($table, $param);
$db->setQueryOption ('LOW_PRIORITY')->insert ($table, $param);
// GIVES: INSERT LOW_PRIORITY INTO table ...
```
```php
$db->setQueryOption ('FOR UPDATE')->get ('users');
// GIVES: SELECT * FROM USERS FOR UPDATE;
```
Also you can use an array of keywords:
```php
$db->setQueryOption(Array('LOW_PRIORITY', 'IGNORE'));
$db->insert ($table,$param);
$db->setQueryOption (Array('LOW_PRIORITY', 'IGNORE'))->insert ($table,$param);
// GIVES: INSERT LOW_PRIORITY IGNORE INTO table ...
```
Same way keywords could be used in SELECT queries as well:
```php
$db->setQueryOption('SQL_NO_CACHE');
$db->setQueryOption ('SQL_NO_CACHE');
$db->get("users");
// GIVES: SELECT SQL_NO_CACHE * FROM USERS;
```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment