Skip to content

Commit

Permalink
v0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kristuff authored Sep 25, 2020
2 parents b239c1d + 6e7e687 commit e03691a
Show file tree
Hide file tree
Showing 42 changed files with 349 additions and 95 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.tmp.php
vendor/*
_old/*
_tmp/*
1 change: 0 additions & 1 deletion .gitignore/.gitignore

This file was deleted.

9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ php:

services:
- mysql
- postgresql
- postgresql

before_install:
- composer install
- cd tests

before_script:
# - psql -c "DROP DATABASE IF EXISTS patabaseTest;" -U postgres
# - mysql -e "DROP DATABASE IF EXISTS patabaseTest;" -u root
- psql -c "DROP DATABASE IF EXISTS patabaseTest;" -U postgres
- psql -c "DROP DATABASE IF EXISTS patabase" -U postgres
- mysql -e "DROP DATABASE IF EXISTS patabaseTest;" -u root
- mysql -e "DROP DATABASE IF EXISTS patabase;" -u root


script:
- ../vendor/bin/phpunit --debug --configuration phpunit.xml --coverage-text --coverage-clover=coverage.xml
Expand Down
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.


## [v0.4] - 2020-09-25

### Added
- Support for MIN select query.
- Support for MAX select query.

## [v0.3] - 2020-04-23

### Changed
Expand All @@ -22,5 +28,3 @@ All notable changes to this project will be documented in this file.

### Initial release
- Support for Sqlite, Mysql, Postgresql


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SQL Features
Database queries:
```
- SELECT FROM:
DISTINCT, all / column(s), columns(s)/alias, function(COUNT, SUM), sub select,
DISTINCT, all / column(s), columns(s)/alias, function(COUNT, SUM, MIN, MAX), sub select,
JOIN (INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN (*), FULL OUTER JOIN (*))
WHERE (=, !=, <, <=, >, >=, IN, NOT IN, NULL, NOT NULL),
GROUP BY,
Expand Down
2 changes: 1 addition & 1 deletion lib/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/Datasource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
*
* @copyright 2017-2020 Kristuff
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
*
* @copyright 2017-2020 Kristuff
*/
Expand All @@ -33,7 +33,7 @@
*/
abstract class DatabaseDriver
{
/**
/**
* PDO connection
*
* @access protected
Expand Down Expand Up @@ -74,9 +74,9 @@ abstract class DatabaseDriver
* @var string
*/
public function sqlCreateTableOptions()
{
{
return '';
}
}

/**
* Gets/returns the default output format
Expand Down Expand Up @@ -368,11 +368,11 @@ abstract public function sqlShowTables();
* Get the SQL for RANDOM function
*
* @access public
* @param string $seed The seed for random function
* @param mixed $seed The seed for random function
*
* @return string
*/
abstract public function sqlRandom($seed);
abstract public function sqlRandom();

/**
* Get the SQL for auto increment column
Expand Down
3 changes: 1 addition & 2 deletions lib/Driver/DriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Driver;

use Kristuff\Patabase;
use Kristuff\Patabase\Driver;
use Kristuff\Patabase\Exception;

Expand Down
17 changes: 12 additions & 5 deletions lib/Driver/Mysql/MysqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
*
* @copyright 2017-2020 Kristuff
*/
Expand Down Expand Up @@ -88,15 +88,21 @@ public function createConnection(array $settings)
$charset = !empty($settings['charset']) ? ';charset='.$settings['charset'] : ';charset=utf8';
$port = !empty($settings['port']) ? ';port='.$settings['port'] : '';
$dbname = !empty($settings['database']) ? ';dbname='.$settings['database'] : '';
$options = [
// \PDO::ATTR_EMULATE_PREPARES => false,
];

$this->pdo = new \PDO(
'mysql:host='.$settings['hostname'] .$port .$dbname .$charset,
$settings['username'],
$settings['password'],
array()
$options
);

//TODO options, shema...
// emulate prepare is true by default in mysql
// TODO
// $this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
// $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}

/**
Expand Down Expand Up @@ -196,11 +202,12 @@ public function databaseExists($databaseName)
*
* @access public
* @param string $databaseName The database name
* @param string $owner (optional) The database owner. This parameter is not honored in Mysql.
* @param string $owner The database owner. This parameter is not honored in Mysql
* but needed for compatibility.
*
* @return bool True if the database has been created, otherwise false.
*/
public function createDatabase($databaseName, $owner = null)
public function createDatabase($databaseName, $owner)
{
$sql = trim(sprintf('CREATE DATABASE %s', $this->escape($databaseName)));
return $this->prepareAndExecuteSql($sql);
Expand Down
11 changes: 7 additions & 4 deletions lib/Driver/Postgres/PostgresDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down Expand Up @@ -110,7 +110,10 @@ public function createConnection(array $settings)
$settings['password'],
array()
);
//TODO options, shema

// make sure emulate prepare is false
//$this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
//$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
}

/**
Expand Down Expand Up @@ -218,12 +221,12 @@ public function databaseExists($databaseName)
*
* @access public
* @param string $databaseName The database name
* @param string $owner (optional) The database owner.
* @param string $owner The database owner.
* @param string $template (optional) The template to use. Default is 'template0'
*
* @return bool True if the database has been created, otherwise false.
*/
public function createDatabase($databaseName, $owner = null, $template = 'template0')
public function createDatabase($databaseName, $owner, $template = 'template0')
{
$sql = trim(sprintf('CREATE DATABASE %s %s TEMPLATE %s',
$this->escape($databaseName),
Expand Down
4 changes: 2 additions & 2 deletions lib/Driver/ServerDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down Expand Up @@ -65,7 +65,7 @@ abstract public function databaseExists($databaseName);
*
* @access public
* @param string $databaseName The database name.
* @param string $owner (optional) The database owner. This parameter is honored in pgsql only.
* @param string $owner The database owner. This parameter is honored in pgsql only.
*
* @return bool True if the database has been created, otherwise false.
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/Sqlite/SqliteDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
7 changes: 5 additions & 2 deletions lib/Driver/Sqlite/SqliteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down Expand Up @@ -63,9 +63,12 @@ public function createConnection(array $settings)
{
$this->pdo = new \PDO('sqlite:'.$settings['database']);

// https://www.sqlite.org/foreignkeys.html
//$this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
//$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

// Foreign key constraints are disabled by default (for backwards compatibility),
// so must be enabled separately for each database connection.
// @see https://www.sqlite.org/foreignkeys.html
$this->enableForeignKeys();
}

Expand Down
8 changes: 4 additions & 4 deletions lib/Exception/InvalidArgException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Exception;

use Kristuff\Patabase\Exception\PatabaseException;

/**
* Class InvalidArgException
*/
class InvalidArgException extends PatabaseException { }
class InvalidArgException extends \Kristuff\Patabase\Exception\PatabaseException
{
}
8 changes: 4 additions & 4 deletions lib/Exception/MissingArgException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

namespace Kristuff\Patabase\Exception;

use Kristuff\Patabase\Exception\PatabaseException;

/**
* Class MissingArgException
*/
class MissingArgException extends PatabaseException { }
class MissingArgException extends \Kristuff\Patabase\Exception\PatabaseException
{
}
6 changes: 4 additions & 2 deletions lib/Exception/PatabaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
*
* @copyright 2017-2020 Kristuff
*/
Expand All @@ -26,4 +26,6 @@
*
* Base class for library custom Exceptions
*/
class PatabaseException extends \Exception { }
class PatabaseException extends \Exception
{
}
2 changes: 1 addition & 1 deletion lib/Outpout.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
6 changes: 3 additions & 3 deletions lib/Query/CreateTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
*
* @copyright 2017-2020 Kristuff
*/
Expand All @@ -31,14 +31,14 @@
*
* Represents a [CREATE TABLE] SQL query
*/
class CreateTable extends Query\QueryBuilder
class CreateTable extends \Kristuff\Patabase\Query\QueryBuilder
{

/**
* Supported string keywords for defaults values
*
* @access private
* @var string $supportedDefaults
* @var array $supportedDefaults
*/
private $supportedDefaults = array('NULL', 'CURRENT_TIMESTAMP');

Expand Down
2 changes: 1 addition & 1 deletion lib/Query/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/Query/Having.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 0.3.0
* @version 0.4.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
Loading

0 comments on commit e03691a

Please sign in to comment.