From 50f8da9bae718e28c7fbdec22d848788f28866ec Mon Sep 17 00:00:00 2001 From: Catfan Date: Tue, 28 Jun 2016 12:43:49 +0800 Subject: [PATCH 1/4] [fix] Fix data mapping bug for get API --- medoo.php | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/medoo.php b/medoo.php index b5bbe09b..d3e9bfa2 100644 --- a/medoo.php +++ b/medoo.php @@ -908,9 +908,13 @@ public function replace($table, $columns, $search = null, $replace = null, $wher return $this->exec('UPDATE ' . $this->table_quote($table) . ' SET ' . $replace_query . $this->where_clause($where)); } - public function get($table, $join = null, $column = null, $where = null) + public function get($table, $join = null, $columns = null, $where = null) { - $query = $this->query($this->select_context($table, $join, $column, $where) . ' LIMIT 1'); + $column = $where == null ? $join : $columns; + + $is_single_column = (is_string($column) && $column !== '*'); + + $query = $this->query($this->select_context($table, $join, $columns, $where) . ' LIMIT 1'); if ($query) { @@ -918,14 +922,31 @@ public function get($table, $join = null, $column = null, $where = null) if (isset($data[ 0 ])) { - $column = $where == null ? $join : $column; + if ($is_single_column) + { + return $data[ 0 ][ preg_replace('/^[\w]*\./i', "", $column) ]; + } + + if ($column === '*') + { + return $data[ 0 ]; + } - if (is_string($column) && $column != '*') + $stack = array(); + + foreach ($columns as $key => $value) { - return $data[ 0 ][ $column ]; + if (is_array($value)) + { + $this->data_map(0, $key, $value, $data[ 0 ], $stack); + } + else + { + $this->data_map(0, $key, preg_replace('/^[\w]*\./i', "", $value), $data[ 0 ], $stack); + } } - return $data[ 0 ]; + return $stack[ 0 ]; } else { From f9741e089dbaa26876223284b33278f6f752e28b Mon Sep 17 00:00:00 2001 From: Catfan Date: Tue, 28 Jun 2016 12:49:32 +0800 Subject: [PATCH 2/4] [fix] Fix order syntax bug --- medoo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/medoo.php b/medoo.php index d3e9bfa2..81d1b3f9 100644 --- a/medoo.php +++ b/medoo.php @@ -489,7 +489,7 @@ protected function where_clause($where) } else if ($value === 'ASC' || $value === 'DESC') { - $stack[] = '"' . str_replace('.', '"."', $column) . ' ' . $value . '"'; + $stack[] = $this->column_quote($column) . ' ' . $value; } else if (is_int($column)) { From 91c00f061c6a86b5b406e7a2209f745602a040b7 Mon Sep 17 00:00:00 2001 From: Catfan Date: Tue, 28 Jun 2016 12:57:18 +0800 Subject: [PATCH 3/4] [fix] Fix select bug for * condition #422 --- medoo.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/medoo.php b/medoo.php index 81d1b3f9..a8e3f8f8 100644 --- a/medoo.php +++ b/medoo.php @@ -741,6 +741,11 @@ public function select($table, $join, $columns = null, $where = null) return false; } + if ($columns === '*') + { + return $query->fetchAll(PDO::FETCH_ASSOC); + } + while ($row = $query->fetch(PDO::FETCH_ASSOC)) { foreach ($columns as $key => $value) From e788a73a2d1da6c10f34908de01f1dbcaf4e9d18 Mon Sep 17 00:00:00 2001 From: Catfan Date: Tue, 28 Jun 2016 12:57:55 +0800 Subject: [PATCH 4/4] [release] Medoo v1.1.1 --- medoo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/medoo.php b/medoo.php index a8e3f8f8..85338b62 100644 --- a/medoo.php +++ b/medoo.php @@ -2,7 +2,7 @@ /*! * Medoo database framework * http://medoo.in - * Version 1.1 + * Version 1.1.1 * * Copyright 2016, Angel Lai * Released under the MIT license