Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
catfan committed Jul 7, 2016
2 parents b1c49a9 + a940f32 commit 828ffeb
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions medoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@ protected function table_quote($table)

protected function column_quote($string)
{
return preg_replace('/(\(JSON\)\s*|^#)?([a-zA-Z0-9_]*)\.([a-zA-Z0-9_]*)/', '"' . $this->prefix . '$2"."$3"', $string);
preg_match('/(\(JSON\)\s*|^#)?([a-zA-Z0-9_]*)\.([a-zA-Z0-9_]*)/', $string, $column_match);

if (isset($column_match[ 2 ], $column_match[ 3 ]))
{
return '"' . $this->prefix . $column_match[ 2 ] . '"."' . $column_match[ 3 ] . '"';
}

return '"' . $string . '"';
}

protected function column_push(&$columns)
Expand Down Expand Up @@ -730,6 +737,10 @@ protected function data_map($index, $key, $value, $data, &$stack)

public function select($table, $join, $columns = null, $where = null)
{
$column = $where == null ? $join : $columns;

$is_single_column = (is_string($column) && $column !== '*');

$query = $this->query($this->select_context($table, $join, $columns, $where));

$stack = array();
Expand All @@ -746,6 +757,11 @@ public function select($table, $join, $columns = null, $where = null)
return $query->fetchAll(PDO::FETCH_ASSOC);
}

if ($is_single_column)
{
return $query->fetchAll(PDO::FETCH_COLUMN);
}

while ($row = $query->fetch(PDO::FETCH_ASSOC))
{
foreach ($columns as $key => $value)
Expand Down Expand Up @@ -783,7 +799,7 @@ public function insert($table, $datas)

foreach ($data as $key => $value)
{
$columns[] = $this->column_quote($key);
$columns[] = preg_replace("/^(\(JSON\)\s*|#)/i", "", $key);

switch (gettype($value))
{
Expand Down Expand Up @@ -836,7 +852,7 @@ public function update($table, $data, $where = null)
}
else
{
$column = $this->column_quote($key);
$column = $this->column_quote(preg_replace("/^(\(JSON\)\s*|#)/i", "", $key));

switch (gettype($value))
{
Expand Down

0 comments on commit 828ffeb

Please sign in to comment.