Skip to content

Commit c7e5256

Browse files
committed
First version;
0 parents  commit c7e5256

25 files changed

+2579
-0
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Ignore all test and documentation for archive
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore
4+
/.scrutinizer.yml export-ignore
5+
/.travis.yml export-ignore
6+
/phpunit.xml.dist export-ignore
7+
/tests export-ignore
8+
/docs export-ignore

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# phpstorm project files
2+
.idea
3+
4+
# netbeans project files
5+
nbproject
6+
7+
# zend studio for eclipse project files
8+
.buildpath
9+
.project
10+
.settings
11+
12+
# windows thumbnail cache
13+
Thumbs.db
14+
15+
# composer vendor dir
16+
/vendor
17+
18+
/composer.lock
19+
20+
# composer itself is not needed
21+
composer.phar
22+
23+
# Mac DS_Store Files
24+
.DS_Store
25+
26+
# phpunit itself is not needed
27+
phpunit.phar
28+
# local phpunit config
29+
/phpunit.xml
30+
31+
# local tests configuration
32+
/tests/data/config.local.php
33+
34+
# runtime cache
35+
/tests/runtime

.travis.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
- nightly
9+
10+
env:
11+
- FB=2.1
12+
- FB=2.5
13+
14+
# run build against hhvm but allow them to fail
15+
# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail
16+
matrix:
17+
fast_finish: true
18+
allow_failures:
19+
- php: 7.0
20+
- php: nightly
21+
22+
# faster builds on new travis setup not using sudo
23+
sudo: true
24+
25+
# cache vendor dirs
26+
cache:
27+
directories:
28+
- $HOME/.composer/cache
29+
30+
before_install:
31+
- sudo apt-get update -qq
32+
- sudo apt-get install -qq firebird$FB-super firebird$FB-dev expect
33+
- if [[ "$FB" == "2.1" ]]; then export DEBIAN_FRONTEND=readline; fi
34+
- if [[ "$FB" == "2.1" ]]; then expect tests/ci/travis/dpkg_firebird2.1.exp; fi
35+
- if [[ "$FB" == "2.1" ]]; then export DEBIAN_FRONTEND=dialog; fi
36+
- if [[ "$FB" == "2.5" ]]; then export FIREBIRD_SERVER_CONFIG=/etc/default/firebird$FB; fi
37+
- if [[ "$FB" == "2.5" ]]; then sudo sed /ENABLE_FIREBIRD_SERVER=/s/no/yes/ -i $FIREBIRD_SERVER_CONFIG; fi
38+
- if [[ "$FB" == "2.5" ]]; then cat $FIREBIRD_SERVER_CONFIG | grep ENABLE_FIREBIRD_SERVER; fi
39+
- sudo service firebird$FB-super start
40+
- export URL_SVN_EXT=https://github.com/php/php-src/branches/PHP-$(phpenv version-name)/ext
41+
- if [[ $(phpenv version-name) == "7.0" ]]; then export URL_SVN_EXT="https://github.com/php/php-src/branches/PHP-7.0.0/ext"; fi
42+
- if [[ $(phpenv version-name) == "nightly" ]]; then export URL_SVN_EXT="https://github.com/php/php-src/trunk/ext"; fi
43+
- svn checkout $URL_SVN_EXT php-ext -q
44+
- (cd php-ext/pdo_firebird/; phpize && ./configure && make && sudo make install)
45+
46+
install:
47+
- echo "extension=pdo_firebird.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
48+
- travis_retry composer self-update && composer --version
49+
- travis_retry composer global require "fxp/composer-asset-plugin:~1.0.0"
50+
- export PATH="$HOME/.composer/vendor/bin:$PATH"
51+
- travis_retry composer install --prefer-dist --no-interaction
52+
53+
before_script:
54+
# show some versions and env information
55+
- isql-fb -z -q -i /dev/null
56+
# initialize databases
57+
- echo "CREATE DATABASE 'localhost:/tmp/TEST.FDB' USER 'SYSDBA' PASSWORD 'masterkey' PAGE_SIZE 16384 DEFAULT CHARACTER SET UTF8;" > /tmp/create_test.sql
58+
- isql-fb -i /tmp/create_test.sql
59+
- cat /tmp/create_test.sql
60+
61+
script:
62+
- phpunit

ColumnSchema.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* @link http://www.yiiframework.com/
5+
* @copyright Copyright (c) 2008 Yii Software LLC
6+
* @license http://www.yiiframework.com/license/
7+
*/
8+
9+
namespace edgardmessias\db\firebird;
10+
11+
/**
12+
*
13+
* @author Edgard Lorraine Messias <[email protected]>
14+
* @since 2.0
15+
*/
16+
class ColumnSchema extends \yii\db\ColumnSchema
17+
{
18+
19+
/**
20+
* Converts the input value according to [[phpType]] after retrieval from the database.
21+
* If the value is null or an [[Expression]], it will not be converted.
22+
* @param mixed $value input value
23+
* @return mixed converted value
24+
* @since 2.0.3
25+
*/
26+
protected function typecast($value)
27+
{
28+
29+
if ($value === '' && $this->type !== Schema::TYPE_TEXT && $this->type !== Schema::TYPE_STRING && $this->type !== Schema::TYPE_BINARY) {
30+
return null;
31+
}
32+
if ($value === null || gettype($value) === $this->phpType || $value instanceof Expression) {
33+
return $value;
34+
}
35+
36+
switch ($this->phpType) {
37+
case 'resource':
38+
case 'string':
39+
if (is_resource($value)) {
40+
return $value;
41+
}
42+
if (is_float($value)) {
43+
// ensure type cast always has . as decimal separator in all locales
44+
return str_replace(',', '.', (string) $value);
45+
}
46+
return (string) $value;
47+
case 'integer':
48+
if (is_bool($value)) {
49+
return ($value) ? 1 : 0;
50+
}
51+
return (int) $value;
52+
case 'boolean':
53+
return (boolean) $value;
54+
case 'double':
55+
return (double) $value;
56+
}
57+
58+
return $value;
59+
}
60+
}

Command.php

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
<?php
2+
3+
/**
4+
* @link http://www.yiiframework.com/
5+
* @copyright Copyright (c) 2008 Yii Software LLC
6+
* @license http://www.yiiframework.com/license/
7+
*/
8+
9+
namespace edgardmessias\db\firebird;
10+
11+
/**
12+
*
13+
* @author Edgard Lorraine Messias <[email protected]>
14+
* @since 2.0
15+
*/
16+
class Command extends \yii\db\Command
17+
{
18+
19+
/**
20+
* @var array pending parameters to be bound to the current PDO statement.
21+
*/
22+
private $_pendingParams = [];
23+
24+
/**
25+
* @var string the SQL statement that this command represents
26+
*/
27+
private $_sql;
28+
29+
/**
30+
* Binds a parameter to the SQL statement to be executed.
31+
* @param string|integer $name parameter identifier. For a prepared statement
32+
* using named placeholders, this will be a parameter name of
33+
* the form `:name`. For a prepared statement using question mark
34+
* placeholders, this will be the 1-indexed position of the parameter.
35+
* @param mixed $value Name of the PHP variable to bind to the SQL statement parameter
36+
* @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
37+
* @param integer $length length of the data type
38+
* @param mixed $driverOptions the driver-specific options
39+
* @return static the current command being executed
40+
* @see http://www.php.net/manual/en/function.PDOStatement-bindParam.php
41+
*/
42+
public function bindParam($name, &$value, $dataType = null, $length = null, $driverOptions = null)
43+
{
44+
if ($dataType == \PDO::PARAM_BOOL) {
45+
$dataType = \PDO::PARAM_INT;
46+
}
47+
return parent::bindParam($name, $value, $dataType, $length, $driverOptions);
48+
}
49+
/**
50+
* Binds pending parameters that were registered via [[bindValue()]] and [[bindValues()]].
51+
* Note that this method requires an active [[pdoStatement]].
52+
*/
53+
protected function bindPendingParams()
54+
{
55+
foreach ($this->_pendingParams as $name => $value) {
56+
// var_dump($value);
57+
if ($value[1] == 'blob') {
58+
$this->pdoStatement->bindParam($name, $value[0]);
59+
} else {
60+
$this->pdoStatement->bindValue($name, $value[0], $value[1]);
61+
}
62+
}
63+
$this->_pendingParams = [];
64+
}
65+
66+
/**
67+
* Returns the SQL statement for this command.
68+
* @return string the SQL statement to be executed
69+
*/
70+
public function getSql()
71+
{
72+
return $this->_sql;
73+
}
74+
75+
/**
76+
* Specifies the SQL statement to be executed.
77+
* The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
78+
* @param string $sql the SQL statement to be set.
79+
* @return static this command instance
80+
*/
81+
public function setSql($sql)
82+
{
83+
if ($sql !== $this->_sql) {
84+
$this->cancel();
85+
$this->_sql = $this->db->quoteSql($sql);
86+
$this->_pendingParams = [];
87+
$this->params = [];
88+
}
89+
90+
return $this;
91+
}
92+
93+
/**
94+
* Returns the raw SQL by inserting parameter values into the corresponding placeholders in [[sql]].
95+
* Note that the return value of this method should mainly be used for logging purpose.
96+
* It is likely that this method returns an invalid SQL due to improper replacement of parameter placeholders.
97+
* @return string the raw SQL with parameter values inserted into the corresponding placeholders in [[sql]].
98+
*/
99+
public function getRawSql()
100+
{
101+
if (empty($this->params)) {
102+
return $this->_sql;
103+
}
104+
$params = [];
105+
foreach ($this->params as $name => $value) {
106+
if (is_string($value)) {
107+
$params[$name] = $this->db->quoteValue($value);
108+
} elseif ($value === null) {
109+
$params[$name] = 'NULL';
110+
} elseif (!is_object($value) && !is_resource($value)) {
111+
$params[$name] = $value;
112+
}
113+
}
114+
if (!isset($params[1])) {
115+
return strtr($this->_sql, $params);
116+
}
117+
$sql = '';
118+
foreach (explode('?', $this->_sql) as $i => $part) {
119+
$sql .= (isset($params[$i]) ? $params[$i] : '') . $part;
120+
}
121+
122+
return $sql;
123+
}
124+
125+
/**
126+
* Binds a value to a parameter.
127+
* @param string|integer $name Parameter identifier. For a prepared statement
128+
* using named placeholders, this will be a parameter name of
129+
* the form `:name`. For a prepared statement using question mark
130+
* placeholders, this will be the 1-indexed position of the parameter.
131+
* @param mixed $value The value to bind to the parameter
132+
* @param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
133+
* @return static the current command being executed
134+
* @see http://www.php.net/manual/en/function.PDOStatement-bindValue.php
135+
*/
136+
public function bindValue($name, $value, $dataType = null)
137+
{
138+
if ($dataType === null) {
139+
$dataType = $this->db->getSchema()->getPdoType($value);
140+
}
141+
if ($dataType == \PDO::PARAM_BOOL) {
142+
$dataType = \PDO::PARAM_INT;
143+
}
144+
$this->_pendingParams[$name] = [$value, $dataType];
145+
$this->params[$name] = $value;
146+
147+
return $this;
148+
}
149+
150+
/**
151+
* Binds a list of values to the corresponding parameters.
152+
* This is similar to [[bindValue()]] except that it binds multiple values at a time.
153+
* Note that the SQL data type of each value is determined by its PHP type.
154+
* @param array $values the values to be bound. This must be given in terms of an associative
155+
* array with array keys being the parameter names, and array values the corresponding parameter values,
156+
* e.g. `[':name' => 'John', ':age' => 25]`. By default, the PDO type of each value is determined
157+
* by its PHP type. You may explicitly specify the PDO type by using an array: `[value, type]`,
158+
* e.g. `[':name' => 'John', ':profile' => [$profile, \PDO::PARAM_LOB]]`.
159+
* @return static the current command being executed
160+
*/
161+
public function bindValues($values)
162+
{
163+
if (empty($values)) {
164+
return $this;
165+
}
166+
167+
$schema = $this->db->getSchema();
168+
foreach ($values as $name => $value) {
169+
if (is_array($value)) {
170+
$this->_pendingParams[$name] = $value;
171+
$this->params[$name] = $value[0];
172+
} else {
173+
$type = $schema->getPdoType($value);
174+
$this->_pendingParams[$name] = [$value, $type];
175+
$this->params[$name] = $value;
176+
}
177+
}
178+
179+
return $this;
180+
}
181+
}

0 commit comments

Comments
 (0)