本文整理汇总了PHP中DibiConnection::getDriver方法的典型用法代码示例。如果您正苦于以下问题:PHP DibiConnection::getDriver方法的具体用法?PHP DibiConnection::getDriver怎么用?PHP DibiConnection::getDriver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DibiConnection
的用法示例。
在下文中一共展示了DibiConnection::getDriver方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param string SQL command or table or view name, as data source
* @param DibiConnection connection
*/
public function __construct($sql, DibiConnection $connection)
{
if (strpbrk($sql, " \t\r\n") === FALSE) {
$this->sql = $connection->getDriver()->escape($sql, dibi::IDENTIFIER);
// table name
} else {
$this->sql = '(' . $sql . ') t';
// SQL command
}
$this->connection = $connection;
}
示例2: translate
/**
* Generates SQL.
* @param array
* @return string
* @throws DibiException
*/
public function translate(array $args)
{
$this->identifiers = new DibiHashMap(array($this, 'delimite'));
$this->driver = $this->connection->getDriver();
$args = array_values($args);
while (count($args) === 1 && is_array($args[0])) {
// implicit array expansion
$args = array_values($args[0]);
}
$this->args = $args;
$this->limit = -1;
$this->offset = 0;
$this->hasError = FALSE;
$commandIns = NULL;
$lastArr = NULL;
// shortcuts
$cursor =& $this->cursor;
$cursor = 0;
// conditional sql
$this->ifLevel = $this->ifLevelStart = 0;
$comment =& $this->comment;
$comment = FALSE;
// iterate
$sql = array();
while ($cursor < count($this->args)) {
$arg = $this->args[$cursor];
$cursor++;
// simple string means SQL
if (is_string($arg)) {
// speed-up - is regexp required?
$toSkip = strcspn($arg, '`[\'":%?');
if (strlen($arg) === $toSkip) {
// needn't be translated
$sql[] = $arg;
} else {
$sql[] = substr($arg, 0, $toSkip) . preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\\[(.+?)\\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\\?))/s', array($this, 'cb'), substr($arg, $toSkip));
if (preg_last_error()) {
throw new DibiPcreException();
}
}
continue;
}
if ($comment) {
$sql[] = '...';
continue;
}
if ($arg instanceof Traversable) {
$arg = iterator_to_array($arg);
}
if (is_array($arg)) {
if (is_string(key($arg))) {
// associative array -> autoselect between SET or VALUES & LIST
if ($commandIns === NULL) {
$commandIns = strtoupper(substr(ltrim($this->args[0]), 0, 6));
$commandIns = $commandIns === 'INSERT' || $commandIns === 'REPLAC';
$sql[] = $this->formatValue($arg, $commandIns ? 'v' : 'a');
} else {
if ($lastArr === $cursor - 1) {
$sql[] = ',';
}
$sql[] = $this->formatValue($arg, $commandIns ? 'l' : 'a');
}
$lastArr = $cursor;
continue;
}
}
// default processing
$sql[] = $this->formatValue($arg, FALSE);
}
// while
if ($comment) {
$sql[] = "*/";
}
$sql = implode(' ', $sql);
if ($this->hasError) {
throw new DibiException('SQL translate error', 0, $sql);
}
// apply limit
if ($this->limit > -1 || $this->offset > 0) {
$this->driver->applyLimit($sql, $this->limit, $this->offset);
}
return $sql;
}
示例3: formatValue
/**
* Apply modifier to single value.
* @param mixed
* @param string
* @return string
*/
public function formatValue($value, $modifier)
{
if ($this->comment) {
return '...';
}
if (!$this->driver) {
$this->driver = $this->connection->getDriver();
}
// array processing (with or without modifier)
if ($value instanceof Traversable) {
$value = iterator_to_array($value);
}
if (is_array($value)) {
$vx = $kx = array();
switch ($modifier) {
case 'and':
case 'or':
// key=val AND key IS NULL AND ...
if (empty($value)) {
return '1=1';
}
foreach ($value as $k => $v) {
if (is_string($k)) {
$pair = explode('%', $k, 2);
// split into identifier & modifier
$k = $this->identifiers->{$pair[0]} . ' ';
if (!isset($pair[1])) {
$v = $this->formatValue($v, FALSE);
$vx[] = $k . ($v === 'NULL' ? 'IS ' : '= ') . $v;
} elseif ($pair[1] === 'ex') {
// TODO: this will be removed
$vx[] = $k . $this->formatValue($v, 'ex');
} else {
$v = $this->formatValue($v, $pair[1]);
if ($pair[1] === 'l' || $pair[1] === 'in') {
$op = 'IN ';
} elseif (strpos($pair[1], 'like') !== FALSE) {
$op = 'LIKE ';
} elseif ($v === 'NULL') {
$op = 'IS ';
} else {
$op = '= ';
}
$vx[] = $k . $op . $v;
}
} else {
$vx[] = $this->formatValue($v, 'ex');
}
}
return '(' . implode(') ' . strtoupper($modifier) . ' (', $vx) . ')';
case 'n':
// key, key, ... identifier names
foreach ($value as $k => $v) {
if (is_string($k)) {
$vx[] = $this->identifiers->{$k} . (empty($v) ? '' : ' AS ' . $this->identifiers->{$v});
} else {
$pair = explode('%', $v, 2);
// split into identifier & modifier
$vx[] = $this->identifiers->{$pair[0]};
}
}
return implode(', ', $vx);
case 'a':
// key=val, key=val, ...
foreach ($value as $k => $v) {
$pair = explode('%', $k, 2);
// split into identifier & modifier
$vx[] = $this->identifiers->{$pair[0]} . '=' . $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
}
return implode(', ', $vx);
case 'in':
// replaces scalar %in modifier!
// replaces scalar %in modifier!
case 'l':
// (val, val, ...)
foreach ($value as $k => $v) {
$pair = explode('%', $k, 2);
// split into identifier & modifier
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
}
return '(' . ($vx || $modifier === 'l' ? implode(', ', $vx) : 'NULL') . ')';
case 'v':
// (key, key, ...) VALUES (val, val, ...)
foreach ($value as $k => $v) {
$pair = explode('%', $k, 2);
// split into identifier & modifier
$kx[] = $this->identifiers->{$pair[0]};
$vx[] = $this->formatValue($v, isset($pair[1]) ? $pair[1] : (is_array($v) ? 'ex' : FALSE));
}
return '(' . implode(', ', $kx) . ') VALUES (' . implode(', ', $vx) . ')';
case 'm':
// (key, key, ...) VALUES (val, val, ...), (val, val, ...), ...
foreach ($value as $k => $v) {
if (is_array($v)) {
//.........这里部分代码省略.........
示例4:
IDataSource{private$connection;private$sql;private$result;private$count;private$totalCount;private$cols=array();private$sorting=array();private$conds=array();private$offset;private$limit;function
__construct($sql,DibiConnection$connection){if(strpbrk($sql," \t\r\n")===FALSE){$this->sql=$connection->getDriver()->escape($sql,dibi::IDENTIFIER);}else{$this->sql='('.$sql.') t';}$this->connection=$connection;}function
示例5: __construct
public function __construct(DibiConnection $connection)
{
$this->connection = $connection;
$this->driver = $connection->getDriver();
$this->identifiers = new DibiHashMap(array($this, 'delimite'));
}
示例6: __construct
public function __construct($sql, DibiConnection $connection)
{
if (strpos($sql, ' ') === FALSE) {
$this->sql = $connection->getDriver()->escape($sql, dibi::IDENTIFIER);
} else {
$this->sql = '(' . $sql . ') t';
}
$this->connection = $connection;
}