Revert "medoo only"

This reverts commit 2c31de1d6a2cf8cf404daff6ae1d060bb1181b00.
This commit is contained in:
2020-01-28 00:56:16 +09:00
parent 4dbe30bb2b
commit 76b8a59f39
10 changed files with 241 additions and 557 deletions
Generated
+8 -10
View File
@@ -1,7 +1,7 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "3fceaf3c2925068c7e757ab12036e29e",
@@ -54,16 +54,16 @@
},
{
"name": "catfan/medoo",
"version": "v1.7.8",
"version": "v1.5.7",
"source": {
"type": "git",
"url": "https://github.com/catfan/Medoo.git",
"reference": "dd9d570584cfb1e09ec470608479b86e41d5b60d"
"reference": "8d90cba0e8ff176028847527d0ea76fe41a06ecf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/dd9d570584cfb1e09ec470608479b86e41d5b60d",
"reference": "dd9d570584cfb1e09ec470608479b86e41d5b60d",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/8d90cba0e8ff176028847527d0ea76fe41a06ecf",
"reference": "8d90cba0e8ff176028847527d0ea76fe41a06ecf",
"shasum": ""
},
"require": {
@@ -77,7 +77,7 @@
"ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_pqsql": "For PostgreSQL database",
"ext-pdo_sqlite": "For SQLite database",
"ext-pdo_sqlsrv": "For MSSQL database on both Window/Liunx platform"
"ext-pdo_sqlsrv": "For MSSQL database"
},
"type": "framework",
"autoload": {
@@ -95,11 +95,10 @@
"email": "angel@catfan.me"
}
],
"description": "The lightweight PHP database framework to accelerate development",
"description": "The lightest PHP database framework to accelerate development",
"homepage": "https://medoo.in",
"keywords": [
"database",
"database library",
"lightweight",
"mariadb",
"mssql",
@@ -110,7 +109,7 @@
"sql",
"sqlite"
],
"time": "2019-12-19T05:04:34+00:00"
"time": "2018-06-14T18:59:08+00:00"
},
{
"name": "ezyang/htmlpurifier",
@@ -426,7 +425,6 @@
"scss",
"stylesheet"
],
"abandoned": "scssphp/scssphp",
"time": "2018-07-22T01:22:08+00:00"
},
{
-3
View File
@@ -1,3 +0,0 @@
# These are supported funding model platforms
open_collective: medoo
@@ -1,19 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
---
**Describe the bug**
A clear and concise description of what the bug is.
**Information**
- Version of Medoo:
- Type of Database (MySQL, MSSQL, SQLite...):
- System (Liunx\Windows\Mac):
**Detail Code**
The detail code causes the problem.
**Expected output**
A clear and concise description of what output you expected.
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 Angel Lai
Copyright (c) 2018 Angel Lai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+4 -6
View File
@@ -6,11 +6,9 @@
<a href="https://packagist.org/packages/catfan/medoo"><img alt="Total Downloads" src="https://poser.pugx.org/catfan/medoo/downloads"></a>
<a href="https://packagist.org/packages/catfan/medoo"><img alt="Latest Stable Version" src="https://poser.pugx.org/catfan/medoo/v/stable"></a>
<a href="https://packagist.org/packages/catfan/medoo"><img alt="License" src="https://poser.pugx.org/catfan/medoo/license"></a>
<a href="https://opencollective.com/medoo"><img alt="Backers on Open Collective" src="https://opencollective.com/Medoo/backers/badge.svg"></a>
<a href="https://opencollective.com/medoo"><img alt="Sponsors on Open Collective" src="https://opencollective.com/Medoo/sponsors/badge.svg"> </a>
</p>
> The lightweight PHP database framework to accelerate development
> The Lightest PHP database framework to accelerate development
## Features
@@ -28,7 +26,7 @@
## Requirement
PHP 5.4+ and PDO extension installed, recommend PHP 7.0+
PHP 5.4+ and PDO extension installed
## Get Started
@@ -36,7 +34,7 @@ PHP 5.4+ and PDO extension installed, recommend PHP 7.0+
Add Medoo to composer.json configuration file.
```
$ composer require catfan/medoo
$ composer require catfan/Medoo
```
And update the composer
@@ -45,7 +43,7 @@ $ composer update
```
```php
// If you installed via composer, just use this code to require autoloader on the top of your projects.
// If you installed via composer, just use this code to requrie autoloader on the top of your projects.
require 'vendor/autoload.php';
// Using Medoo namespace
+4 -4
View File
@@ -1,8 +1,8 @@
{
"name": "catfan/medoo",
"type": "framework",
"description": "The lightweight PHP database framework to accelerate development",
"keywords": ["database", "database library", "lightweight", "PHP framework", "SQL", "MySQL", "MSSQL", "SQLite", "PostgreSQL", "MariaDB", "Oracle"],
"description": "The lightest PHP database framework to accelerate development",
"keywords": ["database", "lightweight", "PHP framework", "SQL", "MySQL", "MSSQL", "SQLite", "PostgreSQL", "MariaDB", "Oracle"],
"homepage": "https://medoo.in",
"license": "MIT",
"support": {
@@ -18,10 +18,10 @@
},
"suggest": {
"ext-pdo_mysql": "For MySQL or MariaDB database",
"ext-pdo_sqlsrv": "For MSSQL database on both Window/Liunx platform",
"ext-pdo_sqlsrv": "For MSSQL database",
"ext-pdo_dblib": "For MSSQL or Sybase database on Linux/UNIX platform",
"ext-pdo_oci": "For Oracle database",
"ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_pqsql": "For PostgreSQL database",
"ext-pdo_sqlite": "For SQLite database"
},
+209 -503
View File
@@ -2,9 +2,9 @@
/*!
* Medoo database framework
* https://medoo.in
* Version 1.7.8
* Version 1.5.7
*
* Copyright 2019, Angel Lai
* Copyright 2018, Angel Lai
* Released under the MIT license
*/
@@ -13,7 +13,6 @@ namespace Medoo;
use PDO;
use Exception;
use PDOException;
use InvalidArgumentException;
class Raw {
public $map;
@@ -30,7 +29,7 @@ class Medoo
protected $statement;
protected $dsn;
protected $option = [];
protected $logs = [];
@@ -40,18 +39,16 @@ class Medoo
protected $guid = 0;
protected $errorInfo = null;
public function __construct(array $options)
public function __construct($options = null)
{
if (!is_array($options))
{
return false;
}
if (isset($options[ 'database_type' ]))
{
$this->type = strtolower($options[ 'database_type' ]);
if ($this->type === 'mariadb')
{
$this->type = 'mysql';
}
}
if (isset($options[ 'prefix' ]))
@@ -59,47 +56,23 @@ class Medoo
$this->prefix = $options[ 'prefix' ];
}
if (isset($options[ 'option' ]))
{
$this->option = $options[ 'option' ];
}
if (isset($options[ 'logging' ]) && is_bool($options[ 'logging' ]))
{
$this->logging = $options[ 'logging' ];
}
$option = isset($options[ 'option' ]) ? $options[ 'option' ] : [];
$commands = (isset($options[ 'command' ]) && is_array($options[ 'command' ])) ? $options[ 'command' ] : [];
switch ($this->type)
if (isset($options[ 'command' ]) && is_array($options[ 'command' ]))
{
case 'mysql':
// Make MySQL using standard quoted identifier
$commands[] = 'SET SQL_MODE=ANSI_QUOTES';
break;
case 'mssql':
// Keep MSSQL QUOTED_IDENTIFIER is ON for standard quoting
$commands[] = 'SET QUOTED_IDENTIFIER ON';
// Make ANSI_NULLS is ON for NULL value
$commands[] = 'SET ANSI_NULLS ON';
break;
$commands = $options[ 'command' ];
}
if (isset($options[ 'pdo' ]))
else
{
if (!$options[ 'pdo' ] instanceof PDO)
{
throw new InvalidArgumentException('Invalid PDO object supplied');
}
$this->pdo = $options[ 'pdo' ];
foreach ($commands as $value)
{
$this->pdo->exec($value);
}
return;
$commands = [];
}
if (isset($options[ 'dsn' ]))
@@ -110,7 +83,7 @@ class Medoo
}
else
{
throw new InvalidArgumentException('Invalid DSN option supplied');
return false;
}
}
else
@@ -127,6 +100,7 @@ class Medoo
switch ($this->type)
{
case 'mariadb':
case 'mysql':
$attr = [
'driver' => 'mysql',
@@ -147,6 +121,8 @@ class Medoo
}
}
// Make MySQL using standard quoted identifier
$commands[] = 'SET SQL_MODE=ANSI_QUOTES';
break;
case 'pgsql':
@@ -200,16 +176,6 @@ class Medoo
'host' => $options[ 'server' ] . ($is_port ? ':' . $port : ''),
'dbname' => $options[ 'database_name' ]
];
if (isset($options[ 'appname' ]))
{
$attr[ 'appname' ] = $options[ 'appname' ];
}
if (isset($options[ 'charset' ]))
{
$attr[ 'charset' ] = $options[ 'charset' ];
}
}
else
{
@@ -218,46 +184,13 @@ class Medoo
'Server' => $options[ 'server' ] . ($is_port ? ',' . $port : ''),
'Database' => $options[ 'database_name' ]
];
if (isset($options[ 'appname' ]))
{
$attr[ 'APP' ] = $options[ 'appname' ];
}
$config = [
'ApplicationIntent',
'AttachDBFileName',
'Authentication',
'ColumnEncryption',
'ConnectionPooling',
'Encrypt',
'Failover_Partner',
'KeyStoreAuthentication',
'KeyStorePrincipalId',
'KeyStoreSecret',
'LoginTimeout',
'MultipleActiveResultSets',
'MultiSubnetFailover',
'Scrollable',
'TraceFile',
'TraceOn',
'TransactionIsolation',
'TransparentNetworkIPResolution',
'TrustServerCertificate',
'WSID',
];
foreach ($config as $value)
{
$keyname = strtolower(preg_replace(['/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'], '$1_$2', $value));
if (isset($options[ $keyname ]))
{
$attr[ $value ] = $options[ $keyname ];
}
}
}
// Keep MSSQL QUOTED_IDENTIFIER is ON for standard quoting
$commands[] = 'SET QUOTED_IDENTIFIER ON';
// Make ANSI_NULLS is ON for NULL value
$commands[] = 'SET ANSI_NULLS ON';
break;
case 'sqlite':
@@ -270,18 +203,8 @@ class Medoo
}
}
if (!isset($attr))
{
throw new InvalidArgumentException('Incorrect connection options');
}
$driver = $attr[ 'driver' ];
if (!in_array($driver, PDO::getAvailableDrivers()))
{
throw new InvalidArgumentException("Unsupported PDO driver: {$driver}");
}
unset($attr[ 'driver' ]);
$stack = [];
@@ -291,27 +214,22 @@ class Medoo
$stack[] = is_int($key) ? $value : $key . '=' . $value;
}
$dsn = $driver . ':' . implode(';', $stack);
$dsn = $driver . ':' . implode($stack, ';');
if (
in_array($this->type, ['mysql', 'pgsql', 'sybase', 'mssql']) &&
in_array($this->type, ['mariadb', 'mysql', 'pgsql', 'sybase', 'mssql']) &&
isset($options[ 'charset' ])
)
{
$commands[] = "SET NAMES '{$options[ 'charset' ]}'" . (
$this->type === 'mysql' && isset($options[ 'collation' ]) ?
" COLLATE '{$options[ 'collation' ]}'" : ''
);
$commands[] = "SET NAMES '" . $options[ 'charset' ] . "'";
}
$this->dsn = $dsn;
try {
$this->pdo = new PDO(
$dsn,
isset($options[ 'username' ]) ? $options[ 'username' ] : null,
isset($options[ 'password' ]) ? $options[ 'password' ] : null,
$option
$this->option
);
foreach ($commands as $value)
@@ -324,6 +242,18 @@ class Medoo
}
}
public function __call($name, $arguments)
{
$aggregation = ['avg', 'count', 'max', 'min', 'sum'];
if (in_array($name, $aggregation))
{
array_unshift($arguments, $name);
return call_user_func_array([$this, 'aggregate'], $arguments);
}
}
public function query($query, $map = [])
{
$raw = $this->raw($query, $map);
@@ -335,8 +265,6 @@ class Medoo
public function exec($query, $map = [])
{
$this->statement = null;
if ($this->debug_mode)
{
echo $this->generate($query, $map);
@@ -357,37 +285,28 @@ class Medoo
$statement = $this->pdo->prepare($query);
if (!$statement)
if ($statement)
{
$this->errorInfo = $this->pdo->errorInfo();
$this->statement = null;
foreach ($map as $key => $value)
{
$statement->bindValue($key, $value[ 0 ], $value[ 1 ]);
}
return false;
$statement->execute();
$this->statement = $statement;
return $statement;
}
$this->statement = $statement;
foreach ($map as $key => $value)
{
$statement->bindValue($key, $value[ 0 ], $value[ 1 ]);
}
$execute = $statement->execute();
$this->errorInfo = $statement->errorInfo();
if (!$execute)
{
$this->statement = null;
}
return $statement;
return false;
}
protected function generate($query, $map)
{
$identifier = [
'mysql' => '`$1`',
'mariadb' => '`$1`',
'mssql' => '[$1]'
];
@@ -477,11 +396,6 @@ class Medoo
protected function tableQuote($table)
{
if (!preg_match('/^[a-zA-Z0-9_]+$/i', $table))
{
throw new InvalidArgumentException("Incorrect table name \"$table\"");
}
return '"' . $this->prefix . $table . '"';
}
@@ -516,11 +430,6 @@ class Medoo
protected function columnQuote($string)
{
if (!preg_match('/^[a-zA-Z0-9_]+(\.?[a-zA-Z0-9_]+)?$/i', $string))
{
throw new InvalidArgumentException("Incorrect column name \"$string\"");
}
if (strpos($string, '.') !== false)
{
return '"' . $this->prefix . str_replace('.', '"."', $string) . '"';
@@ -529,7 +438,7 @@ class Medoo
return '"' . $string . '"';
}
protected function columnPush(&$columns, &$map, $root, $is_join = false)
protected function columnPush(&$columns, &$map)
{
if ($columns === '*')
{
@@ -545,34 +454,23 @@ class Medoo
foreach ($columns as $key => $value)
{
if (!is_int($key) && is_array($value) && $root && count(array_keys($columns)) === 1)
if (is_array($value))
{
$stack[] = $this->columnQuote($key);
$stack[] = $this->columnPush($value, $map, false, $is_join);
}
elseif (is_array($value))
{
$stack[] = $this->columnPush($value, $map, false, $is_join);
$stack[] = $this->columnPush($value, $map);
}
elseif (!is_int($key) && $raw = $this->buildRaw($value, $map))
{
preg_match('/(?<column>[a-zA-Z0-9_\.]+)(\s*\[(?<type>(String|Bool|Int|Number))\])?/i', $key, $match);
$stack[] = $raw . ' AS ' . $this->columnQuote($match[ 'column' ]);
$stack[] = $raw . ' AS ' . $this->columnQuote( $match[ 'column' ] );
}
elseif (is_int($key) && is_string($value))
{
if ($is_join && strpos($value, '*') !== false)
{
throw new InvalidArgumentException('Cannot use table.* to select all columns while joining table');
}
preg_match('/(?<column>[a-zA-Z0-9_\.]+)(?:\s*\((?<alias>[a-zA-Z0-9_]+)\))?(?:\s*\[(?<type>(?:String|Bool|Int|Number|Object|JSON))\])?/i', $value, $match);
if (!empty($match[ 'alias' ]))
{
$stack[] = $this->columnQuote($match[ 'column' ]) . ' AS ' . $this->columnQuote($match[ 'alias' ]);
$stack[] = $this->columnQuote( $match[ 'column' ] ) . ' AS ' . $this->columnQuote( $match[ 'alias' ] );
$columns[ $key ] = $match[ 'alias' ];
@@ -583,12 +481,12 @@ class Medoo
}
else
{
$stack[] = $this->columnQuote($match[ 'column' ]);
$stack[] = $this->columnQuote( $match[ 'column' ] );
}
}
}
return implode(',', $stack);
return implode($stack, ',');
}
protected function arrayQuote($array)
@@ -600,7 +498,7 @@ class Medoo
$stack[] = is_int($value) ? $value : $this->pdo->quote($value);
}
return implode(',', $stack);
return implode($stack, ',');
}
protected function innerConjunct($data, $map, $conjunctor, $outer_conjunctor)
@@ -662,7 +560,7 @@ class Medoo
if (is_numeric($value))
{
$condition .= $map_key;
$map[ $map_key ] = [$value, is_float($value) ? PDO::PARAM_STR : PDO::PARAM_INT];
$map[ $map_key ] = [$value, PDO::PARAM_INT];
}
elseif ($raw = $this->buildRaw($value, $map))
{
@@ -689,10 +587,8 @@ class Medoo
foreach ($value as $index => $item)
{
$stack_key = $map_key . $index . '_i';
$placeholders[] = $stack_key;
$map[ $stack_key ] = $this->typeMap($item, gettype($item));
$placeholders[] = $map_key . $index . '_i';
$map[ $map_key . $index . '_i' ] = $this->typeMap($item, gettype($item));
}
$stack[] = $column . ' NOT IN (' . implode(', ', $placeholders) . ')';
@@ -739,7 +635,7 @@ class Medoo
{
$item = strval($item);
if (!preg_match('/(\[.+\]|[\*\?\!\%#^-_]|%.+|.+%)/', $item))
if (!preg_match('/(\[.+\]|_|%.+|.+%)/', $item))
{
$item = '%' . $item . '%';
}
@@ -786,10 +682,8 @@ class Medoo
foreach ($value as $index => $item)
{
$stack_key = $map_key . $index . '_i';
$placeholders[] = $stack_key;
$map[ $stack_key ] = $this->typeMap($item, gettype($item));
$placeholders[] = $map_key . $index . '_i';
$map[ $map_key . $index . '_i' ] = $this->typeMap($item, gettype($item));
}
$stack[] = $column . ' IN (' . implode(', ', $placeholders) . ')';
@@ -834,7 +728,7 @@ class Medoo
$where_clause = ' WHERE ' . $this->dataImplode($conditions, $map, ' AND');
}
if (isset($where[ 'MATCH' ]) && $this->type === 'mysql')
if (isset($where[ 'MATCH' ]))
{
$MATCH = $where[ 'MATCH' ];
@@ -854,7 +748,7 @@ class Medoo
$mode = ' ' . $mode_array[ $MATCH[ 'mode' ] ];
}
$columns = implode(', ', array_map([$this, 'columnQuote'], $MATCH[ 'columns' ]));
$columns = implode(array_map([$this, 'columnQuote'], $MATCH[ 'columns' ]), ', ');
$map_key = $this->mapKey();
$map[ $map_key ] = [$MATCH[ 'keyword' ], PDO::PARAM_STR];
@@ -875,7 +769,7 @@ class Medoo
$stack[] = $this->columnQuote($value);
}
$where_clause .= ' GROUP BY ' . implode(',', $stack);
$where_clause .= ' GROUP BY ' . implode($stack, ',');
}
elseif ($raw = $this->buildRaw($GROUP, $map))
{
@@ -923,7 +817,7 @@ class Medoo
}
}
$where_clause .= ' ORDER BY ' . implode(',', $stack);
$where_clause .= ' ORDER BY ' . implode($stack, ',');
}
elseif ($raw = $this->buildRaw($ORDER, $map))
{
@@ -1000,7 +894,6 @@ class Medoo
$table_query = $table;
}
$is_join = false;
$join_key = is_array($join) ? array_keys($join) : null;
if (
@@ -1008,8 +901,67 @@ class Medoo
strpos($join_key[ 0 ], '[') === 0
)
{
$is_join = true;
$table_query .= ' ' . $this->buildJoin($table, $join);
$table_join = [];
$join_array = [
'>' => 'LEFT',
'<' => 'RIGHT',
'<>' => 'FULL',
'><' => 'INNER'
];
foreach($join as $sub_table => $relation)
{
preg_match('/(\[(?<join>\<\>?|\>\<?)\])?(?<table>[a-zA-Z0-9_]+)\s?(\((?<alias>[a-zA-Z0-9_]+)\))?/', $sub_table, $match);
if ($match[ 'join' ] !== '' && $match[ 'table' ] !== '')
{
if (is_string($relation))
{
$relation = 'USING ("' . $relation . '")';
}
if (is_array($relation))
{
// For ['column1', 'column2']
if (isset($relation[ 0 ]))
{
$relation = 'USING ("' . implode($relation, '", "') . '")';
}
else
{
$joins = [];
foreach ($relation as $key => $value)
{
$joins[] = (
strpos($key, '.') > 0 ?
// For ['tableB.column' => 'column']
$this->columnQuote($key) :
// For ['column1' => 'column2']
$table . '."' . $key . '"'
) .
' = ' .
$this->tableQuote(isset($match[ 'alias' ]) ? $match[ 'alias' ] : $match[ 'table' ]) . '."' . $value . '"';
}
$relation = 'ON ' . implode($joins, ' AND ');
}
}
$table_name = $this->tableQuote($match[ 'table' ]) . ' ';
if (isset($match[ 'alias' ]))
{
$table_name .= 'AS ' . $this->tableQuote($match[ 'alias' ]) . ' ';
}
$table_join[] = $join_array[ $match[ 'join' ] ] . ' JOIN ' . $table_name . $relation;
}
}
$table_query .= ' ' . implode($table_join, ' ');
}
else
{
@@ -1047,10 +999,6 @@ class Medoo
$where = $columns;
}
}
elseif ($raw = $this->buildRaw($column_fn, $map))
{
$column = $raw;
}
else
{
if (empty($columns) || $this->isRaw($columns))
@@ -1059,83 +1007,18 @@ class Medoo
$where = $join;
}
$column = $column_fn . '(' . $this->columnPush($columns, $map, true) . ')';
$column = $column_fn . '(' . $this->columnPush($columns, $map) . ')';
}
}
else
{
$column = $this->columnPush($columns, $map, true, $is_join);
$column = $this->columnPush($columns, $map);
}
return 'SELECT ' . $column . ' FROM ' . $table_query . $this->whereClause($where, $map);
}
protected function buildJoin($table, $join)
{
$table_join = [];
$join_array = [
'>' => 'LEFT',
'<' => 'RIGHT',
'<>' => 'FULL',
'><' => 'INNER'
];
foreach($join as $sub_table => $relation)
{
preg_match('/(\[(?<join>\<\>?|\>\<?)\])?(?<table>[a-zA-Z0-9_]+)\s?(\((?<alias>[a-zA-Z0-9_]+)\))?/', $sub_table, $match);
if ($match[ 'join' ] !== '' && $match[ 'table' ] !== '')
{
if (is_string($relation))
{
$relation = 'USING ("' . $relation . '")';
}
if (is_array($relation))
{
// For ['column1', 'column2']
if (isset($relation[ 0 ]))
{
$relation = 'USING ("' . implode('", "', $relation) . '")';
}
else
{
$joins = [];
foreach ($relation as $key => $value)
{
$joins[] = (
strpos($key, '.') > 0 ?
// For ['tableB.column' => 'column']
$this->columnQuote($key) :
// For ['column1' => 'column2']
$table . '."' . $key . '"'
) .
' = ' .
$this->tableQuote(isset($match[ 'alias' ]) ? $match[ 'alias' ] : $match[ 'table' ]) . '."' . $value . '"';
}
$relation = 'ON ' . implode(' AND ', $joins);
}
}
$table_name = $this->tableQuote($match[ 'table' ]) . ' ';
if (isset($match[ 'alias' ]))
{
$table_name .= 'AS ' . $this->tableQuote($match[ 'alias' ]) . ' ';
}
$table_join[] = $join_array[ $match[ 'join' ] ] . ' JOIN ' . $table_name . $relation;
}
}
return implode(' ', $table_join);
}
protected function columnMap($columns, &$stack, $root)
protected function columnMap($columns, &$stack)
{
if ($columns === '*')
{
@@ -1178,52 +1061,15 @@ class Medoo
}
elseif (!is_int($key) && is_array($value))
{
if ($root && count(array_keys($columns)) === 1)
{
$stack[ $key ] = [$key, 'String'];
}
$this->columnMap($value, $stack, false);
$this->columnMap($value, $stack);
}
}
return $stack;
}
protected function dataMap($data, $columns, $column_map, &$stack, $root, &$result)
protected function dataMap($data, $columns, $column_map, &$stack)
{
if ($root)
{
$columns_key = array_keys($columns);
if (count($columns_key) === 1 && is_array($columns[$columns_key[0]]))
{
$index_key = array_keys($columns)[0];
$data_key = preg_replace("/^[a-zA-Z0-9_]+\./i", "", $index_key);
$current_stack = [];
foreach ($data as $item)
{
$this->dataMap($data, $columns[ $index_key ], $column_map, $current_stack, false, $result);
$index = $data[ $data_key ];
$result[ $index ] = $current_stack;
}
}
else
{
$current_stack = [];
$this->dataMap($data, $columns, $column_map, $current_stack, false, $result);
$result[] = $current_stack;
}
return;
}
foreach ($columns as $key => $value)
{
$isRaw = $this->isRaw($value);
@@ -1234,7 +1080,7 @@ class Medoo
$column_key = $map[ 0 ];
$item = $data[ $column_key ];
$result = $data[ $column_key ];
if (isset($map[ 1 ]))
{
@@ -1243,7 +1089,7 @@ class Medoo
continue;
}
if (is_null($item))
if (is_null($result))
{
$stack[ $column_key ] = null;
continue;
@@ -1252,103 +1098,50 @@ class Medoo
switch ($map[ 1 ])
{
case 'Number':
$stack[ $column_key ] = (double) $item;
$stack[ $column_key ] = (double) $result;
break;
case 'Int':
$stack[ $column_key ] = (int) $item;
$stack[ $column_key ] = (int) $result;
break;
case 'Bool':
$stack[ $column_key ] = (bool) $item;
$stack[ $column_key ] = (bool) $result;
break;
case 'Object':
$stack[ $column_key ] = unserialize($item);
$stack[ $column_key ] = unserialize($result);
break;
case 'JSON':
$stack[ $column_key ] = json_decode($item, true);
$stack[ $column_key ] = json_decode($result, true);
break;
case 'String':
$stack[ $column_key ] = $item;
$stack[ $column_key ] = $result;
break;
}
}
else
{
$stack[ $column_key ] = $item;
$stack[ $column_key ] = $result;
}
}
else
{
$current_stack = [];
$this->dataMap($data, $value, $column_map, $current_stack, false, $result);
$this->dataMap($data, $value, $column_map, $current_stack);
$stack[ $key ] = $current_stack;
}
}
}
public function create($table, $columns, $options = null)
{
$stack = [];
$tableName = $this->prefix . $table;
foreach ($columns as $name => $definition)
{
if (is_int($name))
{
$stack[] = preg_replace('/\<([a-zA-Z0-9_]+)\>/i', '"$1"', $definition);
}
elseif (is_array($definition))
{
$stack[] = $name . ' ' . implode(' ', $definition);
}
elseif (is_string($definition))
{
$stack[] = $name . ' ' . $this->query($definition);
}
}
$table_option = '';
if (is_array($options))
{
$option_stack = [];
foreach ($options as $key => $value)
{
if (is_string($value) || is_int($value))
{
$option_stack[] = "$key = $value";
}
}
$table_option = ' ' . implode(', ', $option_stack);
}
elseif (is_string($options))
{
$table_option = ' ' . $options;
}
return $this->exec("CREATE TABLE IF NOT EXISTS $tableName (" . implode(', ', $stack) . ")$table_option");
}
public function drop($table)
{
$tableName = $this->prefix . $table;
return $this->exec("DROP TABLE IF EXISTS $tableName");
}
public function select($table, $join, $columns = null, $where = null)
{
$map = [];
$result = [];
$stack = [];
$column_map = [];
$index = 0;
@@ -1359,9 +1152,9 @@ class Medoo
$query = $this->exec($this->selectContext($table, $map, $join, $columns, $where), $map);
$this->columnMap($columns, $column_map, true);
$this->columnMap($columns, $column_map);
if (!$this->statement)
if (!$query)
{
return false;
}
@@ -1371,27 +1164,23 @@ class Medoo
return $query->fetchAll(PDO::FETCH_ASSOC);
}
if ($is_single)
{
return $query->fetchAll(PDO::FETCH_COLUMN);
}
while ($data = $query->fetch(PDO::FETCH_ASSOC))
{
$current_stack = [];
$this->dataMap($data, $columns, $column_map, $current_stack, true, $result);
$this->dataMap($data, $columns, $column_map, $current_stack);
$stack[ $index ] = $current_stack;
$index++;
}
if ($is_single)
{
$single_result = [];
$result_key = $column_map[ $column ][ 0 ];
foreach ($result as $item)
{
$single_result[] = $item[ $result_key ];
}
return $single_result;
}
return $result;
return $stack;
}
public function insert($table, $datas)
@@ -1428,7 +1217,7 @@ class Medoo
continue;
}
$map_key = $this->mapKey();
$map_key =$this->mapKey();
$values[] = $map_key;
@@ -1468,7 +1257,7 @@ class Medoo
}
}
$stack[] = '(' . implode(', ', $values) . ')';
$stack[] = '(' . implode($values, ', ') . ')';
}
foreach ($columns as $key)
@@ -1584,9 +1373,8 @@ class Medoo
public function get($table, $join = null, $columns = null, $where = null)
{
$map = [];
$result = [];
$stack = [];
$column_map = [];
$current_stack = [];
if ($where === null)
{
@@ -1603,31 +1391,33 @@ class Medoo
$query = $this->exec($this->selectContext($table, $map, $join, $columns, $where) . ' LIMIT 1', $map);
if (!$this->statement)
if ($query)
{
$data = $query->fetchAll(PDO::FETCH_ASSOC);
if (isset($data[ 0 ]))
{
if ($column === '*')
{
return $data[ 0 ];
}
$this->columnMap($columns, $column_map);
$this->dataMap($data[ 0 ], $columns, $column_map, $stack);
if ($is_single)
{
return $stack[ $column_map[ $column ][ 0 ] ];
}
return $stack;
}
return false;
}
$data = $query->fetchAll(PDO::FETCH_ASSOC);
if (isset($data[ 0 ]))
{
if ($column === '*')
{
return $data[ 0 ];
}
$this->columnMap($columns, $column_map, true);
$this->dataMap($data[ 0 ], $columns, $column_map, $current_stack, true, $result);
if ($is_single)
{
return $result[ 0 ][ $column_map[ $column ][ 0 ] ];
}
return $result[ 0 ];
}
return false;
}
public function has($table, $join, $where = null)
@@ -1635,66 +1425,16 @@ class Medoo
$map = [];
$column = null;
if ($this->type === 'mssql')
$query = $this->exec('SELECT EXISTS(' . $this->selectContext($table, $map, $join, $column, $where, 1) . ')', $map);
if ($query)
{
$query = $this->exec($this->selectContext($table, $map, $join, $column, $where, Medoo::raw('TOP 1 1')), $map);
}
else
{
$query = $this->exec('SELECT EXISTS(' . $this->selectContext($table, $map, $join, $column, $where, 1) . ')', $map);
$result = $query->fetchColumn();
return $result === '1' || $result === true;
}
if (!$this->statement)
{
return false;
}
$result = $query->fetchColumn();
return $result === '1' || $result === 1 || $result === true;
}
public function rand($table, $join = null, $columns = null, $where = null)
{
$type = $this->type;
$order = 'RANDOM()';
if ($type === 'mysql')
{
$order = 'RAND()';
}
elseif ($type === 'mssql')
{
$order = 'NEWID()';
}
$order_raw = $this->raw($order);
if ($where === null)
{
if ($columns === null)
{
$columns = [
'ORDER' => $order_raw
];
}
else
{
$column = $join;
unset($columns[ 'ORDER' ]);
$columns[ 'ORDER' ] = $order_raw;
}
}
else
{
unset($where[ 'ORDER' ]);
$where[ 'ORDER' ] = $order_raw;
}
return $this->select($table, $join, $columns, $where);
return false;
}
private function aggregate($type, $table, $join = null, $column = null, $where = null)
@@ -1703,39 +1443,14 @@ class Medoo
$query = $this->exec($this->selectContext($table, $map, $join, $column, $where, strtoupper($type)), $map);
if (!$this->statement)
if ($query)
{
return false;
$number = $query->fetchColumn();
return is_numeric($number) ? $number + 0 : $number;
}
$number = $query->fetchColumn();
return is_numeric($number) ? $number + 0 : $number;
}
public function count($table, $join = null, $column = null, $where = null)
{
return $this->aggregate('count', $table, $join, $column, $where);
}
public function avg($table, $join, $column = null, $where = null)
{
return $this->aggregate('avg', $table, $join, $column, $where);
}
public function max($table, $join, $column = null, $where = null)
{
return $this->aggregate('max', $table, $join, $column, $where);
}
public function min($table, $join, $column = null, $where = null)
{
return $this->aggregate('min', $table, $join, $column, $where);
}
public function sum($table, $join, $column = null, $where = null)
{
return $this->aggregate('sum', $table, $join, $column, $where);
return false;
}
public function action($actions)
@@ -1770,30 +1485,22 @@ class Medoo
public function id()
{
if ($this->statement == null)
{
return null;
}
$type = $this->type;
if ($type === 'oracle')
{
return 0;
}
elseif ($type === 'mssql')
{
return $this->pdo->query('SELECT SCOPE_IDENTITY()')->fetchColumn();
}
elseif ($type === 'pgsql')
{
return $this->pdo->query('SELECT LASTVAL()')->fetchColumn();
}
$lastId = $this->pdo->lastInsertId();
if ($lastId != "0" && $lastId != "")
{
return $lastId;
}
return null;
return $this->pdo->lastInsertId();
}
public function debug()
@@ -1805,7 +1512,7 @@ class Medoo
public function error()
{
return $this->errorInfo;
return $this->statement ? $this->statement->errorInfo() : null;
}
public function last()
@@ -1840,8 +1547,7 @@ class Medoo
$output[ $key ] = @$this->pdo->getAttribute(constant('PDO::ATTR_' . $value));
}
$output[ 'dsn' ] = $this->dsn;
return $output;
}
}
}
?>
+3
View File
@@ -23,4 +23,7 @@ return array(
'MeekroDBEval' => $vendorDir . '/sergeytsalkov/meekrodb/db.class.php',
'MeekroDBException' => $vendorDir . '/sergeytsalkov/meekrodb/db.class.php',
'WhereClause' => $vendorDir . '/sergeytsalkov/meekrodb/db.class.php',
'kakao\\KakaoKey' => $baseDir . '/d_setting/KakaoKey.php',
'sammo\\RootDB' => $baseDir . '/d_setting/RootDB.php',
'sammo\\ServConfig' => $baseDir . '/d_setting/ServConfig.php',
);
+3
View File
@@ -155,6 +155,9 @@ class ComposerStaticInit67b09c83b85c3bc0027caefe5bba171a
'MeekroDBEval' => __DIR__ . '/..' . '/sergeytsalkov/meekrodb/db.class.php',
'MeekroDBException' => __DIR__ . '/..' . '/sergeytsalkov/meekrodb/db.class.php',
'WhereClause' => __DIR__ . '/..' . '/sergeytsalkov/meekrodb/db.class.php',
'kakao\\KakaoKey' => __DIR__ . '/../..' . '/d_setting/KakaoKey.php',
'sammo\\RootDB' => __DIR__ . '/../..' . '/d_setting/RootDB.php',
'sammo\\ServConfig' => __DIR__ . '/../..' . '/d_setting/ServConfig.php',
);
public static function getInitializer(ClassLoader $loader)
+9 -11
View File
@@ -49,17 +49,17 @@
},
{
"name": "catfan/medoo",
"version": "v1.7.8",
"version_normalized": "1.7.8.0",
"version": "v1.5.7",
"version_normalized": "1.5.7.0",
"source": {
"type": "git",
"url": "https://github.com/catfan/Medoo.git",
"reference": "dd9d570584cfb1e09ec470608479b86e41d5b60d"
"reference": "8d90cba0e8ff176028847527d0ea76fe41a06ecf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/dd9d570584cfb1e09ec470608479b86e41d5b60d",
"reference": "dd9d570584cfb1e09ec470608479b86e41d5b60d",
"url": "https://api.github.com/repos/catfan/Medoo/zipball/8d90cba0e8ff176028847527d0ea76fe41a06ecf",
"reference": "8d90cba0e8ff176028847527d0ea76fe41a06ecf",
"shasum": ""
},
"require": {
@@ -73,9 +73,9 @@
"ext-pdo_oci8": "For Oracle version 8 database",
"ext-pdo_pqsql": "For PostgreSQL database",
"ext-pdo_sqlite": "For SQLite database",
"ext-pdo_sqlsrv": "For MSSQL database on both Window/Liunx platform"
"ext-pdo_sqlsrv": "For MSSQL database"
},
"time": "2019-12-19T05:04:34+00:00",
"time": "2018-06-14T18:59:08+00:00",
"type": "framework",
"installation-source": "dist",
"autoload": {
@@ -93,11 +93,10 @@
"email": "angel@catfan.me"
}
],
"description": "The lightweight PHP database framework to accelerate development",
"description": "The lightest PHP database framework to accelerate development",
"homepage": "https://medoo.in",
"keywords": [
"database",
"database library",
"lightweight",
"mariadb",
"mssql",
@@ -435,8 +434,7 @@
"sass",
"scss",
"stylesheet"
],
"abandoned": "scssphp/scssphp"
]
},
{
"name": "league/plates",