Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
catfan committed Aug 15, 2014
2 parents 2cf2d9f + ad2e18a commit e489311
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*!
* Medoo database framework
* http://medoo.in
* Version 0.9.6
* Version 0.9.6.2
*
* Copyright 2014, Angel Lai
* Released under the MIT license
Expand Down Expand Up @@ -238,11 +238,7 @@ protected function data_implode($data, $conjunctor, $outer_conjunctor = null)

if (isset($match[4]))
{
if ($match[4] == '')
{
$wheres[] = $column . ' ' . $match[4] . '= ' . $this->quote($value);
}
elseif ($match[4] == '!')
if ($match[4] == '!')
{
switch ($type)
{
Expand Down Expand Up @@ -303,6 +299,13 @@ protected function data_implode($data, $conjunctor, $outer_conjunctor = null)
{
$wheres[] = $column . ' ' . $match[4] . ' ' . $this->quote(date('Y-m-d H:i:s', $datetime));
}
else
{
if (strpos($key, '#') === 0)
{
$wheres[] = $column . ' ' . $match[4] . ' ' . $this->fn_quote($key, $value);
}
}
}
}
}
Expand Down Expand Up @@ -379,24 +382,24 @@ protected function where_clause($where)

if (isset($where['LIKE']))
{
$like_query = $where['LIKE'];
$LIKE = $where['LIKE'];

if (is_array($like_query))
if (is_array($LIKE))
{
$is_OR = isset($like_query['OR']);
$is_OR = isset($LIKE['OR']);
$clause_wrap = array();

if ($is_OR || isset($like_query['AND']))
if ($is_OR || isset($LIKE['AND']))
{
$connector = $is_OR ? 'OR' : 'AND';
$like_query = $is_OR ? $like_query['OR'] : $like_query['AND'];
$LIKE = $is_OR ? $LIKE['OR'] : $LIKE['AND'];
}
else
{
$connector = 'AND';
}

foreach ($like_query as $column => $keyword)
foreach ($LIKE as $column => $keyword)
{
$keyword = is_array($keyword) ? $keyword : array($keyword);

Expand All @@ -423,11 +426,11 @@ protected function where_clause($where)

if (isset($where['MATCH']))
{
$match_query = $where['MATCH'];
$MATCH = $where['MATCH'];

if (is_array($match_query) && isset($match_query['columns'], $match_query['keyword']))
if (is_array($MATCH) && isset($MATCH['columns'], $MATCH['keyword']))
{
$where_clause .= ($where_clause != '' ? ' AND ' : ' WHERE ') . ' MATCH ("' . str_replace('.', '"."', implode($match_query['columns'], '", "')) . '") AGAINST (' . $this->quote($match_query['keyword']) . ')';
$where_clause .= ($where_clause != '' ? ' AND ' : ' WHERE ') . ' MATCH ("' . str_replace('.', '"."', implode($MATCH['columns'], '", "')) . '") AGAINST (' . $this->quote($MATCH['keyword']) . ')';
}
}

Expand All @@ -439,21 +442,22 @@ protected function where_clause($where)
if (isset($where['ORDER']))
{
$rsort = '/(^[a-zA-Z0-9_\-\.]*)(\s*(DESC|ASC))?/';
$ORDER = $where['ORDER'];

if (is_array($where['ORDER']))
if (is_array($ORDER))
{
if (
isset($where['ORDER'][1]) &&
is_array($where['ORDER'][1])
isset($ORDER[1]) &&
is_array($ORDER[1])
)
{
$where_clause .= ' ORDER BY FIELD(' . $this->column_quote($where['ORDER'][0]) . ', ' . $this->array_quote($where['ORDER'][1]) . ')';
$where_clause .= ' ORDER BY FIELD(' . $this->column_quote($ORDER[0]) . ', ' . $this->array_quote($ORDER[1]) . ')';
}
else
{
$stack = array();

foreach ($where['ORDER'] as $column)
foreach ($ORDER as $column)
{
preg_match($rsort, $column, $order_match);

Expand All @@ -465,7 +469,7 @@ protected function where_clause($where)
}
else
{
preg_match($rsort, $where['ORDER'], $order_match);
preg_match($rsort, $ORDER, $order_match);

$where_clause .= ' ORDER BY "' . str_replace('.', '"."', $order_match[1]) . '"' . (isset($order_match[3]) ? ' ' . $order_match[3] : '');
}
Expand All @@ -478,18 +482,20 @@ protected function where_clause($where)

if (isset($where['LIMIT']))
{
if (is_numeric($where['LIMIT']))
$LIMIT = $where['LIMIT'];

if (is_numeric($LIMIT))
{
$where_clause .= ' LIMIT ' . $where['LIMIT'];
$where_clause .= ' LIMIT ' . $LIMIT;
}

if (
is_array($where['LIMIT']) &&
is_numeric($where['LIMIT'][0]) &&
is_numeric($where['LIMIT'][1])
is_array($LIMIT) &&
is_numeric($LIMIT[0]) &&
is_numeric($LIMIT[1])
)
{
$where_clause .= ' LIMIT ' . $where['LIMIT'][0] . ',' . $where['LIMIT'][1];
$where_clause .= ' LIMIT ' . $LIMIT[0] . ',' . $LIMIT[1];
}
}
}
Expand Down Expand Up @@ -597,10 +603,6 @@ protected function select_context($table, $join, &$columns = null, $where = null
{
$where = $columns;
}
else
{
$where = $join;
}
}
else
{
Expand Down

0 comments on commit e489311

Please sign in to comment.