From 0612c4683e9503fd63286d90bb62a8bfcb3e6a08 Mon Sep 17 00:00:00 2001 From: Catfan Date: Mon, 23 Jun 2014 21:34:04 +0800 Subject: [PATCH 1/4] [fix] Fix Allow using SQL functions bug #112, reported by @Heirir --- medoo.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/medoo.php b/medoo.php index dff70544..b149f9d9 100644 --- a/medoo.php +++ b/medoo.php @@ -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) { @@ -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); + } + } } } } From 8f6961eea133fe2b7a2993163c67728a898b1af3 Mon Sep 17 00:00:00 2001 From: Catfan Date: Mon, 7 Jul 2014 01:31:49 +0800 Subject: [PATCH 2/4] [update] Optimize code --- medoo.php | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/medoo.php b/medoo.php index b149f9d9..53e1b0ad 100644 --- a/medoo.php +++ b/medoo.php @@ -382,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); @@ -426,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']) . ')'; } } @@ -442,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); @@ -468,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] : ''); } @@ -481,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]; } } } From 485f6b2002b1389eb2ee0b762b73ae6329daa5ae Mon Sep 17 00:00:00 2001 From: Catfan Date: Sun, 13 Jul 2014 20:17:24 +0800 Subject: [PATCH 3/4] [fix] Fix bug for has API --- medoo.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/medoo.php b/medoo.php index 53e1b0ad..06dca1f4 100644 --- a/medoo.php +++ b/medoo.php @@ -603,10 +603,6 @@ protected function select_context($table, $join, &$columns = null, $where = null { $where = $columns; } - else - { - $where = $join; - } } else { From ad2e18adca12d4c73560ac30669135e1a4806857 Mon Sep 17 00:00:00 2001 From: Catfan Date: Fri, 15 Aug 2014 20:27:20 +0800 Subject: [PATCH 4/4] [release] Medoo 0.9.6.2 --- medoo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/medoo.php b/medoo.php index 06dca1f4..c10560bd 100644 --- a/medoo.php +++ b/medoo.php @@ -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