Skip to content

Commit

Permalink
First version;
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jul 8, 2015
0 parents commit c7e5256
Show file tree
Hide file tree
Showing 25 changed files with 2,579 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore all test and documentation for archive
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/docs export-ignore
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# phpstorm project files
.idea

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# composer vendor dir
/vendor

/composer.lock

# composer itself is not needed
composer.phar

# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
/phpunit.xml

# local tests configuration
/tests/data/config.local.php

# runtime cache
/tests/runtime
62 changes: 62 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- nightly

env:
- FB=2.1
- FB=2.5

# run build against hhvm but allow them to fail
# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail
matrix:
fast_finish: true
allow_failures:
- php: 7.0
- php: nightly

# faster builds on new travis setup not using sudo
sudo: true

# cache vendor dirs
cache:
directories:
- $HOME/.composer/cache

before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq firebird$FB-super firebird$FB-dev expect
- if [[ "$FB" == "2.1" ]]; then export DEBIAN_FRONTEND=readline; fi
- if [[ "$FB" == "2.1" ]]; then expect tests/ci/travis/dpkg_firebird2.1.exp; fi
- if [[ "$FB" == "2.1" ]]; then export DEBIAN_FRONTEND=dialog; fi
- if [[ "$FB" == "2.5" ]]; then export FIREBIRD_SERVER_CONFIG=/etc/default/firebird$FB; fi
- if [[ "$FB" == "2.5" ]]; then sudo sed /ENABLE_FIREBIRD_SERVER=/s/no/yes/ -i $FIREBIRD_SERVER_CONFIG; fi
- if [[ "$FB" == "2.5" ]]; then cat $FIREBIRD_SERVER_CONFIG | grep ENABLE_FIREBIRD_SERVER; fi
- sudo service firebird$FB-super start
- export URL_SVN_EXT=https://github.com/php/php-src/branches/PHP-$(phpenv version-name)/ext
- if [[ $(phpenv version-name) == "7.0" ]]; then export URL_SVN_EXT="https://github.com/php/php-src/branches/PHP-7.0.0/ext"; fi
- if [[ $(phpenv version-name) == "nightly" ]]; then export URL_SVN_EXT="https://github.com/php/php-src/trunk/ext"; fi
- svn checkout $URL_SVN_EXT php-ext -q
- (cd php-ext/pdo_firebird/; phpize && ./configure && make && sudo make install)

install:
- echo "extension=pdo_firebird.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- travis_retry composer self-update && composer --version
- travis_retry composer global require "fxp/composer-asset-plugin:~1.0.0"
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer install --prefer-dist --no-interaction

before_script:
# show some versions and env information
- isql-fb -z -q -i /dev/null
# initialize databases
- echo "CREATE DATABASE 'localhost:/tmp/TEST.FDB' USER 'SYSDBA' PASSWORD 'masterkey' PAGE_SIZE 16384 DEFAULT CHARACTER SET UTF8;" > /tmp/create_test.sql
- isql-fb -i /tmp/create_test.sql
- cat /tmp/create_test.sql

script:
- phpunit
60 changes: 60 additions & 0 deletions ColumnSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace edgardmessias\db\firebird;

/**
*
* @author Edgard Lorraine Messias <[email protected]>
* @since 2.0
*/
class ColumnSchema extends \yii\db\ColumnSchema
{

/**
* Converts the input value according to [[phpType]] after retrieval from the database.
* If the value is null or an [[Expression]], it will not be converted.
* @param mixed $value input value
* @return mixed converted value
* @since 2.0.3
*/
protected function typecast($value)
{

if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
return null;
}
if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
return $value;
}

switch ($this->phpType) {
case 'resource':
case 'string':
if (is_resource($value)) {
return $value;
}
if (is_float($value)) {
// ensure type cast always has . as decimal separator in all locales
return str_replace(',', '.', (string) $value);
}
return (string) $value;
case 'integer':
if (is_bool($value)) {
return ($value) ? 1 : 0;
}
return (int) $value;
case 'boolean':
return (boolean) $value;
case 'double':
return (double) $value;
}

return $value;
}
}
181 changes: 181 additions & 0 deletions Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?php

/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace edgardmessias\db\firebird;

/**
*
* @author Edgard Lorraine Messias <[email protected]>
* @since 2.0
*/
class Command extends \yii\db\Command
{

/**
* @var array pending parameters to be bound to the current PDO statement.
*/
private $_pendingParams = [];

/**
* @var string the SQL statement that this command represents
*/
private $_sql;

/**
* Binds a parameter to the SQL statement to be executed.
* @param string|integer $name parameter identifier. For a prepared statement
* using named placeholders, this will be a parameter name of
* the form `:name`. For a prepared statement using question mark
* placeholders, this will be the 1-indexed position of the parameter.
* @param mixed $value Name of the PHP variable to bind to the SQL statement parameter
* @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
* @param integer $length length of the data type
* @param mixed $driverOptions the driver-specific options
* @return static the current command being executed
* @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php
*/
public function bindParam($name, &$value, $dataType = null, $length = null, $driverOptions = null)
{
if ($dataType == \PDO::PARAM_BOOL) {
$dataType = \PDO::PARAM_INT;
}
return parent::bindParam($name, $value, $dataType, $length, $driverOptions);
}
/**
* Binds pending parameters that were registered via [[bindValue()]] and [[bindValues()]].
* Note that this method requires an active [[pdoStatement]].
*/
protected function bindPendingParams()
{
foreach ($this->_pendingParams as $name => $value) {
// var_dump($value);
if ($value[1] == 'blob') {
$this->pdoStatement->bindParam($name, $value[0]);
} else {
$this->pdoStatement->bindValue($name, $value[0], $value[1]);
}
}
$this->_pendingParams = [];
}

/**
* Returns the SQL statement for this command.
* @return string the SQL statement to be executed
*/
public function getSql()
{
return $this->_sql;
}

/**
* Specifies the SQL statement to be executed.
* The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
* @param string $sql the SQL statement to be set.
* @return static this command instance
*/
public function setSql($sql)
{
if ($sql !== $this->_sql) {
$this->cancel();
$this->_sql = $this->db->quoteSql($sql);
$this->_pendingParams = [];
$this->params = [];
}

return $this;
}

/**
* Returns the raw SQL by inserting parameter values into the corresponding placeholders in [[sql]].
* Note that the return value of this method should mainly be used for logging purpose.
* It is likely that this method returns an invalid SQL due to improper replacement of parameter placeholders.
* @return string the raw SQL with parameter values inserted into the corresponding placeholders in [[sql]].
*/
public function getRawSql()
{
if (empty($this->params)) {
return $this->_sql;
}
$params = [];
foreach ($this->params as $name => $value) {
if (is_string($value)) {
$params[$name] = $this->db->quoteValue($value);
} elseif ($value === null) {
$params[$name] = 'NULL';
} elseif (!is_object($value) && !is_resource($value)) {
$params[$name] = $value;
}
}
if (!isset($params[1])) {
return strtr($this->_sql, $params);
}
$sql = '';
foreach (explode('?', $this->_sql) as $i => $part) {
$sql .= (isset($params[$i]) ? $params[$i] : '') . $part;
}

return $sql;
}

/**
* Binds a value to a parameter.
* @param string|integer $name Parameter identifier. For a prepared statement
* using named placeholders, this will be a parameter name of
* the form `:name`. For a prepared statement using question mark
* placeholders, this will be the 1-indexed position of the parameter.
* @param mixed $value The value to bind to the parameter
* @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
* @return static the current command being executed
* @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php
*/
public function bindValue($name, $value, $dataType = null)
{
if ($dataType === null) {
$dataType = $this->db->getSchema()->getPdoType($value);
}
if ($dataType == \PDO::PARAM_BOOL) {
$dataType = \PDO::PARAM_INT;
}
$this->_pendingParams[$name] = [$value, $dataType];
$this->params[$name] = $value;

return $this;
}

/**
* Binds a list of values to the corresponding parameters.
* This is similar to [[bindValue()]] except that it binds multiple values at a time.
* Note that the SQL data type of each value is determined by its PHP type.
* @param array $values the values to be bound. This must be given in terms of an associative
* array with array keys being the parameter names, and array values the corresponding parameter values,
* e.g. `[':name' => 'John', ':age' => 25]`. By default, the PDO type of each value is determined
* by its PHP type. You may explicitly specify the PDO type by using an array: `[value, type]`,
* e.g. `[':name' => 'John', ':profile' => [$profile, \PDO::PARAM_LOB]]`.
* @return static the current command being executed
*/
public function bindValues($values)
{
if (empty($values)) {
return $this;
}

$schema = $this->db->getSchema();
foreach ($values as $name => $value) {
if (is_array($value)) {
$this->_pendingParams[$name] = $value;
$this->params[$name] = $value[0];
} else {
$type = $schema->getPdoType($value);
$this->_pendingParams[$name] = [$value, $type];
$this->params[$name] = $value;
}
}

return $this;
}
}
Loading

0 comments on commit c7e5256

Please sign in to comment.