1
0

Commit changes to bundled-libs after Zend->Laminas rename

This commit is contained in:
Soatok Dreamseeker
2020-04-21 05:00:13 -04:00
committed by onli
parent e9f0864c8c
commit 7e98987b5a
501 changed files with 0 additions and 57840 deletions

View File

@ -1,5 +0,0 @@
#!/usr/bin/env bash
echo "Configure MySQL test database"
mysql --user=root --password=Password123 -e 'create database zenddb_test;'

View File

@ -1,5 +0,0 @@
#!/usr/bin/env bash
echo "Configure MySQL test database"
mysql -u root -e 'create database zenddb_test;'

View File

@ -1,6 +0,0 @@
#!/usr/bin/env bash
echo "Configure PostgreSQL test database"
psql -U postgres -c 'create database zenddb_test;'
psql -U postgres -c "alter role postgres password 'postgres'"

View File

@ -1,5 +0,0 @@
#!/usr/bin/env bash
echo "Configure SQL server test database"
sqlcmd -S localhost -U sa -P Password123 -Q "CREATE DATABASE zenddb_test;"

View File

@ -1,445 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file, in reverse chronological order by release.
## 2.10.0 - 2019-02-25
### Added
- [#157](https://github.com/zendframework/zend-db/pull/157) added support of
`Zend\Db\Sql\TableIdentifier` in DDL
- [#345](https://github.com/zendframework/zend-db/pull/345) allow usage with
zend-hydrator v3
- [#346](https://github.com/zendframework/zend-db/pull/346) adds support for PHP
7.3
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#303](https://github.com/zendframework/zend-db/pull/303) fixes #295 issue:
handle empty array as datasource at `AbstractResultSet::initialize()` at PHP
7.2
- [#313](https://github.com/zendframework/zend-db/pull/313) test
`AbstractResultSet::current()` to return null on empty array
- [#329](https://github.com/zendframework/zend-db/pull/329) fixes Exception
thrown when calling `prepareStatementForSqlObject` on a Select with a
sub-Select that has limit and/or offset set
- [#337](https://github.com/zendframework/zend-db/pull/337) fixes #330 current
NULL for mysqli
- [#338](https://github.com/zendframework/zend-db/pull/338) restore missing use
`ResultSet` in `AbstractTableGateway`
- [#341](https://github.com/zendframework/zend-db/pull/341) fixes undefined
variable bug in MetadataFeature
- [#357](https://github.com/zendframework/zend-db/pull/357) fixes named params
in subquery - limit and offset (issue #355)
## 2.9.3 - 2018-04-09
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#295](https://github.com/zendframework/zend-db/pull/295) fix error when
datasource passed to `AbstractResultSet::initialize()` is empty array at
php 7.2 environment
- [#300](https://github.com/zendframework/zend-db/pull/300) Fix error for nested
queries inside field parameters
- [#301](https://github.com/zendframework/zend-db/pull/301) fix for issue with
set fields that exists in different tables in one query
- [#304](https://github.com/zendframework/zend-db/pull/304) fix PDO bind
parameter name to use field name with extended charset (PDO only supports
alphanumeric and underscore for placeholder/parameter names).
## 2.9.2 - 2017-12-11
### Added
- Nothing.
### Changed
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#292](https://github.com/zendframework/zend-db/pull/292) ensures that you may
reference bound parameter names using a leading colon (`:`) character when
using the PDO adapter. (The leading colon is not technically necessary, as the
adapter will prefix for you; however, this ensures portability with vanilla
PDO.)
## 2.9.1 - 2017-12-07
### Added
- Nothing.
### Changed
- [#289](https://github.com/zendframework/zend-db/pull/289) reverts a change
introduced in 2.9.0 and modifies the behavior of the PDO adapter slightly
to remove a regression. In 2.9.0, when binding parameters with names that
contained characters not supported by PDO, we would pass the parameter names
to `md5()`; this caused a regression, as the SQL string containing the
parameter name was not also updated.
This patch modifies the behavior during a bind-operation to instead raise an
exception if a parameter name contains characters not supported by PDO.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.9.0 - 2017-12-06
### Added
- [#216](https://github.com/zendframework/zend-db/pull/216) added AFTER support
in ALTER TABLE syntax for MySQL
- [#223](https://github.com/zendframework/zend-db/pull/223) added support for
empty values set with IN predicate
- [#271](https://github.com/zendframework/zend-db/pull/271) added support for
dash character on MySQL identifier
- [#273](https://github.com/zendframework/zend-db/pull/273) added support for
implementing an error handler for db2_prepare
- [#275](https://github.com/zendframework/zend-db/pull/275) added support for
LIMIT OFFSET for db2
- [#280](https://github.com/zendframework/zend-db/pull/280) added version dsn
parameter for pdo_dblib
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#205](https://github.com/zendframework/zend-db/pull/205) fixes the spaces in
ORDER BY syntax
- [#224](https://github.com/zendframework/zend-db/pull/224) fixes how parameters
are bound to statements in the PDO adapter. PDO has a restriction on parameter
names of `[0-9a-zA_Z_]`; as such, the driver now hashes the parameter names
using `md5()` in order to ensure compatibility with other drivers.
- [#229](https://github.com/zendframework/zend-db/pull/229) fixes the support
of SSL for mysqli
- [#255](https://github.com/zendframework/zend-db/pull/255) fixes ResultSet with
array values
- [#261](https://github.com/zendframework/zend-db/pull/261) fixes Exception in
Firebird driver doesn't support lastInsertId
- [#276](https://github.com/zendframework/zend-db/pull/276) fixes the support
of PHP 7.2
- [#287](https://github.com/zendframework/zend-db/pull/287) fixes the usage of
count() with PHP 7.2
## 2.8.2 - 2016-08-09
### Added
- [#110](https://github.com/zendframework/zend-db/pull/110) prepared the
documentation for publication at https://zendframework.github.io/zend-db/
- [#114](https://github.com/zendframework/zend-db/pull/114) add
Adapter\Adapter::class to alias against Adapter\AdapterInterface::class
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#154](https://github.com/zendframework/zend-db/pull/154) fixes the how the
COMBINE operator is applied to SQLite adapters, ensuring a valid UNION
statement is generated.
- [#112](https://github.com/zendframework/zend-db/pull/112) fixes the test on
the number of replacements when using the same variable name.
- [#115](https://github.com/zendframework/zend-db/pull/115) TableGateway update
method was incorrect when specifying default join declaration.
- [#145](https://github.com/zendframework/zend-db/pull/145) Fix MSSQL Select
when encounting DISTINCT and OFFSET and LIMIT together.
- [#153](https://github.com/zendframework/zend-db/pull/153) Runtime exception
threw fatal error due to incorrect spelling of the class when a DSN did not
exist.
## 2.8.1 - 2016-04-14
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#100](https://github.com/zendframework/zend-db/pull/100) fixes the JOIN
behavior to re-allow selecting an empty column set from the joined table.
- [#106](https://github.com/zendframework/zend-db/pull/106) fixes an issue in
the test suite when ext/pgsql is enabled, but no databases are avaiable.
## 2.8.0 - 2016-04-12
### Added
- [#92](https://github.com/zendframework/zend-db/pull/92) adds the class
`Zend\Db\Sql\Join` for creating and aggregating JOIN specifications. This is
now consumed by all `Zend\Db\Sql` implementations in order to represent JOIN
statements.
- [#92](https://github.com/zendframework/zend-db/pull/92) adds support for JOIN
operations to UPDATE statements.
- [#92](https://github.com/zendframework/zend-db/pull/92) adds support for joins
to `AbstractTableGateway::update`; you can now pass an array of
specifications via a third argument to the method.
- [#96](https://github.com/zendframework/zend-db/pull/96) exposes the package as
config-provider/component, but adding:
- `Zend\Db\ConfigProvider`, which maps the `AdapterInterface` to the
`AdapterServiceFactory`, and enables the `AdapterAbstractServiceFactory`.
- `Zend\Db\Module`, which does the same, for a zend-mvc context.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.7.1 - 2016-04-12
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#71](https://github.com/zendframework/zend-db/pull/71) updates the `Pgsql`
adapter to allow passing the connection charset; this can be done with the
`charset` option when creating your adapter.
- [#76](https://github.com/zendframework/zend-db/pull/76) fixes the behavior of
`Zend\Db\Sql\Insert` when an array of names is used for columns to ensure the
string names are used, and not the array indices.
- [#91](https://github.com/zendframework/zend-db/pull/91) fixes the behavior of
the `Oci8` adapter when initializing a result set; previously, it was
improperly assigning the count of affected rows to the generated value.
- [#95](https://github.com/zendframework/zend-db/pull/95) fixes the `IbmDb2`
platform's `quoteIdentifier()` method to properly allow `#` characters in
identifiers (as they are commonly used on that platform).
## 2.7.0 - 2016-02-22
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#85](https://github.com/zendframework/zend-db/pull/85) and
[#87](https://github.com/zendframework/zend-db/pull/87) update the code base
to be forwards compatible with:
- zend-eventmanager v3
- zend-hydrator v2.1
- zend-servicemanager v3
- zend-stdlib v3
## 2.6.2 - 2015-12-09
### Added
- [#49](https://github.com/zendframework/zend-db/pull/49) Add docbook
documentation.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#55](https://github.com/zendframework/zend-db/pull/55) Implement FeatureSet
canCallMagicCall and callMagicCall methods
- [#56](https://github.com/zendframework/zend-db/pull/56)
AbstractResultSet::current now does validation to ensure an array.
- [#58](https://github.com/zendframework/zend-db/pull/58) Fix unbuffered result
on MySQLi.
- [#59](https://github.com/zendframework/zend-db/pull/59) Allow unix_socket
parameter
## 2.6.1 - 2015-10-14
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#31](https://github.com/zendframework/zend-db/pull/31) fixes table gateway
update when there is a table alias utilized.
## 2.6.1 - 2015-10-14
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- Nothing.
### Fixed
- [#43](https://github.com/zendframework/zend-db/pull/43) unset and get during
an insert operation would throw an InvalidArgumentException during an insert.
## 2.6.0 - 2015-09-22
### Added
- [#42](https://github.com/zendframework/zend-db/pull/42) updates the component
to use zend-hydrator for hydrator functionality; this provides forward
compatibility with zend-hydrator, and backwards compatibility with
hydrators from older versions of zend-stdlib.
- [#15](https://github.com/zendframework/zend-db/pull/15) adds a new predicate,
`Zend\Db\Sql\Predicate\NotBetween`, which can be invoked via `Sql`
instances: `$sql->notBetween($field, $min, $max)`.
- [#22](https://github.com/zendframework/zend-db/pull/22) extracts a factory,
`Zend\Db\Metadata\Source\Factory`, from `Zend\Db\Metadata\Metadata`,
removing the (non-public) `createSourceFromAdapter()` method from that
class. Additionally, it extracts `Zend\Db\Metadata\MetadataInterface`, to
allow creating alternate implementations.
### Deprecated
- [#27](https://github.com/zendframework/zend-db/pull/27) deprecates the
constants `JOIN_OUTER_LEFT` and `JOIN_OUTER_RIGHT` in favor of
`JOIN_LEFT_OUTER` and `JOIN_RIGHT_OUTER`.
### Removed
- Nothing.
### Fixed
- Nothing.
## 2.5.2 - 2015-09-22
### Added
- Nothing.
### Deprecated
- Nothing.
### Removed
- [#29](https://github.com/zendframework/zend-db/pull/29) removes the required
second argument to `Zend\Db\Predicate\Predicate::expression()`, allowing it to
be nullable, and mirroring the constructor of `Zend\Db\Predicate\Expression`.
### Fixed
- [#40](https://github.com/zendframework/zend-db/pull/40) updates the
zend-stdlib dependency to reference `>=2.5.0,<2.7.0` to ensure hydrators
will work as expected following extraction of hydrators to the zend-hydrator
repository.
- [#34](https://github.com/zendframework/zend-db/pull/34) fixes retrieval of
constraint metadata in the Oracle adapter.
- [#41](https://github.com/zendframework/zend-db/pull/41) removes hard dependency
on EventManager in AbstractTableGateway.
- [#17](https://github.com/zendframework/zend-db/pull/17) removes an executable
bit on a regular file.
- [#3](https://github.com/zendframework/zend-db/pull/3) updates the code to use
closure binding (now that we're on 5.5+, this is possible).
- [#9](https://github.com/zendframework/zend-db/pull/9) thoroughly audits the
OCI8 (Oracle) driver, ensuring it provides feature parity with other drivers,
and fixes issues with subselects, limits, and offsets.

View File

@ -1,27 +0,0 @@
Copyright (c) 2005-2017, Zend Technologies USA, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
- Neither the name of Zend Technologies USA, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,12 +0,0 @@
# zend-db
[![Build Status](https://secure.travis-ci.org/zendframework/zend-db.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-db)
[![Coverage Status](https://coveralls.io/repos/github/zendframework/zend-db/badge.svg?branch=master)](https://coveralls.io/github/zendframework/zend-db?branch=master)
`Zend\Db` is a component that abstract the access to a Database using an object
oriented API to build the queries. `Zend\Db` consumes different storage adapters
to access different database vendors such as MySQL, PostgreSQL, Oracle, IBM DB2,
Microsoft Sql Server, PDO, etc.
- File issues at https://github.com/zendframework/zend-db/issues
- Documentation is at https://docs.zendframework.com/zend-db/

View File

@ -1,73 +0,0 @@
{
"name": "zendframework/zend-db",
"description": "Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations",
"license": "BSD-3-Clause",
"keywords": [
"zf",
"zendframework",
"db"
],
"support": {
"docs": "https://docs.zendframework.com/zend-db/",
"issues": "https://github.com/zendframework/zend-db/issues",
"source": "https://github.com/zendframework/zend-db",
"rss": "https://github.com/zendframework/zend-db/releases.atom",
"slack": "https://zendframework-slack.herokuapp.com",
"forum": "https://discourse.zendframework.com/c/questions/components"
},
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.25 || ^6.4.4",
"zendframework/zend-coding-standard": "~1.0.0",
"zendframework/zend-eventmanager": "^2.6.2 || ^3.0",
"zendframework/zend-hydrator": "^1.1 || ^2.1 || ^3.0",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3"
},
"suggest": {
"zendframework/zend-eventmanager": "Zend\\EventManager component",
"zendframework/zend-hydrator": "Zend\\Hydrator component for using HydratingResultSets",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component"
},
"autoload": {
"psr-4": {
"Zend\\Db\\": "src/"
}
},
"autoload-dev": {
"files": [
"test/autoload.php"
],
"psr-4": {
"ZendTest\\Db\\": "test/unit",
"ZendIntegrationTest\\Db\\": "test/integration"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "2.9-dev",
"dev-develop": "2.10-dev"
},
"zf": {
"component": "Zend\\Db",
"config-provider": "Zend\\Db\\ConfigProvider"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always --testsuite \"unit test\"",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"test-integration" : "phpunit --colors=always --testsuite \"integration test\"",
"upload-coverage": "coveralls -v"
}
}

View File

@ -1,43 +0,0 @@
# Contributor Code of Conduct
This project adheres to [The Code Manifesto](http://codemanifesto.com)
as its guidelines for contributor interactions.
## The Code Manifesto
We want to work in an ecosystem that empowers developers to reach their
potential — one that encourages growth and effective collaboration. A space that
is safe for all.
A space such as this benefits everyone that participates in it. It encourages
new developers to enter our field. It is through discussion and collaboration
that we grow, and through growth that we improve.
In the effort to create such a place, we hold to these values:
1. **Discrimination limits us.** This includes discrimination on the basis of
race, gender, sexual orientation, gender identity, age, nationality, technology
and any other arbitrary exclusion of a group of people.
2. **Boundaries honor us.** Your comfort levels are not everyones comfort
levels. Remember that, and if brought to your attention, heed it.
3. **We are our biggest assets.** None of us were born masters of our trade.
Each of us has been helped along the way. Return that favor, when and where
you can.
4. **We are resources for the future.** As an extension of #3, share what you
know. Make yourself a resource to help those that come after you.
5. **Respect defines us.** Treat others as you wish to be treated. Make your
discussions, criticisms and debates from a position of respectfulness. Ask
yourself, is it true? Is it necessary? Is it constructive? Anything less is
unacceptable.
6. **Reactions require grace.** Angry responses are valid, but abusive language
and vindictive actions are toxic. When something happens that offends you,
handle it assertively, but be respectful. Escalate reasonably, and try to
allow the offender an opportunity to explain themselves, and possibly correct
the issue.
7. **Opinions are just that: opinions.** Each and every one of us, due to our
background and upbringing, have varying opinions. The fact of the matter, is
that is perfectly acceptable. Remember this: if you respect your own
opinions, you should respect the opinions of others.
8. **To err is human.** You might not intend it, but mistakes do happen and
contribute to build experience. Tolerate honest mistakes, and don't hesitate
to apologize if you make one yourself.

View File

@ -1,189 +0,0 @@
# CONTRIBUTING
## RESOURCES
If you wish to contribute to this project, please be sure to
read/subscribe to the following resources:
- [Coding Standards](https://github.com/zendframework/zend-coding-standard)
- [Forums](https://discourse.zendframework.com/c/contributors)
- [Slack](https://zendframework-slack.herokuapp.com)
- [Code of Conduct](CODE_OF_CONDUCT.md)
If you are working on new features or refactoring
[create a proposal](https://github.com/zendframework/zend-db/issues/new).
## RUNNING TESTS
To run tests:
- Clone the repository:
```console
$ git clone git://github.com/zendframework/zend-db.git
$ cd zend-db
```
- Install dependencies via composer:
```console
$ composer install
```
If you don't have `composer` installed, please download it from https://getcomposer.org/download/
- Run the tests using the "test" command shipped in the `composer.json`:
```console
$ composer test
```
You can turn on conditional tests with the `phpunit.xml` file.
To do so:
- Copy `phpunit.xml.dist` file to `phpunit.xml`
- Edit `phpunit.xml` to enable any specific functionality you
want to test, as well as to provide test values to utilize.
## Running Coding Standards Checks
First, ensure you've installed dependencies via composer, per the previous
section on running tests.
To run CS checks only:
```console
$ composer cs-check
```
To attempt to automatically fix common CS issues:
```console
$ composer cs-fix
```
If the above fixes any CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.
## Recommended Workflow for Contributions
Your first step is to establish a public repository from which we can
pull your work into the master repository. We recommend using
[GitHub](https://github.com), as that is where the component is already hosted.
1. Setup a [GitHub account](https://github.com/), if you haven't yet
2. Fork the repository (https://github.com/zendframework/zend-db)
3. Clone the canonical repository locally and enter it.
```console
$ git clone git://github.com/zendframework/zend-db.git
$ cd zend-db
```
4. Add a remote to your fork; substitute your GitHub username in the command
below.
```console
$ git remote add {username} git@github.com:{username}/zend-db.git
$ git fetch {username}
```
### Keeping Up-to-Date
Periodically, you should update your fork or personal repository to
match the canonical ZF repository. Assuming you have setup your local repository
per the instructions above, you can do the following:
```console
$ git checkout master
$ git fetch origin
$ git rebase origin/master
# OPTIONALLY, to keep your remote up-to-date -
$ git push {username} master:master
```
If you're tracking other branches -- for example, the "develop" branch, where
new feature development occurs -- you'll want to do the same operations for that
branch; simply substitute "develop" for "master".
### Working on a patch
We recommend you do each new feature or bugfix in a new branch. This simplifies
the task of code review as well as the task of merging your changes into the
canonical repository.
A typical workflow will then consist of the following:
1. Create a new local branch based off either your master or develop branch.
2. Switch to your new local branch. (This step can be combined with the
previous step with the use of `git checkout -b`.)
3. Do some work, commit, repeat as necessary.
4. Push the local branch to your remote repository.
5. Send a pull request.
The mechanics of this process are actually quite trivial. Below, we will
create a branch for fixing an issue in the tracker.
```console
$ git checkout -b hotfix/9295
Switched to a new branch 'hotfix/9295'
```
... do some work ...
```console
$ git commit
```
... write your log message ...
```console
$ git push {username} hotfix/9295:hotfix/9295
Counting objects: 38, done.
Delta compression using up to 2 threads.
Compression objects: 100% (18/18), done.
Writing objects: 100% (20/20), 8.19KiB, done.
Total 20 (delta 12), reused 0 (delta 0)
To ssh://git@github.com/{username}/zend-db.git
b5583aa..4f51698 HEAD -> master
```
To send a pull request, you have two options.
If using GitHub, you can do the pull request from there. Navigate to
your repository, select the branch you just created, and then select the
"Pull Request" button in the upper right. Select the user/organization
"zendframework" (or whatever the upstream organization is) as the recipient.
#### What branch to issue the pull request against?
Which branch should you issue a pull request against?
- For fixes against the stable release, issue the pull request against the
"master" branch.
- For new features, or fixes that introduce new elements to the public API (such
as new public methods or properties), issue the pull request against the
"develop" branch.
### Branch Cleanup
As you might imagine, if you are a frequent contributor, you'll start to
get a ton of branches both locally and on your remote.
Once you know that your changes have been accepted to the master
repository, we suggest doing some cleanup of these branches.
- Local branch cleanup
```console
$ git branch -d <branchname>
```
- Remote branch removal
```console
$ git push {username} :<branchname>
```

View File

@ -1,19 +0,0 @@
- [ ] I was not able to find an [open](https://github.com/zendframework/zend-db/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/zend-db/issues?q=is%3Aclosed) issue matching what I'm seeing.
- [ ] This is not a question. (Questions should be asked on [slack](https://zendframework.slack.com/) ([Signup for Slack here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).)
Provide a narrative description of what you are trying to accomplish.
### Code to reproduce the issue
<!-- Please provide the minimum code necessary to recreate the issue -->
```php
```
### Expected results
<!-- What do you think should have happened? -->
### Actual results
<!-- What did you actually observe? -->

View File

@ -1,25 +0,0 @@
Provide a narrative description of what you are trying to accomplish:
- [ ] Are you fixing a bug?
- [ ] Detail how the bug is invoked currently.
- [ ] Detail the original, incorrect behavior.
- [ ] Detail the new, expected behavior.
- [ ] Base your feature on the `master` branch, and submit against that branch.
- [ ] Add a regression test that demonstrates the bug, and proves the fix.
- [ ] Add a `CHANGELOG.md` entry for the fix.
- [ ] Are you creating a new feature?
- [ ] Why is the new feature needed? What purpose does it serve?
- [ ] How will users use the new feature?
- [ ] Base your feature on the `develop` branch, and submit against that branch.
- [ ] Add only one feature per pull request; split multiple features over multiple pull requests
- [ ] Add tests for the new feature.
- [ ] Add documentation for the new feature.
- [ ] Add a `CHANGELOG.md` entry for the new feature.
- [ ] Is this related to quality assurance?
<!-- Detail why the changes are necessary -->
- [ ] Is this related to documentation?
<!-- Is it a typographical and/or grammatical fix? -->
<!-- Is it new documentation? -->

View File

@ -1,25 +0,0 @@
# Getting Support
Zend Framework offers three support channels:
- For real-time questions, use our
[Slack](https://zendframework-slack.herokuapp.com)
- For detailed questions (e.g., those requiring examples) use our
[forums](https://discourse.zendframework.com/c/questions/components)
- To report issues, use this repository's
[issue tracker](https://github.com/zendframework/zend-db/issues/new)
**DO NOT** use the issue tracker to ask questions; use Slack or the forums for
that. Questions posed to the issue tracker will be closed.
When reporting an issue, please include the following details:
- A narrative description of what you are trying to accomplish.
- The minimum code necessary to reproduce the issue.
- The expected results of exercising that code.
- The actual results received.
We may ask for additional details: what version of the library you are using,
and what PHP version was used to reproduce the issue.
You may also submit a failing test case as a pull request.

View File

@ -1,498 +0,0 @@
# Adapters
`Zend\Db\Adapter\Adapter` is the central object of the zend-db component. It is
responsible for adapting any code written in or for zend-db to the targeted PHP
extensions and vendor databases. In doing this, it creates an abstraction layer
for the PHP extensions in the `Driver` subnamespace of `Zend\Db\Adapter`. It
also creates a lightweight "Platform" abstraction layer, for the various
idiosyncrasies that each vendor-specific platform might have in its SQL/RDBMS
implementation, separate from the driver implementations.
## Creating an adapter using configuration
Create an adapter by instantiating the `Zend\Db\Adapter\Adapter` class. The most
common use case, while not the most explicit, is to pass an array of
configuration to the `Adapter`:
```php
use Zend\Db\Adapter\Adapter;
$adapter = new Adapter($configArray);
```
This driver array is an abstraction for the extension level required parameters.
Here is a table for the key-value pairs that should be in configuration array.
Key | Is Required? | Value
---------- | ---------------------- | -----
`driver` | required | `Mysqli`, `Sqlsrv`, `Pdo_Sqlite`, `Pdo_Mysql`, `Pdo`(= Other PDO Driver)
`database` | generally required | the name of the database (schema)
`username` | generally required | the connection username
`password` | generally required | the connection password
`hostname` | not generally required | the IP address or hostname to connect to
`port` | not generally required | the port to connect to (if applicable)
`charset` | not generally required | the character set to use
> ### Options are adapter-dependent
>
> Other names will work as well. Effectively, if the PHP manual uses a
> particular naming, this naming will be supported by the associated driver. For
> example, `dbname` in most cases will also work for 'database'. Another
> example is that in the case of `Sqlsrv`, `UID` will work in place of
> `username`. Which format you choose is up to you, but the above table
> represents the official abstraction names.
For example, a MySQL connection using ext/mysqli:
```php
$adapter = new Zend\Db\Adapter\Adapter([
'driver' => 'Mysqli',
'database' => 'zend_db_example',
'username' => 'developer',
'password' => 'developer-password',
]);
```
Another example, of a Sqlite connection via PDO:
```php
$adapter = new Zend\Db\Adapter\Adapter([
'driver' => 'Pdo_Sqlite',
'database' => 'path/to/sqlite.db',
]);
```
Another example, of an IBM i DB2 connection via IbmDb2:
```php
$adapter = new Zend\Db\Adapter\Adapter([
'database' => '*LOCAL', // or name from WRKRDBDIRE, may be serial #
'driver' => 'IbmDb2',
'driver_options' => [
'autocommit' => DB2_AUTOCOMMIT_ON,
'i5_naming' => DB2_I5_NAMING_ON,
'i5_libl' => 'SCHEMA1 SCHEMA2 SCHEMA3',
],
'username' => '__USER__',
'password' => '__PASS__',
// 'persistent' => true,
'platform' => 'IbmDb2',
'platform_options' => ['quote_identifiers' => false],
]);
```
Another example, of an IBM i DB2 connection via PDO:
```php
$adapter = new Zend\Db\Adapter\Adapter([
'dsn' => 'ibm:DB_NAME', // DB_NAME is from WRKRDBDIRE, may be serial #
'driver' => 'pdo',
'driver_options' => [
// PDO::ATTR_PERSISTENT => true,
PDO::ATTR_AUTOCOMMIT => true,
PDO::I5_ATTR_DBC_SYS_NAMING => true,
PDO::I5_ATTR_DBC_CURLIB => '',
PDO::I5_ATTR_DBC_LIBL => 'SCHEMA1 SCHEMA2 SCHEMA3',
],
'username' => '__USER__',
'password' => '__PASS__',
'platform' => 'IbmDb2',
'platform_options' => ['quote_identifiers' => false],
]);
```
It is important to know that by using this style of adapter creation, the
`Adapter` will attempt to create any dependencies that were not explicitly
provided. A `Driver` object will be created from the configuration array
provided in the constructor. A `Platform` object will be created based off the
type of `Driver` class that was instantiated. And lastly, a default `ResultSet`
object is created and utilized. Any of these objects can be injected, to do
this, see the next section.
The list of officially supported drivers:
- `IbmDb2`: The ext/ibm_db2 driver
- `Mysqli`: The ext/mysqli driver
- `Oci8`: The ext/oci8 driver
- `Pgsql`: The ext/pgsql driver
- `Sqlsrv`: The ext/sqlsrv driver (from Microsoft)
- `Pdo_Mysql`: MySQL via the PDO extension
- `Pdo_Sqlite`: SQLite via the PDO extension
- `Pdo_Pgsql`: PostgreSQL via the PDO extension
## Creating an adapter using dependency injection
The more expressive and explicit way of creating an adapter is by injecting all
your dependencies up front. `Zend\Db\Adapter\Adapter` uses constructor
injection, and all required dependencies are injected through the constructor,
which has the following signature (in pseudo-code):
```php
use Zend\Db\Adapter\Platform\PlatformInterface;
use Zend\Db\ResultSet\ResultSet;
class Zend\Db\Adapter\Adapter
{
public function __construct(
$driver,
PlatformInterface $platform = null,
ResultSet $queryResultSetPrototype = null
);
}
```
What can be injected:
- `$driver`: an array of connection parameters (see above) or an instance of
`Zend\Db\Adapter\Driver\DriverInterface`.
- `$platform` (optional): an instance of `Zend\Db\Platform\PlatformInterface`;
the default will be created based off the driver implementation.
- `$queryResultSetPrototype` (optional): an instance of
`Zend\Db\ResultSet\ResultSet`; to understand this object's role, see the
section below on querying.
## Query Preparation
By default, `Zend\Db\Adapter\Adapter::query()` prefers that you use
"preparation" as a means for processing SQL statements. This generally means
that you will supply a SQL statement containing placeholders for the values, and
separately provide substitutions for those placeholders. As an example:
```php
$adapter->query('SELECT * FROM `artist` WHERE `id` = ?', [5]);
```
The above example will go through the following steps:
- create a new `Statement` object.
- prepare the array `[5]` into a `ParameterContainer` if necessary.
- inject the `ParameterContainer` into the `Statement` object.
- execute the `Statement` object, producing a `Result` object.
- check the `Result` object to check if the supplied SQL was a result set
producing statement:
- if the query produced a result set, clone the `ResultSet` prototype,
inject the `Result` as its datasource, and return the new `ResultSet`
instance.
- otherwise, return the `Result`.
## Query Execution
In some cases, you have to execute statements directly without preparation. One
possible reason for doing so would be to execute a DDL statement, as most
extensions and RDBMS systems are incapable of preparing such statements.
To execute a query without the preparation step, you will need to pass a flag as
the second argument indicating execution is required:
```php
$adapter->query(
'ALTER TABLE ADD INDEX(`foo_index`) ON (`foo_column`)',
Adapter::QUERY_MODE_EXECUTE
);
```
The primary difference to notice is that you must provide the
`Adapter::QUERY_MODE_EXECUTE` (execute) flag as the second parameter.
## Creating Statements
While `query()` is highly useful for one-off and quick querying of a database
via the `Adapter`, it generally makes more sense to create a statement and
interact with it directly, so that you have greater control over the
prepare-then-execute workflow. To do this, `Adapter` gives you a routine called
`createStatement()` that allows you to create a `Driver` specific `Statement` to
use so you can manage your own prepare-then-execute workflow.
```php
// with optional parameters to bind up-front:
$statement = $adapter->createStatement($sql, $optionalParameters);
$result = $statement->execute();
```
## Using the Driver Object
The `Driver` object is the primary place where `Zend\Db\Adapter\Adapter`
implements the connection level abstraction specific to a given extension. To
make this possible, each driver is composed of 3 objects:
- A connection: `Zend\Db\Adapter\Driver\ConnectionInterface`
- A statement: `Zend\Db\Adapter\Driver\StatementInterface`
- A result: `Zend\Db\Adapter\Driver\ResultInterface`
Each of the built-in drivers practice "prototyping" as a means of creating
objects when new instances are requested. The workflow looks like this:
- An adapter is created with a set of connection parameters.
- The adapter chooses the proper driver to instantiate (for example,
`Zend\Db\Adapter\Driver\Mysqli`)
- That driver class is instantiated.
- If no connection, statement, or result objects are injected, defaults are
instantiated.
This driver is now ready to be called on when particular workflows are
requested. Here is what the `Driver` API looks like:
```php
namespace Zend\Db\Adapter\Driver;
interface DriverInterface
{
const PARAMETERIZATION_POSITIONAL = 'positional';
const PARAMETERIZATION_NAMED = 'named';
const NAME_FORMAT_CAMELCASE = 'camelCase';
const NAME_FORMAT_NATURAL = 'natural';
public function getDatabasePlatformName(string $nameFormat = self::NAME_FORMAT_CAMELCASE) : string;
public function checkEnvironment() : bool;
public function getConnection() : ConnectionInterface;
public function createStatement(string|resource $sqlOrResource = null) : StatementInterface;
public function createResult(resource $resource) : ResultInterface;
public function getPrepareType() :string;
public function formatParameterName(string $name, $type = null) : string;
public function getLastGeneratedValue() : mixed;
}
```
From this `DriverInterface`, you can
- Determine the name of the platform this driver supports (useful for choosing
the proper platform object).
- Check that the environment can support this driver.
- Return the `Connection` instance.
- Create a `Statement` instance which is optionally seeded by an SQL statement
(this will generally be a clone of a prototypical statement object).
- Create a `Result` object which is optionally seeded by a statement resource
(this will generally be a clone of a prototypical result object)
- Format parameter names; this is important to distinguish the difference
between the various ways parameters are named between extensions
- Retrieve the overall last generated value (such as an auto-increment value).
Now let's turn to the `Statement` API:
```php
namespace Zend\Db\Adapter\Driver;
interface StatementInterface extends StatementContainerInterface
{
public function getResource() : resource;
public function prepare($sql = null) : void;
public function isPrepared() : bool;
public function execute(null|array|ParameterContainer $parameters = null) : ResultInterface;
/** Inherited from StatementContainerInterface */
public function setSql(string $sql) : void;
public function getSql() : string;
public function setParameterContainer(ParameterContainer $parameterContainer) : void;
public function getParameterContainer() : ParameterContainer;
}
```
And finally, the `Result` API:
```php
namespace Zend\Db\Adapter\Driver;
use Countable;
use Iterator;
interface ResultInterface extends Countable, Iterator
{
public function buffer() : void;
public function isQueryResult() : bool;
public function getAffectedRows() : int;
public function getGeneratedValue() : mixed;
public function getResource() : resource;
public function getFieldCount() : int;
}
```
## Using The Platform Object
The `Platform` object provides an API to assist in crafting queries in a way
that is specific to the SQL implementation of a particular vendor. The object
handles nuances such as how identifiers or values are quoted, or what the
identifier separator character is. To get an idea of the capabilities, the
interface for a platform object looks like this:
```php
namespace Zend\Db\Adapter\Platform;
interface PlatformInterface
{
public function getName() : string;
public function getQuoteIdentifierSymbol() : string;
public function quoteIdentifier(string $identifier) : string;
public function quoteIdentifierChain(string|string[] $identiferChain) : string;
public function getQuoteValueSymbol() : string;
public function quoteValue(string $value) : string;
public function quoteTrustedValue(string $value) : string;
public function quoteValueList(string|string[] $valueList) : string;
public function getIdentifierSeparator() : string;
public function quoteIdentifierInFragment(string $identifier, array $additionalSafeWords = []) : string;
}
```
While you can directly instantiate a `Platform` object, generally speaking, it
is easier to get the proper `Platform` instance from the configured adapter (by
default the `Platform` type will match the underlying driver implementation):
```php
$platform = $adapter->getPlatform();
// or
$platform = $adapter->platform; // magic property access
```
The following are examples of `Platform` usage:
```php
// $adapter is a Zend\Db\Adapter\Adapter instance;
// $platform is a Zend\Db\Adapter\Platform\Sql92 instance.
$platform = $adapter->getPlatform();
// "first_name"
echo $platform->quoteIdentifier('first_name');
// "
echo $platform->getQuoteIdentifierSymbol();
// "schema"."mytable"
echo $platform->quoteIdentifierChain(['schema', 'mytable']);
// '
echo $platform->getQuoteValueSymbol();
// 'myvalue'
echo $platform->quoteValue('myvalue');
// 'value', 'Foo O\\'Bar'
echo $platform->quoteValueList(['value', "Foo O'Bar"]);
// .
echo $platform->getIdentifierSeparator();
// "foo" as "bar"
echo $platform->quoteIdentifierInFragment('foo as bar');
// additionally, with some safe words:
// ("foo"."bar" = "boo"."baz")
echo $platform->quoteIdentifierInFragment('(foo.bar = boo.baz)', ['(', ')', '=']);
```
## Using The Parameter Container
The `ParameterContainer` object is a container for the various parameters that
need to be passed into a `Statement` object to fulfill all the various
parameterized parts of the SQL statement. This object implements the
`ArrayAccess` interface. Below is the `ParameterContainer` API:
```php
namespace Zend\Db\Adapter;
use ArrayAccess;
use ArrayIterator;
use Countable;
use Iterator;
class ParameterContainer implements Iterator, ArrayAccess, Countable
{
public function __construct(array $data = [])
/** methods to interact with values */
public function offsetExists(string|int $name) : bool;
public function offsetGet(string|int $name) : mixed;
public function offsetSetReference(string|int $name, string|int $from) : void;
public function offsetSet(string|int $name, mixed $value, mixed $errata = null, int $maxLength = null) : void;
public function offsetUnset(string|int $name) : void;
/** set values from array (will reset first) */
public function setFromArray(array $data) : ParameterContainer;
/** methods to interact with value errata */
public function offsetSetErrata(string|int $name, mixed $errata) : void;
public function offsetGetErrata(string|int $name) : mixed;
public function offsetHasErrata(string|int $name) : bool;
public function offsetUnsetErrata(string|int $name) : void;
/** errata only iterator */
public function getErrataIterator() : ArrayIterator;
/** get array with named keys */
public function getNamedArray() : array;
/** get array with int keys, ordered by position */
public function getPositionalArray() : array;
/** iterator: */
public function count() : int;
public function current() : mixed;
public function next() : mixed;
public function key() : string|int;
public function valid() : bool;
public function rewind() : void;
/** merge existing array of parameters with existing parameters */
public function merge(array $parameters) : ParameterContainer;
}
```
In addition to handling parameter names and values, the container will assist in
tracking parameter types for PHP type to SQL type handling. For example, it
might be important that:
```php
$container->offsetSet('limit', 5);
```
be bound as an integer. To achieve this, pass in the
`ParameterContainer::TYPE_INTEGER` constant as the 3rd parameter:
```php
$container->offsetSet('limit', 5, $container::TYPE_INTEGER);
```
This will ensure that if the underlying driver supports typing of bound
parameters, that this translated information will also be passed along to the
actual php database driver.
## Examples
Creating a `Driver`, a vendor-portable query, and preparing and iterating the
result:
```php
$adapter = new Zend\Db\Adapter\Adapter($driverConfig);
$qi = function ($name) use ($adapter) {
return $adapter->platform->quoteIdentifier($name);
};
$fp = function ($name) use ($adapter) {
return $adapter->driver->formatParameterName($name);
};
$sql = 'UPDATE ' . $qi('artist')
. ' SET ' . $qi('name') . ' = ' . $fp('name')
. ' WHERE ' . $qi('id') . ' = ' . $fp('id');
$statement = $adapter->query($sql);
$parameters = [
'name' => 'Updated Artist',
'id' => 1,
];
$statement->execute($parameters);
// DATA INSERTED, NOW CHECK
$statement = $adapter->query(
'SELECT * FROM '
. $qi('artist')
. ' WHERE id = ' . $fp('id')
);
$results = $statement->execute(['id' => 1]);
$row = $results->current();
$name = $row['name'];
```

View File

@ -1,10 +0,0 @@
<div class="container">
<div class="jumbotron">
<h1>zend-db</h1>
<p>Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations.</p>
<pre><code class="language-bash">$ composer require zendframework/zend-db</code></pre>
</div>
</div>

View File

@ -1,229 +0,0 @@
# RDBMS Metadata
`Zend\Db\Metadata` is as sub-component of zend-db that makes it possible to get
metadata information about tables, columns, constraints, triggers, and other
information from a database in a standardized way. The primary interface for
`Metadata` is:
```php
namespace Zend\Db\Metadata;
interface MetadataInterface
{
public function getSchemas();
public function getTableNames(string $schema = null, bool $includeViews = false) : string[];
public function getTables(string $schema = null, bool $includeViews = false) : Object\TableObject[];
public function getTable(string $tableName, string $schema = null) : Object\TableObject;
public function getViewNames(string $schema = null) : string[];
public function getViews(string $schema = null) : Object\ViewObject[];
public function getView(string $viewName, string $schema = null) : Object\ViewObject;
public function getColumnNames(string string $table, $schema = null) : string[];
public function getColumns(string $table, string $schema = null) : Object\ColumnObject[];
public function getColumn(string $columnName, string $table, string $schema = null) Object\ColumnObject;
public function getConstraints(string $table, $string schema = null) : Object\ConstraintObject[];
public function getConstraint(string $constraintName, string $table, string $schema = null) : Object\ConstraintObject;
public function getConstraintKeys(string $constraint, string $table, string $schema = null) : Object\ConstraintKeyObject[];
public function getTriggerNames(string $schema = null) : string[];
public function getTriggers(string $schema = null) : Object\TriggerObject[];
public function getTrigger(string $triggerName, string $schema = null) : Object\TriggerObject;
}
```
## Basic Usage
Usage of `Zend\Db\Metadata` involves:
- Constructing a `Zend\Db\Metadata\Metadata` instance with an `Adapter`.
- Choosing a strategy for retrieving metadata, based on the database platform
used. In most cases, information will come from querying the
`INFORMATION_SCHEMA` tables for the currently accessible schema.
The `Metadata::get*Names()` methods will return arrays of strings, while the
other methods will return value objects specific to the type queried.
```php
$metadata = new Zend\Db\Metadata\Metadata($adapter);
// get the table names
$tableNames = $metadata->getTableNames();
foreach ($tableNames as $tableName) {
echo 'In Table ' . $tableName . PHP_EOL;
$table = $metadata->getTable($tableName);
echo ' With columns: ' . PHP_EOL;
foreach ($table->getColumns() as $column) {
echo ' ' . $column->getName()
. ' -> ' . $column->getDataType()
. PHP_EOL;
}
echo PHP_EOL;
echo ' With constraints: ' . PHP_EOL;
foreach ($metadata->getConstraints($tableName) as $constraint) {
echo ' ' . $constraint->getName()
. ' -> ' . $constraint->getType()
. PHP_EOL;
if (! $constraint->hasColumns()) {
continue;
}
echo ' column: ' . implode(', ', $constraint->getColumns());
if ($constraint->isForeignKey()) {
$fkCols = [];
foreach ($constraint->getReferencedColumns() as $refColumn) {
$fkCols[] = $constraint->getReferencedTableName() . '.' . $refColumn;
}
echo ' => ' . implode(', ', $fkCols);
}
echo PHP_EOL;
}
echo '----' . PHP_EOL;
}
```
## Metadata value objects
Metadata returns value objects that provide an interface to help developers
better explore the metadata. Below is the API for the various value objects:
### TableObject
```php
class Zend\Db\Metadata\Object\TableObject
{
public function __construct($name);
public function setColumns(array $columns);
public function getColumns();
public function setConstraints($constraints);
public function getConstraints();
public function setName($name);
public function getName();
}
```
### ColumnObject
```php
class Zend\Db\Metadata\Object\ColumnObject
{
public function __construct($name, $tableName, $schemaName = null);
public function setName($name);
public function getName();
public function getTableName();
public function setTableName($tableName);
public function setSchemaName($schemaName);
public function getSchemaName();
public function getOrdinalPosition();
public function setOrdinalPosition($ordinalPosition);
public function getColumnDefault();
public function setColumnDefault($columnDefault);
public function getIsNullable();
public function setIsNullable($isNullable);
public function isNullable();
public function getDataType();
public function setDataType($dataType);
public function getCharacterMaximumLength();
public function setCharacterMaximumLength($characterMaximumLength);
public function getCharacterOctetLength();
public function setCharacterOctetLength($characterOctetLength);
public function getNumericPrecision();
public function setNumericPrecision($numericPrecision);
public function getNumericScale();
public function setNumericScale($numericScale);
public function getNumericUnsigned();
public function setNumericUnsigned($numericUnsigned);
public function isNumericUnsigned();
public function getErratas();
public function setErratas(array $erratas);
public function getErrata($errataName);
public function setErrata($errataName, $errataValue);
}
```
### ConstraintObject
```php
class Zend\Db\Metadata\Object\ConstraintObject
{
public function __construct($name, $tableName, $schemaName = null);
public function setName($name);
public function getName();
public function setSchemaName($schemaName);
public function getSchemaName();
public function getTableName();
public function setTableName($tableName);
public function setType($type);
public function getType();
public function hasColumns();
public function getColumns();
public function setColumns(array $columns);
public function getReferencedTableSchema();
public function setReferencedTableSchema($referencedTableSchema);
public function getReferencedTableName();
public function setReferencedTableName($referencedTableName);
public function getReferencedColumns();
public function setReferencedColumns(array $referencedColumns);
public function getMatchOption();
public function setMatchOption($matchOption);
public function getUpdateRule();
public function setUpdateRule($updateRule);
public function getDeleteRule();
public function setDeleteRule($deleteRule);
public function getCheckClause();
public function setCheckClause($checkClause);
public function isPrimaryKey();
public function isUnique();
public function isForeignKey();
public function isCheck();
}
```
### TriggerObject
```php
class Zend\Db\Metadata\Object\TriggerObject
{
public function getName();
public function setName($name);
public function getEventManipulation();
public function setEventManipulation($eventManipulation);
public function getEventObjectCatalog();
public function setEventObjectCatalog($eventObjectCatalog);
public function getEventObjectSchema();
public function setEventObjectSchema($eventObjectSchema);
public function getEventObjectTable();
public function setEventObjectTable($eventObjectTable);
public function getActionOrder();
public function setActionOrder($actionOrder);
public function getActionCondition();
public function setActionCondition($actionCondition);
public function getActionStatement();
public function setActionStatement($actionStatement);
public function getActionOrientation();
public function setActionOrientation($actionOrientation);
public function getActionTiming();
public function setActionTiming($actionTiming);
public function getActionReferenceOldTable();
public function setActionReferenceOldTable($actionReferenceOldTable);
public function getActionReferenceNewTable();
public function setActionReferenceNewTable($actionReferenceNewTable);
public function getActionReferenceOldRow();
public function setActionReferenceOldRow($actionReferenceOldRow);
public function getActionReferenceNewRow();
public function setActionReferenceNewRow($actionReferenceNewRow);
public function getCreated();
public function setCreated($created);
}
```

View File

@ -1,157 +0,0 @@
# Result Sets
`Zend\Db\ResultSet` is a sub-component of zend-db for abstracting the iteration
of results returned from queries producing rowsets. While data sources for this
can be anything that is iterable, generally these will be populated from
`Zend\Db\Adapter\Driver\ResultInterface` instances.
Result sets must implement the `Zend\Db\ResultSet\ResultSetInterface`, and all
sub-components of zend-db that return a result set as part of their API will
assume an instance of a `ResultSetInterface` should be returned. In most cases,
the prototype pattern will be used by consuming object to clone a prototype of
a `ResultSet` and return a specialized `ResultSet` with a specific data source
injected. `ResultSetInterface` is defined as follows:
```php
use Countable;
use Traversable;
interface ResultSetInterface extends Traversable, Countable
{
public function initialize(mixed $dataSource) : void;
public function getFieldCount() : int;
}
```
## Quick start
`Zend\Db\ResultSet\ResultSet` is the most basic form of a `ResultSet` object
that will expose each row as either an `ArrayObject`-like object or an array of
row data. By default, `Zend\Db\Adapter\Adapter` will use a prototypical
`Zend\Db\ResultSet\ResultSet` object for iterating when using the
`Zend\Db\Adapter\Adapter::query()` method.
The following is an example workflow similar to what one might find inside
`Zend\Db\Adapter\Adapter::query()`:
```php
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\ResultSet\ResultSet;
$statement = $driver->createStatement('SELECT * FROM users');
$statement->prepare();
$result = $statement->execute($parameters);
if ($result instanceof ResultInterface && $result->isQueryResult()) {
$resultSet = new ResultSet;
$resultSet->initialize($result);
foreach ($resultSet as $row) {
echo $row->my_column . PHP_EOL;
}
}
```
## Zend\\Db\\ResultSet\\ResultSet and Zend\\Db\\ResultSet\\AbstractResultSet
For most purposes, either an instance of `Zend\Db\ResultSet\ResultSet` or a
derivative of `Zend\Db\ResultSet\AbstractResultSet` will be used. The
implementation of the `AbstractResultSet` offers the following core
functionality:
```php
namespace Zend\Db\ResultSet;
use Iterator;
abstract class AbstractResultSet implements Iterator, ResultSetInterface
{
public function initialize(array|Iterator|IteratorAggregate|ResultInterface $dataSource) : self;
public function getDataSource() : Iterator|IteratorAggregate|ResultInterface;
public function getFieldCount() : int;
/** Iterator */
public function next() : mixed;
public function key() : string|int;
public function current() : mixed;
public function valid() : bool;
public function rewind() : void;
/** countable */
public function count() : int;
/** get rows as array */
public function toArray() : array;
}
```
## Zend\\Db\\ResultSet\\HydratingResultSet
`Zend\Db\ResultSet\HydratingResultSet` is a more flexible `ResultSet` object
that allows the developer to choose an appropriate "hydration strategy" for
getting row data into a target object. While iterating over results,
`HydratingResultSet` will take a prototype of a target object and clone it once
for each row. The `HydratingResultSet` will then hydrate that clone with the
row data.
The `HydratingResultSet` depends on
[zend-hydrator](https://docs.zendframework.com/zend-hydrator), which you will
need to install:
```bash
$ composer require zendframework/zend-hydrator
```
In the example below, rows from the database will be iterated, and during
iteration, `HydratingResultSet` will use the `Reflection` based hydrator to
inject the row data directly into the protected members of the cloned
`UserEntity` object:
```php
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Hydrator\Reflection as ReflectionHydrator;
class UserEntity
{
protected $first_name;
protected $last_name;
public function getFirstName()
{
return $this->first_name;
}
public function getLastName()
{
return $this->last_name;
}
public function setFirstName($firstName)
{
$this->first_name = $firstName;
}
public function setLastName($lastName)
{
$this->last_name = $lastName;
}
}
$statement = $driver->createStatement($sql);
$statement->prepare($parameters);
$result = $statement->execute();
if ($result instanceof ResultInterface && $result->isQueryResult()) {
$resultSet = new HydratingResultSet(new ReflectionHydrator, new UserEntity);
$resultSet->initialize($result);
foreach ($resultSet as $user) {
echo $user->getFirstName() . ' ' . $user->getLastName() . PHP_EOL;
}
}
```
For more information, see the [zend-hydrator](https://docs.zendframework.com/zend-hydrator/)
documentation to get a better sense of the different strategies that can be
employed in order to populate a target object.

View File

@ -1,98 +0,0 @@
# Row Gateways
`Zend\Db\RowGateway` is a sub-component of zend-db that implements the Row Data
Gateway pattern described in the book [Patterns of Enterprise Application
Architecture](http://www.martinfowler.com/books/eaa.html). Row Data Gateways
model individual rows of a database table, and provide methods such as `save()`
and `delete()` that persist the row to the database. Likewise, after a row from
the database is retrieved, it can then be manipulated and `save()`'d back to
the database in the same position (row), or it can be `delete()`'d from the
table.
`RowGatewayInterface` defines the methods `save()` and `delete()`:
```php
namespace Zend\Db\RowGateway;
interface RowGatewayInterface
{
public function save();
public function delete();
}
```
## Quick start
`RowGateway` is generally used in conjunction with objects that produce
`Zend\Db\ResultSet`s, though it may also be used standalone. To use it
standalone, you need an `Adapter` instance and a set of data to work with.
The following demonstrates a basic use case.
```php
use Zend\Db\RowGateway\RowGateway;
// Query the database:
$resultSet = $adapter->query('SELECT * FROM `user` WHERE `id` = ?', [2]);
// Get array of data:
$rowData = $resultSet->current()->getArrayCopy();
// Create a row gateway:
$rowGateway = new RowGateway('id', 'my_table', $adapter);
$rowGateway->populate($rowData, true);
// Manipulate the row and persist it:
$rowGateway->first_name = 'New Name';
$rowGateway->save();
// Or delete this row:
$rowGateway->delete();
```
The workflow described above is greatly simplified when `RowGateway` is used in
conjunction with the [TableGateway RowGatewayFeature](table-gateway.md#tablegateway-features).
In that paradigm, `select()` operations will produce a `ResultSet` that iterates
`RowGateway` instances.
As an example:
```php
use Zend\Db\TableGateway\Feature\RowGatewayFeature;
use Zend\Db\TableGateway\TableGateway;
$table = new TableGateway('artist', $adapter, new RowGatewayFeature('id'));
$results = $table->select(['id' => 2]);
$artistRow = $results->current();
$artistRow->name = 'New Name';
$artistRow->save();
```
## ActiveRecord Style Objects
If you wish to have custom behaviour in your `RowGateway` objects &mdash;
essentially making them behave similarly to the
[ActiveRecord](http://www.martinfowler.com/eaaCatalog/activeRecord.html)
pattern), pass a prototype object implementing the `RowGatewayInterface` to the
`RowGatewayFeature` constructor instead of a primary key:
```php
use Zend\Db\TableGateway\Feature\RowGatewayFeature;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\RowGateway\RowGatewayInterface;
class Artist implements RowGatewayInterface
{
protected $adapter;
public function __construct($adapter)
{
$this->adapter = $adapter;
}
// ... save() and delete() implementations
}
$table = new TableGateway('artist', $adapter, new RowGatewayFeature(new Artist($adapter)));
```

View File

@ -1,201 +0,0 @@
# DDL Abstraction
`Zend\Db\Sql\Ddl` is a sub-component of `Zend\Db\Sql` allowing creation of DDL
(Data Definition Language) SQL statements. When combined with a platform
specific `Zend\Db\Sql\Sql` object, DDL objects are capable of producing
platform-specific `CREATE TABLE` statements, with specialized data types,
constraints, and indexes for a database/schema.
The following platforms have platform specializations for DDL:
- MySQL
- All databases compatible with ANSI SQL92
## Creating Tables
Like `Zend\Db\Sql` objects, each statement type is represented by a class. For
example, `CREATE TABLE` is modeled by the `CreateTable` class; this is likewise
the same for `ALTER TABLE` (as `AlterTable`), and `DROP TABLE` (as
`DropTable`). You can create instances using a number of approaches:
```php
use Zend\Db\Sql\Ddl;
use Zend\Db\Sql\TableIdentifier;
$table = new Ddl\CreateTable();
// With a table name:
$table = new Ddl\CreateTable('bar');
// With a schema name "foo":
$table = new Ddl\CreateTable(new TableIdentifier('bar', 'foo'));
// Optionally, as a temporary table:
$table = new Ddl\CreateTable('bar', true);
```
You can also set the table after instantiation:
```php
$table->setTable('bar');
```
Currently, columns are added by creating a column object (described in the
[data type table below](#currently-supported-data-types)):
```php
use Zend\Db\Sql\Ddl\Column;
$table->addColumn(new Column\Integer('id'));
$table->addColumn(new Column\Varchar('name', 255));
```
Beyond adding columns to a table, you may also add constraints:
```php
use Zend\Db\Sql\Ddl\Constraint;
$table->addConstraint(new Constraint\PrimaryKey('id'));
$table->addConstraint(
new Constraint\UniqueKey(['name', 'foo'], 'my_unique_key')
);
```
You can also use the `AUTO_INCREMENT` attribute for MySQL:
```php
use Zend\Db\Sql\Ddl\Column;
$column = new Column\Integer('id');
$column->setOption('AUTO_INCREMENT', true);
```
## Altering Tables
Similar to `CreateTable`, you may also use `AlterTable` instances:
```php
use Zend\Db\Sql\Ddl;
use Zend\Db\Sql\TableIdentifier;
$table = new Ddl\AlterTable();
// With a table name:
$table = new Ddl\AlterTable('bar');
// With a schema name "foo":
$table = new Ddl\AlterTable(new TableIdentifier('bar', 'foo'));
// Optionally, as a temporary table:
$table = new Ddl\AlterTable('bar', true);
```
The primary difference between a `CreateTable` and `AlterTable` is that the
`AlterTable` takes into account that the table and its assets already exist.
Therefore, while you still have `addColumn()` and `addConstraint()`, you will
also have the ability to *alter* existing columns:
```php
use Zend\Db\Sql\Ddl\Column;
$table->changeColumn('name', Column\Varchar('new_name', 50));
```
You may also *drop* existing columns or constraints:
```php
$table->dropColumn('foo');
$table->dropConstraint('my_index');
```
## Dropping Tables
To drop a table, create a `DropTable` instance:
```php
use Zend\Db\Sql\Ddl;
use Zend\Db\Sql\TableIdentifier;
// With a table name:
$drop = new Ddl\DropTable('bar');
// With a schema name "foo":
$drop = new Ddl\DropTable(new TableIdentifier('bar', 'foo'));
```
## Executing DDL Statements
After a DDL statement object has been created and configured, at some point you
will need to execute the statement. This requires an `Adapter` instance and a
properly seeded `Sql` instance.
The workflow looks something like this, with `$ddl` being a `CreateTable`,
`AlterTable`, or `DropTable` instance:
```php
use Zend\Db\Sql\Sql;
// Existence of $adapter is assumed.
$sql = new Sql($adapter);
$adapter->query(
$sql->getSqlStringForSqlObject($ddl),
$adapter::QUERY_MODE_EXECUTE
);
```
By passing the `$ddl` object through the `$sql` instance's
`getSqlStringForSqlObject()` method, we ensure that any platform specific
specializations/modifications are utilized to create a platform specific SQL
statement.
Next, using the constant `Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE` ensures
that the SQL statement is not prepared, as most DDL statements on most
platforms cannot be prepared, only executed.
## Currently Supported Data Types
These types exist in the `Zend\Db\Sql\Ddl\Column` namespace. Data types must
implement `Zend\Db\Sql\Ddl\Column\ColumnInterface`.
In alphabetical order:
Type | Arguments For Construction
-----------------|---------------------------
BigInteger | `$name`, `$nullable = false`, `$default = null`, `array $options = array()`
Binary | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()`
Blob | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()`
Boolean | `$name`
Char | `$name`, `length`
Column (generic) | `$name = null`
Date | `$name`
DateTime | `$name`
Decimal | `$name`, `$precision`, `$scale = null`
Float | `$name`, `$digits`, `$decimal` (Note: this class is deprecated as of 2.4.0; use Floating instead)
Floating | `$name`, `$digits`, `$decimal`
Integer | `$name`, `$nullable = false`, `default = null`, `array $options = array()`
Text | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()`
Time | `$name`
Timestamp | `$name`
Varbinary | `$name`, `$length`
Varchar | `$name`, `$length`
Each of the above types can be utilized in any place that accepts a `Column\ColumnInterface`
instance. Currently, this is primarily in `CreateTable::addColumn()` and `AlterTable`'s
`addColumn()` and `changeColumn()` methods.
## Currently Supported Constraint Types
These types exist in the `Zend\Db\Sql\Ddl\Constraint` namespace. Data types
must implement `Zend\Db\Sql\Ddl\Constraint\ConstraintInterface`.
In alphabetical order:
Type | Arguments For Construction
-----------|---------------------------
Check | `$expression`, `$name`
ForeignKey | `$name`, `$column`, `$referenceTable`, `$referenceColumn`, `$onDeleteRule = null`, `$onUpdateRule = null`
PrimaryKey | `$columns`
UniqueKey | `$column`, `$name = null`
Each of the above types can be utilized in any place that accepts a
`Column\ConstraintInterface` instance. Currently, this is primarily in
`CreateTable::addConstraint()` and `AlterTable::addConstraint()`.

View File

@ -1,741 +0,0 @@
# SQL Abstraction
`Zend\Db\Sql` is a SQL abstraction layer for building platform-specific SQL
queries via an object-oriented API. The end result of a `Zend\Db\Sql` object
will be to either produce a `Statement` and `ParameterContainer` that
represents the target query, or a full string that can be directly executed
against the database platform. To achieve this, `Zend\Db\Sql` objects require a
`Zend\Db\Adapter\Adapter` object in order to produce the desired results.
## Quick start
There are four primary tasks associated with interacting with a database
defined by Data Manipulation Language (DML): selecting, inserting, updating,
and deleting. As such, there are four primary classes that developers can
interact with in order to build queries in the `Zend\Db\Sql` namespace:
`Select`, `Insert`, `Update`, and `Delete`.
Since these four tasks are so closely related and generally used together
within the same application, the `Zend\Db\Sql\Sql` class helps you create them
and produce the result you are attempting to achieve.
```php
use Zend\Db\Sql\Sql;
$sql = new Sql($adapter);
$select = $sql->select(); // returns a Zend\Db\Sql\Select instance
$insert = $sql->insert(); // returns a Zend\Db\Sql\Insert instance
$update = $sql->update(); // returns a Zend\Db\Sql\Update instance
$delete = $sql->delete(); // returns a Zend\Db\Sql\Delete instance
```
As a developer, you can now interact with these objects, as described in the
sections below, to customize each query. Once they have been populated with
values, they are ready to either be prepared or executed.
To prepare (using a Select object):
```php
use Zend\Db\Sql\Sql;
$sql = new Sql($adapter);
$select = $sql->select();
$select->from('foo');
$select->where(['id' => 2]);
$statement = $sql->prepareStatementForSqlObject($select);
$results = $statement->execute();
```
To execute (using a Select object)
```php
use Zend\Db\Sql\Sql;
$sql = new Sql($adapter);
$select = $sql->select();
$select->from('foo');
$select->where(['id' => 2]);
$selectString = $sql->buildSqlString($select);
$results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
```
`Zend\\Db\\Sql\\Sql` objects can also be bound to a particular table so that in
obtaining a `Select`, `Insert`, `Update`, or `Delete` instance, the object will be
seeded with the table:
```php
use Zend\Db\Sql\Sql;
$sql = new Sql($adapter, 'foo');
$select = $sql->select();
$select->where(['id' => 2]); // $select already has from('foo') applied
```
## Common interfaces for SQL implementations
Each of these objects implements the following two interfaces:
```php
interface PreparableSqlInterface
{
public function prepareStatement(Adapter $adapter, StatementInterface $statement) : void;
}
interface SqlInterface
{
public function getSqlString(PlatformInterface $adapterPlatform = null) : string;
}
```
Use these functions to produce either (a) a prepared statement, or (b) a string
to execute.
## Select
`Zend\Db\Sql\Select` presents a unified API for building platform-specific SQL
SELECT queries. Instances may be created and consumed without
`Zend\Db\Sql\Sql`:
```php
use Zend\Db\Sql\Select;
$select = new Select();
// or, to produce a $select bound to a specific table
$select = new Select('foo');
```
If a table is provided to the `Select` object, then `from()` cannot be called
later to change the name of the table.
Once you have a valid `Select` object, the following API can be used to further
specify various select statement parts:
```php
class Select extends AbstractSql implements SqlInterface, PreparableSqlInterface
{
const JOIN_INNER = 'inner';
const JOIN_OUTER = 'outer';
const JOIN_LEFT = 'left';
const JOIN_RIGHT = 'right';
const SQL_STAR = '*';
const ORDER_ASCENDING = 'ASC';
const ORDER_DESCENDING = 'DESC';
public $where; // @param Where $where
public function __construct(string|array|TableIdentifier $table = null);
public function from(string|array|TableIdentifier $table) : self;
public function columns(array $columns, bool $prefixColumnsWithTable = true) : self;
public function join(string|array $name, string $on, string|array $columns = self::SQL_STAR, string $type = self::JOIN_INNER) : self;
public function where(Where|callable|string|array|PredicateInterface $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self;
public function group(string|array $group);
public function having(Having|callable|string|array $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self;
public function order(string|array $order) : self;
public function limit(int $limit) : self;
public function offset(int $offset) : self;
}
```
### from()
```php
// As a string:
$select->from('foo');
// As an array to specify an alias
// (produces SELECT "t".* FROM "table" AS "t")
$select->from(['t' => 'table']);
// Using a Sql\TableIdentifier:
// (same output as above)
$select->from(['t' => new TableIdentifier('table')]);
```
### columns()
```php
// As an array of names
$select->columns(['foo', 'bar']);
// As an associative array with aliases as the keys
// (produces 'bar' AS 'foo', 'bax' AS 'baz')
$select->columns([
'foo' => 'bar',
'baz' => 'bax'
]);
// Sql function call on the column
// (produces CONCAT_WS('/', 'bar', 'bax') AS 'foo')
$select->columns([
'foo' => new \Zend\Db\Sql\Expression("CONCAT_WS('/', 'bar', 'bax')")
]);
```
### join()
```php
$select->join(
'foo', // table name
'id = bar.id', // expression to join on (will be quoted by platform object before insertion),
['bar', 'baz'], // (optional) list of columns, same requirements as columns() above
$select::JOIN_OUTER // (optional), one of inner, outer, left, right also represented by constants in the API
);
$select
->from(['f' => 'foo']) // base table
->join(
['b' => 'bar'], // join table with alias
'f.foo_id = b.foo_id' // join expression
);
```
### where(), having()
`Zend\Db\Sql\Select` provides bit of flexibility as it regards to what kind of
parameters are acceptable when calling `where()` or `having()`. The method
signature is listed as:
```php
/**
* Create where clause
*
* @param Where|callable|string|array $predicate
* @param string $combination One of the OP_* constants from Predicate\PredicateSet
* @return Select
*/
public function where($predicate, $combination = Predicate\PredicateSet::OP_AND);
```
If you provide a `Zend\Db\Sql\Where` instance to `where()` or a
`Zend\Db\Sql\Having` instance to `having()`, any previous internal instances
will be replaced completely. When either instance is processed, this object will
be iterated to produce the WHERE or HAVING section of the SELECT statement.
If you provide a PHP callable to `where()` or `having()`, this function will be
called with the `Select`'s `Where`/`Having` instance as the only parameter.
This enables code like the following:
```php
$select->where(function (Where $where) {
$where->like('username', 'ralph%');
});
```
If you provide a *string*, this string will be used to create a
`Zend\Db\Sql\Predicate\Expression` instance, and its contents will be applied
as-is, with no quoting:
```php
// SELECT "foo".* FROM "foo" WHERE x = 5
$select->from('foo')->where('x = 5');
```
If you provide an array with integer indices, the value can be one of:
- a string; this will be used to build a `Predicate\Expression`.
- any object implementing `Predicate\PredicateInterface`.
In either case, the instances are pushed onto the `Where` stack with the
`$combination` provided (defaulting to `AND`).
As an example:
```php
// SELECT "foo".* FROM "foo" WHERE x = 5 AND y = z
$select->from('foo')->where(['x = 5', 'y = z']);
```
If you provide an associative array with string keys, any value with a string
key will be cast as follows:
PHP value | Predicate type
--------- | --------------
`null` | `Predicate\IsNull`
`array` | `Predicate\In`
`string` | `Predicate\Operator`, where the key is the identifier.
As an example:
```php
// SELECT "foo".* FROM "foo" WHERE "c1" IS NULL AND "c2" IN (?, ?, ?) AND "c3" IS NOT NULL
$select->from('foo')->where([
'c1' => null,
'c2' => [1, 2, 3],
new \Zend\Db\Sql\Predicate\IsNotNull('c3'),
]);
```
As another example of complex queries with nested conditions e.g.
```sql
SELECT * WHERE (column1 is null or column1 = 2) AND (column2 = 3)
```
you need to use the `nest()` and `unnest()` methods, as follows:
```php
$select->where->nest() // bracket opened
->isNull('column1')
->or
->equalTo('column1', '2')
->unnest(); // bracket closed
->equalTo('column2', '3');
```
### order()
```php
$select = new Select;
$select->order('id DESC'); // produces 'id' DESC
$select = new Select;
$select
->order('id DESC')
->order('name ASC, age DESC'); // produces 'id' DESC, 'name' ASC, 'age' DESC
$select = new Select;
$select->order(['name ASC', 'age DESC']); // produces 'name' ASC, 'age' DESC
```
### limit() and offset()
```php
$select = new Select;
$select->limit(5); // always takes an integer/numeric
$select->offset(10); // similarly takes an integer/numeric
```
## Insert
The Insert API:
```php
class Insert implements SqlInterface, PreparableSqlInterface
{
const VALUES_MERGE = 'merge';
const VALUES_SET = 'set';
public function __construct(string|TableIdentifier $table = null);
public function into(string|TableIdentifier $table) : self;
public function columns(array $columns) : self;
public function values(array $values, string $flag = self::VALUES_SET) : self;
}
```
As with `Select`, the table may be provided during instantiation or via the
`into()` method.
### columns()
```php
$insert->columns(['foo', 'bar']); // set the valid columns
```
### values()
```php
// The default behavior of values is to set the values;
// successive calls will not preserve values from previous calls.
$insert->values([
'col_1' => 'value1',
'col_2' => 'value2',
]);
```
```php
// To merge values with previous calls, provide the appropriate flag:
$insert->values(['col_2' => 'value2'], $insert::VALUES_MERGE);
```
## Update
```php
class Update
{
const VALUES_MERGE = 'merge';
const VALUES_SET = 'set';
public $where; // @param Where $where
public function __construct(string|TableIdentifier $table = null);
public function table(string|TableIdentifier $table) : self;
public function set(array $values, string $flag = self::VALUES_SET) : self;
public function where(Where|callable|string|array|PredicateInterface $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self;
}
```
### set()
```php
$update->set(['foo' => 'bar', 'baz' => 'bax']);
```
### where()
See the [section on Where and Having](#where-and-having).
## Delete
```php
class Delete
{
public $where; // @param Where $where
public function __construct(string|TableIdentifier $table = null);
public function from(string|TableIdentifier $table);
public function where(Where|callable|string|array|PredicateInterface $predicate, string $combination = Predicate\PredicateSet::OP_AND) : self;
}
```
### where()
See the [section on Where and Having](#where-and-having).
## Where and Having
In the following, we will talk about `Where`; note, however, that `Having`
utilizes the same API.
Effectively, `Where` and `Having` extend from the same base object, a
`Predicate` (and `PredicateSet`). All of the parts that make up a WHERE or
HAVING clause that are AND'ed or OR'd together are called *predicates*. The
full set of predicates is called a `PredicateSet`. A `Predicate` generally
contains the values (and identifiers) separate from the fragment they belong to
until the last possible moment when the statement is either prepared
(parameteritized) or executed. In parameterization, the parameters will be
replaced with their proper placeholder (a named or positional parameter), and
the values stored inside an `Adapter\ParameterContainer`. When executed, the
values will be interpolated into the fragments they belong to and properly
quoted.
In the `Where`/`Having` API, a distinction is made between what elements are
considered identifiers (`TYPE_IDENTIFIER`) and which are values (`TYPE_VALUE`).
There is also a special use case type for literal values (`TYPE_LITERAL`). All
element types are expressed via the `Zend\Db\Sql\ExpressionInterface`
interface.
> ### Literals
>
> In ZF 2.1, an actual `Literal` type was added. `Zend\Db\Sql` now makes the
> distinction that literals will not have any parameters that need
> interpolating, while `Expression` objects *might* have parameters that need
> interpolating. In cases where there are parameters in an `Expression`,
> `Zend\Db\Sql\AbstractSql` will do its best to identify placeholders when the
> `Expression` is processed during statement creation. In short, if you don't
> have parameters, use `Literal` objects.
The `Where` and `Having` API is that of `Predicate` and `PredicateSet`:
```php
// Where & Having extend Predicate:
class Predicate extends PredicateSet
{
public $and;
public $or;
public $AND;
public $OR;
public $NEST;
public $UNNEST;
public function nest() : Predicate;
public function setUnnest(Predicate $predicate) : void;
public function unnest() : Predicate;
public function equalTo(
int|float|bool|string $left,
int|float|bool|string $right,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
) : self;
public function notEqualTo(
int|float|bool|string $left,
int|float|bool|string $right,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
) : self;
public function lessThan(
int|float|bool|string $left,
int|float|bool|string $right,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
) : self;
public function greaterThan(
int|float|bool|string $left,
int|float|bool|string $right,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
) : self;
public function lessThanOrEqualTo(
int|float|bool|string $left,
int|float|bool|string $right,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
) : self;
public function greaterThanOrEqualTo(
int|float|bool|string $left,
int|float|bool|string $right,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
) : self;
public function like(string $identifier, string $like) : self;
public function notLike(string $identifier, string $notLike) : self;
public function literal(string $literal) : self;
public function expression(string $expression, array $parameters = null) : self;
public function isNull(string $identifier) : self;
public function isNotNull(string $identifier) : self;
public function in(string $identifier, array $valueSet = []) : self;
public function notIn(string $identifier, array $valueSet = []) : self;
public function between(
string $identifier,
int|float|string $minValue,
int|float|string $maxValue
) : self;
public function notBetween(
string $identifier,
int|float|string $minValue,
int|float|string $maxValue
) : self;
public function predicate(PredicateInterface $predicate) : self;
// Inherited From PredicateSet
public function addPredicate(PredicateInterface $predicate, $combination = null) : self;
public function getPredicates() PredicateInterface[];
public function orPredicate(PredicateInterface $predicate) : self;
public function andPredicate(PredicateInterface $predicate) : self;
public function getExpressionData() : array;
public function count() : int;
}
```
Each method in the API will produce a corresponding `Predicate` object of a similarly named
type, as described below.
### equalTo(), lessThan(), greaterThan(), lessThanOrEqualTo(), greaterThanOrEqualTo()
```php
$where->equalTo('id', 5);
// The above is equivalent to:
$where->addPredicate(
new Predicate\Operator($left, Operator::OPERATOR_EQUAL_TO, $right, $leftType, $rightType)
);
```
Operators use the following API:
```php
class Operator implements PredicateInterface
{
const OPERATOR_EQUAL_TO = '=';
const OP_EQ = '=';
const OPERATOR_NOT_EQUAL_TO = '!=';
const OP_NE = '!=';
const OPERATOR_LESS_THAN = '<';
const OP_LT = '<';
const OPERATOR_LESS_THAN_OR_EQUAL_TO = '<=';
const OP_LTE = '<=';
const OPERATOR_GREATER_THAN = '>';
const OP_GT = '>';
const OPERATOR_GREATER_THAN_OR_EQUAL_TO = '>=';
const OP_GTE = '>=';
public function __construct(
int|float|bool|string $left = null,
string $operator = self::OPERATOR_EQUAL_TO,
int|float|bool|string $right = null,
string $leftType = self::TYPE_IDENTIFIER,
string $rightType = self::TYPE_VALUE
);
public function setLeft(int|float|bool|string $left);
public function getLeft() : int|float|bool|string;
public function setLeftType(string $type) : self;
public function getLeftType() : string;
public function setOperator(string $operator);
public function getOperator() : string;
public function setRight(int|float|bool|string $value) : self;
public function getRight() : int|float|bool|string;
public function setRightType(string $type) : self;
public function getRightType() : string;
public function getExpressionData() : array;
}
```
### like($identifier, $like), notLike($identifier, $notLike)
```php
$where->like($identifier, $like):
// The above is equivalent to:
$where->addPredicate(
new Predicate\Like($identifier, $like)
);
```
The following is the `Like` API:
```php
class Like implements PredicateInterface
{
public function __construct(string $identifier = null, string $like = null);
public function setIdentifier(string $identifier) : self;
public function getIdentifier() : string;
public function setLike(string $like) : self;
public function getLike() : string;
}
```
### literal($literal)
```php
$where->literal($literal);
// The above is equivalent to:
$where->addPredicate(
new Predicate\Literal($literal)
);
```
The following is the `Literal` API:
```php
class Literal implements ExpressionInterface, PredicateInterface
{
const PLACEHOLDER = '?';
public function __construct(string $literal = '');
public function setLiteral(string $literal) : self;
public function getLiteral() : string;
}
```
### expression($expression, $parameter)
```php
$where->expression($expression, $parameter);
// The above is equivalent to:
$where->addPredicate(
new Predicate\Expression($expression, $parameter)
);
```
The following is the `Expression` API:
```php
class Expression implements ExpressionInterface, PredicateInterface
{
const PLACEHOLDER = '?';
public function __construct(
string $expression = null,
int|float|bool|string|array $valueParameter = null
/* [, $valueParameter, ... ] */
);
public function setExpression(string $expression) : self;
public function getExpression() : string;
public function setParameters(int|float|bool|string|array $parameters) : self;
public function getParameters() : array;
}
```
### isNull($identifier)
```php
$where->isNull($identifier);
// The above is equivalent to:
$where->addPredicate(
new Predicate\IsNull($identifier)
);
```
The following is the `IsNull` API:
```php
class IsNull implements PredicateInterface
{
public function __construct(string $identifier = null);
public function setIdentifier(string $identifier) : self;
public function getIdentifier() : string;
}
```
### isNotNull($identifier)
```php
$where->isNotNull($identifier);
// The above is equivalent to:
$where->addPredicate(
new Predicate\IsNotNull($identifier)
);
```
The following is the `IsNotNull` API:
```php
class IsNotNull implements PredicateInterface
{
public function __construct(string $identifier = null);
public function setIdentifier(string $identifier) : self;
public function getIdentifier() : string;
}
```
### in($identifier, $valueSet), notIn($identifier, $valueSet)
```php
$where->in($identifier, $valueSet);
// The above is equivalent to:
$where->addPredicate(
new Predicate\In($identifier, $valueSet)
);
```
The following is the `In` API:
```php
class In implements PredicateInterface
{
public function __construct(
string|array $identifier = null,
array|Select $valueSet = null
);
public function setIdentifier(string|array $identifier) : self;
public function getIdentifier() : string|array;
public function setValueSet(array|Select $valueSet) : self;
public function getValueSet() : array|Select;
}
```
### between($identifier, $minValue, $maxValue), notBetween($identifier, $minValue, $maxValue)
```php
$where->between($identifier, $minValue, $maxValue);
// The above is equivalent to:
$where->addPredicate(
new Predicate\Between($identifier, $minValue, $maxValue)
);
```
The following is the `Between` API:
```php
class Between implements PredicateInterface
{
public function __construct(
string $identifier = null,
int|float|string $minValue = null,
int|float|string $maxValue = null
);
public function setIdentifier(string $identifier) : self;
public function getIdentifier() : string;
public function setMinValue(int|float|string $minValue) : self;
public function getMinValue() : int|float|string;
public function setMaxValue(int|float|string $maxValue) : self;
public function getMaxValue() : int|float|string;
public function setSpecification(string $specification);
}
```

View File

@ -1,217 +0,0 @@
# Table Gateways
The Table Gateway subcomponent provides an object-oriented representation of a
database table; its methods mirror the most common table operations. In code,
the interface resembles:
```php
namespace Zend\Db\TableGateway;
use Zend\Db\ResultSet\ResultSetInterface;
use Zend\Db\Sql\Where;
interface TableGatewayInterface
{
public function getTable() : string;
public function select(Where|callable|string|array $where = null) : ResultSetInterface;
public function insert(array $set) : int;
public function update(
array $set,
Where|callable|string|array $where = null,
array $joins = null
) : int;
public function delete(Where|callable|string|array $where) : int;
}
```
There are two primary implementations of the `TableGatewayInterface`,
`AbstractTableGateway` and `TableGateway`. The `AbstractTableGateway` is an
abstract basic implementation that provides functionality for `select()`,
`insert()`, `update()`, `delete()`, as well as an additional API for doing
these same kinds of tasks with explicit `Zend\Db\Sql` objects: `selectWith()`,
`insertWith()`, `updateWith()`, and `deleteWith()`. In addition,
AbstractTableGateway also implements a "Feature" API, that allows for expanding
the behaviors of the base `TableGateway` implementation without having to
extend the class with this new functionality. The `TableGateway` concrete
implementation simply adds a sensible constructor to the `AbstractTableGateway`
class so that out-of-the-box, `TableGateway` does not need to be extended in
order to be consumed and utilized to its fullest.
## Quick start
The following example uses `Zend\Db\TableGateway\TableGateway`, which defines
the following API:
```php
namespace Zend\Db\TableGateway;
use Zend\Db\Adapter\AdapterInterface;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\ResultSet\ResultSetInterface;
use Zend\Db\Sql;
use Zend\Db\Sql\TableIdentifier;
class TableGateway extends AbstractTableGateway
{
public $lastInsertValue;
public $table;
public $adapter;
public function __construct(
string|TableIdentifier $table,
AdapterInterface $adapter,
Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[] $features = null,
ResultSetInterface $resultSetPrototype = null,
Sql\Sql $sql = null
);
/** Inherited from AbstractTableGateway */
public function isInitialized() : bool;
public function initialize() : void;
public function getTable() : string;
public function getAdapter() : AdapterInterface;
public function getColumns() : array;
public function getFeatureSet() Feature\FeatureSet;
public function getResultSetPrototype() : ResultSetInterface;
public function getSql() | Sql\Sql;
public function select(Sql\Where|callable|string|array $where = null) : ResultSetInterface;
public function selectWith(Sql\Select $select) : ResultSetInterface;
public function insert(array $set) : int;
public function insertWith(Sql\Insert $insert) | int;
public function update(
array $set,
Sql\Where|callable|string|array $where = null,
array $joins = null
) : int;
public function updateWith(Sql\Update $update) : int;
public function delete(Sql\Where|callable|string|array $where) : int;
public function deleteWith(Sql\Delete $delete) : int;
public function getLastInsertValue() : int;
}
```
The concrete `TableGateway` object uses constructor injection for getting
dependencies and options into the instance. The table name and an instance of
an `Adapter` are all that is required to create an instance.
Out of the box, this implementation makes no assumptions about table structure
or metadata, and when `select()` is executed, a simple `ResultSet` object with
the populated `Adapter`'s `Result` (the datasource) will be returned and ready
for iteration.
```php
use Zend\Db\TableGateway\TableGateway;
$projectTable = new TableGateway('project', $adapter);
$rowset = $projectTable->select(['type' => 'PHP']);
echo 'Projects of type PHP: ' . PHP_EOL;
foreach ($rowset as $projectRow) {
echo $projectRow['name'] . PHP_EOL;
}
// Or, when expecting a single row:
$artistTable = new TableGateway('artist', $adapter);
$rowset = $artistTable->select(['id' => 2]);
$artistRow = $rowset->current();
var_dump($artistRow);
```
The `select()` method takes the same arguments as
`Zend\Db\Sql\Select::where()`; arguments will be passed to the `Select`
instance used to build the SELECT query. This means the following is possible:
```php
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Select;
$artistTable = new TableGateway('artist', $adapter);
// Search for at most 2 artists who's name starts with Brit, ascending:
$rowset = $artistTable->select(function (Select $select) {
$select->where->like('name', 'Brit%');
$select->order('name ASC')->limit(2);
});
```
## TableGateway Features
The Features API allows for extending the functionality of the base
`TableGateway` object without having to polymorphically extend the base class.
This allows for a wider array of possible mixing and matching of features to
achieve a particular behavior that needs to be attained to make the base
implementation of `TableGateway` useful for a particular problem.
With the `TableGateway` object, features should be injected through the
constructor. The constructor can take features in 3 different forms:
- as a single `Feature` instance
- as a `FeatureSet` instance
- as an array of `Feature` instances
There are a number of features built-in and shipped with zend-db:
- `GlobalAdapterFeature`: the ability to use a global/static adapter without
needing to inject it into a `TableGateway` instance. This is only useful when
you are extending the `AbstractTableGateway` implementation:
```php
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\TableGateway\Feature;
class MyTableGateway extends AbstractTableGateway
{
public function __construct()
{
$this->table = 'my_table';
$this->featureSet = new Feature\FeatureSet();
$this->featureSet->addFeature(new Feature\GlobalAdapterFeature());
$this->initialize();
}
}
// elsewhere in code, in a bootstrap
Zend\Db\TableGateway\Feature\GlobalAdapterFeature::setStaticAdapter($adapter);
// in a controller, or model somewhere
$table = new MyTableGateway(); // adapter is statically loaded
```
- `MasterSlaveFeature`: the ability to use a master adapter for `insert()`,
`update()`, and `delete()`, but switch to a slave adapter for all `select()`
operations.
```php
$table = new TableGateway('artist', $adapter, new Feature\MasterSlaveFeature($slaveAdapter));
```
- `MetadataFeature`: the ability populate `TableGateway` with column
information from a `Metadata` object. It will also store the primary key
information in case the `RowGatewayFeature` needs to consume this information.
```php
$table = new TableGateway('artist', $adapter, new Feature\MetadataFeature());
```
- `EventFeature`: the ability to compose a
[zend-eventmanager](https://github.com/zendframework/zend-eventmanager)
`EventManager` instance within your `TableGateway` instance, and attach
listeners to the various events of its lifecycle.
```php
$table = new TableGateway('artist', $adapter, new Feature\EventFeature($eventManagerInstance));
```
- `RowGatewayFeature`: the ability for `select()` to return a `ResultSet` object that upon iteration
will return a `RowGateway` instance for each row.
```php
$table = new TableGateway('artist', $adapter, new Feature\RowGatewayFeature('id'));
$results = $table->select(['id' => 2]);
$artistRow = $results->current();
$artistRow->name = 'New Name';
$artistRow->save();
```

View File

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml" />
<rule ref="PSR1.Files.SideEffects">
<exclude-pattern>*/test/unit/Adapter/Driver/IbmDb2/StatementTest.php</exclude-pattern>
</rule>
<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>

View File

@ -1,436 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
use Zend\Db\ResultSet;
/**
* @property Driver\DriverInterface $driver
* @property Platform\PlatformInterface $platform
*/
class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface
{
/**
* Query Mode Constants
*/
const QUERY_MODE_EXECUTE = 'execute';
const QUERY_MODE_PREPARE = 'prepare';
/**
* Prepare Type Constants
*/
const PREPARE_TYPE_POSITIONAL = 'positional';
const PREPARE_TYPE_NAMED = 'named';
const FUNCTION_FORMAT_PARAMETER_NAME = 'formatParameterName';
const FUNCTION_QUOTE_IDENTIFIER = 'quoteIdentifier';
const FUNCTION_QUOTE_VALUE = 'quoteValue';
const VALUE_QUOTE_SEPARATOR = 'quoteSeparator';
/**
* @var Driver\DriverInterface
*/
protected $driver = null;
/**
* @var Platform\PlatformInterface
*/
protected $platform = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var ResultSet\ResultSetInterface
*/
protected $queryResultSetPrototype = null;
/**
* @var Driver\StatementInterface
*/
protected $lastPreparedStatement = null;
/**
* @param Driver\DriverInterface|array $driver
* @param Platform\PlatformInterface $platform
* @param ResultSet\ResultSetInterface $queryResultPrototype
* @param Profiler\ProfilerInterface $profiler
* @throws Exception\InvalidArgumentException
*/
public function __construct(
$driver,
Platform\PlatformInterface $platform = null,
ResultSet\ResultSetInterface $queryResultPrototype = null,
Profiler\ProfilerInterface $profiler = null
) {
// first argument can be an array of parameters
$parameters = [];
if (is_array($driver)) {
$parameters = $driver;
if ($profiler === null && isset($parameters['profiler'])) {
$profiler = $this->createProfiler($parameters);
}
$driver = $this->createDriver($parameters);
} elseif (! $driver instanceof Driver\DriverInterface) {
throw new Exception\InvalidArgumentException(
'The supplied or instantiated driver object does not implement Zend\Db\Adapter\Driver\DriverInterface'
);
}
$driver->checkEnvironment();
$this->driver = $driver;
if ($platform === null) {
$platform = $this->createPlatform($parameters);
}
$this->platform = $platform;
$this->queryResultSetPrototype = ($queryResultPrototype) ?: new ResultSet\ResultSet();
if ($profiler) {
$this->setProfiler($profiler);
}
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->driver instanceof Profiler\ProfilerAwareInterface) {
$this->driver->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* getDriver()
*
* @throws Exception\RuntimeException
* @return Driver\DriverInterface
*/
public function getDriver()
{
if ($this->driver === null) {
throw new Exception\RuntimeException('Driver has not been set or configured for this adapter.');
}
return $this->driver;
}
/**
* @return Platform\PlatformInterface
*/
public function getPlatform()
{
return $this->platform;
}
/**
* @return ResultSet\ResultSetInterface
*/
public function getQueryResultSetPrototype()
{
return $this->queryResultSetPrototype;
}
public function getCurrentSchema()
{
return $this->driver->getConnection()->getCurrentSchema();
}
/**
* query() is a convenience function
*
* @param string $sql
* @param string|array|ParameterContainer $parametersOrQueryMode
* @param \Zend\Db\ResultSet\ResultSetInterface $resultPrototype
* @throws Exception\InvalidArgumentException
* @return Driver\StatementInterface|ResultSet\ResultSet
*/
public function query(
$sql,
$parametersOrQueryMode = self::QUERY_MODE_PREPARE,
ResultSet\ResultSetInterface $resultPrototype = null
) {
if (is_string($parametersOrQueryMode)
&& in_array($parametersOrQueryMode, [self::QUERY_MODE_PREPARE, self::QUERY_MODE_EXECUTE])
) {
$mode = $parametersOrQueryMode;
$parameters = null;
} elseif (is_array($parametersOrQueryMode) || $parametersOrQueryMode instanceof ParameterContainer) {
$mode = self::QUERY_MODE_PREPARE;
$parameters = $parametersOrQueryMode;
} else {
throw new Exception\InvalidArgumentException(
'Parameter 2 to this method must be a flag, an array, or ParameterContainer'
);
}
if ($mode == self::QUERY_MODE_PREPARE) {
$this->lastPreparedStatement = null;
$this->lastPreparedStatement = $this->driver->createStatement($sql);
$this->lastPreparedStatement->prepare();
if (is_array($parameters) || $parameters instanceof ParameterContainer) {
if (is_array($parameters)) {
$this->lastPreparedStatement->setParameterContainer(new ParameterContainer($parameters));
} else {
$this->lastPreparedStatement->setParameterContainer($parameters);
}
$result = $this->lastPreparedStatement->execute();
} else {
return $this->lastPreparedStatement;
}
} else {
$result = $this->driver->getConnection()->execute($sql);
}
if ($result instanceof Driver\ResultInterface && $result->isQueryResult()) {
$resultSet = clone ($resultPrototype ?: $this->queryResultSetPrototype);
$resultSet->initialize($result);
return $resultSet;
}
return $result;
}
/**
* Create statement
*
* @param string $initialSql
* @param ParameterContainer $initialParameters
* @return Driver\StatementInterface
*/
public function createStatement($initialSql = null, $initialParameters = null)
{
$statement = $this->driver->createStatement($initialSql);
if ($initialParameters === null
|| ! $initialParameters instanceof ParameterContainer
&& is_array($initialParameters)
) {
$initialParameters = new ParameterContainer((is_array($initialParameters) ? $initialParameters : []));
}
$statement->setParameterContainer($initialParameters);
return $statement;
}
public function getHelpers()
{
$functions = [];
$platform = $this->platform;
foreach (func_get_args() as $arg) {
switch ($arg) {
case self::FUNCTION_QUOTE_IDENTIFIER:
$functions[] = function ($value) use ($platform) {
return $platform->quoteIdentifier($value);
};
break;
case self::FUNCTION_QUOTE_VALUE:
$functions[] = function ($value) use ($platform) {
return $platform->quoteValue($value);
};
break;
}
}
}
/**
* @param $name
* @throws Exception\InvalidArgumentException
* @return Driver\DriverInterface|Platform\PlatformInterface
*/
public function __get($name)
{
switch (strtolower($name)) {
case 'driver':
return $this->driver;
case 'platform':
return $this->platform;
default:
throw new Exception\InvalidArgumentException('Invalid magic property on adapter');
}
}
/**
* @param array $parameters
* @return Driver\DriverInterface
* @throws \InvalidArgumentException
* @throws Exception\InvalidArgumentException
*/
protected function createDriver($parameters)
{
if (! isset($parameters['driver'])) {
throw new Exception\InvalidArgumentException(
__FUNCTION__ . ' expects a "driver" key to be present inside the parameters'
);
}
if ($parameters['driver'] instanceof Driver\DriverInterface) {
return $parameters['driver'];
}
if (! is_string($parameters['driver'])) {
throw new Exception\InvalidArgumentException(
__FUNCTION__ . ' expects a "driver" to be a string or instance of DriverInterface'
);
}
$options = [];
if (isset($parameters['options'])) {
$options = (array) $parameters['options'];
unset($parameters['options']);
}
$driverName = strtolower($parameters['driver']);
switch ($driverName) {
case 'mysqli':
$driver = new Driver\Mysqli\Mysqli($parameters, null, null, $options);
break;
case 'sqlsrv':
$driver = new Driver\Sqlsrv\Sqlsrv($parameters);
break;
case 'oci8':
$driver = new Driver\Oci8\Oci8($parameters);
break;
case 'pgsql':
$driver = new Driver\Pgsql\Pgsql($parameters);
break;
case 'ibmdb2':
$driver = new Driver\IbmDb2\IbmDb2($parameters);
break;
case 'pdo':
default:
if ($driverName == 'pdo' || strpos($driverName, 'pdo') === 0) {
$driver = new Driver\Pdo\Pdo($parameters);
}
}
if (! isset($driver) || ! $driver instanceof Driver\DriverInterface) {
throw new Exception\InvalidArgumentException('DriverInterface expected', null, null);
}
return $driver;
}
/**
* @param array $parameters
* @return Platform\PlatformInterface
*/
protected function createPlatform(array $parameters)
{
if (isset($parameters['platform'])) {
$platformName = $parameters['platform'];
} elseif ($this->driver instanceof Driver\DriverInterface) {
$platformName = $this->driver->getDatabasePlatformName(Driver\DriverInterface::NAME_FORMAT_CAMELCASE);
} else {
throw new Exception\InvalidArgumentException(
'A platform could not be determined from the provided configuration'
);
}
// currently only supported by the IbmDb2 & Oracle concrete implementations
$options = (isset($parameters['platform_options'])) ? $parameters['platform_options'] : [];
switch ($platformName) {
case 'Mysql':
// mysqli or pdo_mysql driver
if ($this->driver instanceof Driver\Mysqli\Mysqli || $this->driver instanceof Driver\Pdo\Pdo) {
$driver = $this->driver;
} else {
$driver = null;
}
return new Platform\Mysql($driver);
case 'SqlServer':
// PDO is only supported driver for quoting values in this platform
return new Platform\SqlServer(($this->driver instanceof Driver\Pdo\Pdo) ? $this->driver : null);
case 'Oracle':
if ($this->driver instanceof Driver\Oci8\Oci8 || $this->driver instanceof Driver\Pdo\Pdo) {
$driver = $this->driver;
} else {
$driver = null;
}
return new Platform\Oracle($options, $driver);
case 'Sqlite':
// PDO is only supported driver for quoting values in this platform
if ($this->driver instanceof Driver\Pdo\Pdo) {
return new Platform\Sqlite($this->driver);
}
return new Platform\Sqlite(null);
case 'Postgresql':
// pgsql or pdo postgres driver
if ($this->driver instanceof Driver\Pgsql\Pgsql || $this->driver instanceof Driver\Pdo\Pdo) {
$driver = $this->driver;
} else {
$driver = null;
}
return new Platform\Postgresql($driver);
case 'IbmDb2':
// ibm_db2 driver escaping does not need an action connection
return new Platform\IbmDb2($options);
default:
return new Platform\Sql92();
}
}
/**
*
* @param array $parameters
* @return Profiler\ProfilerInterface
* @throws Exception\InvalidArgumentException
*/
protected function createProfiler($parameters)
{
if ($parameters['profiler'] instanceof Profiler\ProfilerInterface) {
$profiler = $parameters['profiler'];
} elseif (is_bool($parameters['profiler'])) {
$profiler = ($parameters['profiler'] == true) ? new Profiler\Profiler : null;
} else {
throw new Exception\InvalidArgumentException(
'"profiler" parameter must be an instance of ProfilerInterface or a boolean'
);
}
return $profiler;
}
/**
* @param array $parameters
* @return Driver\DriverInterface
* @throws \InvalidArgumentException
* @throws Exception\InvalidArgumentException
* @deprecated
*/
protected function createDriverFromParameters(array $parameters)
{
return $this->createDriver($parameters);
}
/**
* @param Driver\DriverInterface $driver
* @return Platform\PlatformInterface
* @deprecated
*/
protected function createPlatformFromDriver(Driver\DriverInterface $driver)
{
return $this->createPlatform($driver);
}
}

View File

@ -1,125 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\AbstractFactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
/**
* Database adapter abstract service factory.
*
* Allows configuring several database instances (such as writer and reader).
*/
class AdapterAbstractServiceFactory implements AbstractFactoryInterface
{
/**
* @var array
*/
protected $config;
/**
* Can we create an adapter by the requested name?
*
* @param ContainerInterface $container
* @param string $requestedName
* @return bool
*/
public function canCreate(ContainerInterface $container, $requestedName)
{
$config = $this->getConfig($container);
if (empty($config)) {
return false;
}
return (
isset($config[$requestedName])
&& is_array($config[$requestedName])
&& ! empty($config[$requestedName])
);
}
/**
* Determine if we can create a service with name (SM v2 compatibility)
*
* @param ServiceLocatorInterface $serviceLocator
* @param string $name
* @param string $requestedName
* @return bool
*/
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->canCreate($serviceLocator, $requestedName);
}
/**
* Create a DB adapter
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return Adapter
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $this->getConfig($container);
return new Adapter($config[$requestedName]);
}
/**
* Create service with name
*
* @param ServiceLocatorInterface $serviceLocator
* @param string $name
* @param string $requestedName
* @return Adapter
*/
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this($serviceLocator, $requestedName);
}
/**
* Get db configuration, if any
*
* @param ContainerInterface $container
* @return array
*/
protected function getConfig(ContainerInterface $container)
{
if ($this->config !== null) {
return $this->config;
}
if (! $container->has('config')) {
$this->config = [];
return $this->config;
}
$config = $container->get('config');
if (! isset($config['db'])
|| ! is_array($config['db'])
) {
$this->config = [];
return $this->config;
}
$config = $config['db'];
if (! isset($config['adapters'])
|| ! is_array($config['adapters'])
) {
$this->config = [];
return $this->config;
}
$this->config = $config['adapters'];
return $this->config;
}
}

View File

@ -1,21 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
interface AdapterAwareInterface
{
/**
* Set db adapter
*
* @param Adapter $adapter
* @return AdapterAwareInterface
*/
public function setDbAdapter(Adapter $adapter);
}

View File

@ -1,31 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
trait AdapterAwareTrait
{
/**
* @var Adapter
*/
protected $adapter = null;
/**
* Set db adapter
*
* @param Adapter $adapter
* @return self Provides a fluent interface
*/
public function setDbAdapter(Adapter $adapter)
{
$this->adapter = $adapter;
return $this;
}
}

View File

@ -1,28 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
/**
*
* @property Driver\DriverInterface $driver
* @property Platform\PlatformInterface $platform
*/
interface AdapterInterface
{
/**
* @return Driver\DriverInterface
*/
public function getDriver();
/**
* @return Platform\PlatformInterface
*/
public function getPlatform();
}

View File

@ -1,42 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class AdapterServiceFactory implements FactoryInterface
{
/**
* Create db adapter service
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return Adapter
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$config = $container->get('config');
return new Adapter($config['db']);
}
/**
* Create db adapter service (v2)
*
* @param ServiceLocatorInterface $container
* @return Adapter
*/
public function createService(ServiceLocatorInterface $container)
{
return $this($container, Adapter::class);
}
}

View File

@ -1,135 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver;
use Zend\Db\Adapter\Profiler\ProfilerAwareInterface;
use Zend\Db\Adapter\Profiler\ProfilerInterface;
abstract class AbstractConnection implements ConnectionInterface, ProfilerAwareInterface
{
/**
* @var array
*/
protected $connectionParameters = [];
/**
* @var string|null
*/
protected $driverName;
/**
* @var boolean
*/
protected $inTransaction = false;
/**
* Nested transactions count.
*
* @var integer
*/
protected $nestedTransactionsCount = 0;
/**
* @var ProfilerInterface|null
*/
protected $profiler;
/**
* @var resource|null
*/
protected $resource;
/**
* {@inheritDoc}
*/
public function disconnect()
{
if ($this->isConnected()) {
$this->resource = null;
}
return $this;
}
/**
* Get connection parameters
*
* @return array
*/
public function getConnectionParameters()
{
return $this->connectionParameters;
}
/**
* Get driver name
*
* @return null|string
*/
public function getDriverName()
{
return $this->driverName;
}
/**
* @return null|ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* {@inheritDoc}
*
* @return resource
*/
public function getResource()
{
if (! $this->isConnected()) {
$this->connect();
}
return $this->resource;
}
/**
* Checks whether the connection is in transaction state.
*
* @return boolean
*/
public function inTransaction()
{
return $this->inTransaction;
}
/**
* @param array $connectionParameters
* @return self Provides a fluent interface
*/
public function setConnectionParameters(array $connectionParameters)
{
$this->connectionParameters = $connectionParameters;
return $this;
}
/**
* {@inheritDoc}
*
* @return self Provides a fluent interface
*/
public function setProfiler(ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
}

View File

@ -1,85 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver;
interface ConnectionInterface
{
/**
* Get current schema
*
* @return string
*/
public function getCurrentSchema();
/**
* Get resource
*
* @return mixed
*/
public function getResource();
/**
* Connect
*
* @return ConnectionInterface
*/
public function connect();
/**
* Is connected
*
* @return bool
*/
public function isConnected();
/**
* Disconnect
*
* @return ConnectionInterface
*/
public function disconnect();
/**
* Begin transaction
*
* @return ConnectionInterface
*/
public function beginTransaction();
/**
* Commit
*
* @return ConnectionInterface
*/
public function commit();
/**
* Rollback
*
* @return ConnectionInterface
*/
public function rollback();
/**
* Execute
*
* @param string $sql
* @return ResultInterface
*/
public function execute($sql);
/**
* Get last generated id
*
* @param null $name Ignored
* @return int
*/
public function getLastGeneratedValue($name = null);
}

View File

@ -1,79 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver;
interface DriverInterface
{
const PARAMETERIZATION_POSITIONAL = 'positional';
const PARAMETERIZATION_NAMED = 'named';
const NAME_FORMAT_CAMELCASE = 'camelCase';
const NAME_FORMAT_NATURAL = 'natural';
/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE);
/**
* Check environment
*
* @return bool
*/
public function checkEnvironment();
/**
* Get connection
*
* @return ConnectionInterface
*/
public function getConnection();
/**
* Create statement
*
* @param string|resource $sqlOrResource
* @return StatementInterface
*/
public function createStatement($sqlOrResource = null);
/**
* Create result
*
* @param resource $resource
* @return ResultInterface
*/
public function createResult($resource);
/**
* Get prepare type
*
* @return string
*/
public function getPrepareType();
/**
* Format parameter name
*
* @param string $name
* @param mixed $type
* @return string
*/
public function formatParameterName($name, $type = null);
/**
* Get last generated value
*
* @return mixed
*/
public function getLastGeneratedValue();
}

View File

@ -1,38 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Feature;
use Zend\Db\Adapter\Driver\DriverInterface;
abstract class AbstractFeature
{
/**
* @var DriverInterface
*/
protected $driver = null;
/**
* Set driver
*
* @param DriverInterface $driver
* @return void
*/
public function setDriver(DriverInterface $driver)
{
$this->driver = $driver;
}
/**
* Get name
*
* @return string
*/
abstract public function getName();
}

View File

@ -1,37 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Feature;
interface DriverFeatureInterface
{
/**
* Setup the default features for Pdo
*
* @return DriverFeatureInterface
*/
public function setupDefaultFeatures();
/**
* Add feature
*
* @param string $name
* @param mixed $feature
* @return DriverFeatureInterface
*/
public function addFeature($name, $feature);
/**
* Get feature
*
* @param $name
* @return mixed|false
*/
public function getFeature($name);
}

View File

@ -1,285 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\IbmDb2;
use Zend\Db\Adapter\Driver\AbstractConnection;
use Zend\Db\Adapter\Exception;
class Connection extends AbstractConnection
{
/**
* @var IbmDb2
*/
protected $driver = null;
/**
* i5 OS
*
* @var bool
*/
protected $i5;
/**
* Previous autocommit set
*
* @var mixed
*/
protected $prevAutocommit;
/**
* Constructor
*
* @param array|resource|null $connectionParameters (ibm_db2 connection resource)
* @throws Exception\InvalidArgumentException
*/
public function __construct($connectionParameters = null)
{
if (is_array($connectionParameters)) {
$this->setConnectionParameters($connectionParameters);
} elseif (is_resource($connectionParameters)) {
$this->setResource($connectionParameters);
} elseif (null !== $connectionParameters) {
throw new Exception\InvalidArgumentException(
'$connection must be an array of parameters, a db2 connection resource or null'
);
}
}
/**
* Set driver
*
* @param IbmDb2 $driver
* @return self Provides a fluent interface
*/
public function setDriver(IbmDb2 $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param resource $resource DB2 resource
* @return self Provides a fluent interface
*/
public function setResource($resource)
{
if (! is_resource($resource) || get_resource_type($resource) !== 'DB2 Connection') {
throw new Exception\InvalidArgumentException('The resource provided must be of type "DB2 Connection"');
}
$this->resource = $resource;
return $this;
}
/**
* {@inheritDoc}
*/
public function getCurrentSchema()
{
if (! $this->isConnected()) {
$this->connect();
}
$info = db2_server_info($this->resource);
return (isset($info->DB_NAME) ? $info->DB_NAME : '');
}
/**
* {@inheritDoc}
*/
public function connect()
{
if (is_resource($this->resource)) {
return $this;
}
// localize
$p = $this->connectionParameters;
// given a list of key names, test for existence in $p
$findParameterValue = function (array $names) use ($p) {
foreach ($names as $name) {
if (isset($p[$name])) {
return $p[$name];
}
}
return;
};
$database = $findParameterValue(['database', 'db']);
$username = $findParameterValue(['username', 'uid', 'UID']);
$password = $findParameterValue(['password', 'pwd', 'PWD']);
$isPersistent = $findParameterValue(['persistent', 'PERSISTENT', 'Persistent']);
$options = (isset($p['driver_options']) ? $p['driver_options'] : []);
$connect = ((bool) $isPersistent) ? 'db2_pconnect' : 'db2_connect';
$this->resource = $connect($database, $username, $password, $options);
if ($this->resource === false) {
throw new Exception\RuntimeException(sprintf(
'%s: Unable to connect to database',
__METHOD__
));
}
return $this;
}
/**
* {@inheritDoc}
*/
public function isConnected()
{
return ($this->resource !== null);
}
/**
* {@inheritDoc}
*/
public function disconnect()
{
if ($this->resource) {
db2_close($this->resource);
$this->resource = null;
}
return $this;
}
/**
* {@inheritDoc}
*/
public function beginTransaction()
{
if ($this->isI5() && ! ini_get('ibm_db2.i5_allow_commit')) {
throw new Exception\RuntimeException(
'DB2 transactions are not enabled, you need to set the ibm_db2.i5_allow_commit=1 in your php.ini'
);
}
if (! $this->isConnected()) {
$this->connect();
}
$this->prevAutocommit = db2_autocommit($this->resource);
db2_autocommit($this->resource, DB2_AUTOCOMMIT_OFF);
$this->inTransaction = true;
return $this;
}
/**
* {@inheritDoc}
*/
public function commit()
{
if (! $this->isConnected()) {
$this->connect();
}
if (! db2_commit($this->resource)) {
throw new Exception\RuntimeException("The commit has not been successful");
}
if ($this->prevAutocommit) {
db2_autocommit($this->resource, $this->prevAutocommit);
}
$this->inTransaction = false;
return $this;
}
/**
* Rollback
*
* @return self Provides a fluent interface
* @throws Exception\RuntimeException
*/
public function rollback()
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}
if (! $this->inTransaction()) {
throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.');
}
if (! db2_rollback($this->resource)) {
throw new Exception\RuntimeException('The rollback has not been successful');
}
if ($this->prevAutocommit) {
db2_autocommit($this->resource, $this->prevAutocommit);
}
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*/
public function execute($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->profiler) {
$this->profiler->profilerStart($sql);
}
set_error_handler(function () {
}, E_WARNING); // suppress warnings
$resultResource = db2_exec($this->resource, $sql);
restore_error_handler();
if ($this->profiler) {
$this->profiler->profilerFinish($sql);
}
// if the returnValue is something other than a pg result resource, bypass wrapping it
if ($resultResource === false) {
throw new Exception\InvalidQueryException(db2_stmt_errormsg());
}
return $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource);
}
/**
* {@inheritDoc}
*/
public function getLastGeneratedValue($name = null)
{
return db2_last_insert_id($this->resource);
}
/**
* Determine if the OS is OS400 (AS400, IBM i)
*
* @return bool
*/
protected function isI5()
{
if (isset($this->i5)) {
return $this->i5;
}
$this->i5 = (php_uname('s') == 'OS400');
return $this->i5;
}
}

View File

@ -1,214 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\IbmDb2;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\Profiler;
class IbmDb2 implements DriverInterface, Profiler\ProfilerAwareInterface
{
/**
* @var Connection
*/
protected $connection;
/** @var Statement */
protected $statementPrototype;
/** @var Result */
protected $resultPrototype;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler;
/**
* @param array|Connection|resource $connection
* @param null|Statement $statementPrototype
* @param null|Result $resultPrototype
*/
public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null)
{
if (! $connection instanceof Connection) {
$connection = new Connection($connection);
}
$this->registerConnection($connection);
$this->registerStatementPrototype(($statementPrototype) ?: new Statement());
$this->registerResultPrototype(($resultPrototype) ?: new Result());
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->connection instanceof Profiler\ProfilerAwareInterface) {
$this->connection->setProfiler($profiler);
}
if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) {
$this->statementPrototype->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* @param Connection $connection
* @return self Provides a fluent interface
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this);
return $this;
}
/**
* @param Statement $statementPrototype
* @return self Provides a fluent interface
*/
public function registerStatementPrototype(Statement $statementPrototype)
{
$this->statementPrototype = $statementPrototype;
$this->statementPrototype->setDriver($this);
return $this;
}
/**
* @param Result $resultPrototype
* @return self Provides a fluent interface
*/
public function registerResultPrototype(Result $resultPrototype)
{
$this->resultPrototype = $resultPrototype;
return $this;
}
/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
if ($nameFormat == self::NAME_FORMAT_CAMELCASE) {
return 'IbmDb2';
} else {
return 'IBM DB2';
}
}
/**
* Check environment
*
* @return bool
*/
public function checkEnvironment()
{
if (! extension_loaded('ibm_db2')) {
throw new Exception\RuntimeException('The ibm_db2 extension is required by this driver.');
}
}
/**
* Get connection
*
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* Create statement
*
* @param string|resource $sqlOrResource
* @return Statement
*/
public function createStatement($sqlOrResource = null)
{
$statement = clone $this->statementPrototype;
if (is_resource($sqlOrResource) && get_resource_type($sqlOrResource) == 'DB2 Statement') {
$statement->setResource($sqlOrResource);
} else {
if (is_string($sqlOrResource)) {
$statement->setSql($sqlOrResource);
} elseif ($sqlOrResource !== null) {
throw new Exception\InvalidArgumentException(
__FUNCTION__ . ' only accepts an SQL string or an ibm_db2 resource'
);
}
if (! $this->connection->isConnected()) {
$this->connection->connect();
}
$statement->initialize($this->connection->getResource());
}
return $statement;
}
/**
* Create result
*
* @param resource $resource
* @return Result
*/
public function createResult($resource)
{
$result = clone $this->resultPrototype;
$result->initialize($resource, $this->connection->getLastGeneratedValue());
return $result;
}
/**
* Get prepare type
*
* @return string
*/
public function getPrepareType()
{
return self::PARAMETERIZATION_POSITIONAL;
}
/**
* Format parameter name
*
* @param string $name
* @param mixed $type
* @return string
*/
public function formatParameterName($name, $type = null)
{
return '?';
}
/**
* Get last generated value
*
* @return mixed
*/
public function getLastGeneratedValue()
{
return $this->connection->getLastGeneratedValue();
}
}

View File

@ -1,192 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\IbmDb2;
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\Adapter\Exception;
class Result implements ResultInterface
{
/**
* @var resource
*/
protected $resource;
/**
* @var int
*/
protected $position = 0;
/**
* @var bool
*/
protected $currentComplete = false;
/**
* @var mixed
*/
protected $currentData = null;
/**
* @var mixed
*/
protected $generatedValue = null;
/**
* @param resource $resource
* @param mixed $generatedValue
* @return self Provides a fluent interface
*/
public function initialize($resource, $generatedValue = null)
{
$this->resource = $resource;
$this->generatedValue = $generatedValue;
return $this;
}
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Return the current element
* @link http://php.net/manual/en/iterator.current.php
* @return mixed Can return any type.
*/
public function current()
{
if ($this->currentComplete) {
return $this->currentData;
}
$this->currentData = db2_fetch_assoc($this->resource);
return $this->currentData;
}
/**
* @return mixed
*/
public function next()
{
$this->currentData = db2_fetch_assoc($this->resource);
$this->currentComplete = true;
$this->position++;
return $this->currentData;
}
/**
* @return int|string
*/
public function key()
{
return $this->position;
}
/**
* @return bool
*/
public function valid()
{
return ($this->currentData !== false);
}
/**
* (PHP 5 &gt;= 5.0.0)<br/>
* Rewind the Iterator to the first element
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
*/
public function rewind()
{
if ($this->position > 0) {
throw new Exception\RuntimeException(
'This result is a forward only result set, calling rewind() after moving forward is not supported'
);
}
$this->currentData = db2_fetch_assoc($this->resource);
$this->currentComplete = true;
$this->position = 1;
}
/**
* Force buffering
*
* @return void
*/
public function buffer()
{
return;
}
/**
* Check if is buffered
*
* @return bool|null
*/
public function isBuffered()
{
return false;
}
/**
* Is query result?
*
* @return bool
*/
public function isQueryResult()
{
return (db2_num_fields($this->resource) > 0);
}
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows()
{
return db2_num_rows($this->resource);
}
/**
* Get generated value
*
* @return mixed|null
*/
public function getGeneratedValue()
{
return $this->generatedValue;
}
/**
* Get the resource
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Get field count
*
* @return int
*/
public function getFieldCount()
{
return db2_num_fields($this->resource);
}
/**
* @return null|int
*/
public function count()
{
return;
}
}

View File

@ -1,277 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\IbmDb2;
use ErrorException;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;
class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
{
/**
* @var resource
*/
protected $db2 = null;
/**
* @var IbmDb2
*/
protected $driver = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var string
*/
protected $sql = '';
/**
* @var ParameterContainer
*/
protected $parameterContainer = null;
/**
* @var bool
*/
protected $isPrepared = false;
/**
* @var resource
*/
protected $resource = null;
/**
* @param $resource
* @return self Provides a fluent interface
*/
public function initialize($resource)
{
$this->db2 = $resource;
return $this;
}
/**
* @param IbmDb2 $driver
* @return self Provides a fluent interface
*/
public function setDriver(IbmDb2 $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Set sql
*
* @param $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Get sql
*
* @return mixed
*/
public function getSql()
{
return $this->sql;
}
/**
* Set parameter container
*
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* Get parameter container
*
* @return mixed
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
/**
* @param $resource
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function setResource($resource)
{
if (get_resource_type($resource) !== 'DB2 Statement') {
throw new Exception\InvalidArgumentException('Resource must be of type DB2 Statement');
}
$this->resource = $resource;
}
/**
* Get resource
*
* @return resource
*/
public function getResource()
{
return $this->resource;
}
/**
* Prepare sql
*
* @param string|null $sql
* @return self Provides a fluent interface
* @throws Exception\RuntimeException
*/
public function prepare($sql = null)
{
if ($this->isPrepared) {
throw new Exception\RuntimeException('This statement has been prepared already');
}
if ($sql === null) {
$sql = $this->sql;
}
try {
set_error_handler($this->createErrorHandler());
$this->resource = db2_prepare($this->db2, $sql);
} catch (ErrorException $e) {
throw new Exception\RuntimeException($e->getMessage() . '. ' . db2_stmt_errormsg(), db2_stmt_error(), $e);
} finally {
restore_error_handler();
}
if ($this->resource === false) {
throw new Exception\RuntimeException(db2_stmt_errormsg(), db2_stmt_error());
}
$this->isPrepared = true;
return $this;
}
/**
* Check if is prepared
*
* @return bool
*/
public function isPrepared()
{
return $this->isPrepared;
}
/**
* Execute
*
* @param null|array|ParameterContainer $parameters
* @return Result
*/
public function execute($parameters = null)
{
if (! $this->isPrepared) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (! $this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
set_error_handler(function () {
}, E_WARNING); // suppress warnings
$response = db2_execute($this->resource, $this->parameterContainer->getPositionalArray());
restore_error_handler();
if ($this->profiler) {
$this->profiler->profilerFinish();
}
if ($response === false) {
throw new Exception\RuntimeException(db2_stmt_errormsg($this->resource));
}
$result = $this->driver->createResult($this->resource);
return $result;
}
/**
* Creates and returns a callable error handler that raises exceptions.
*
* Only raises exceptions for errors that are within the error_reporting mask.
*
* @return callable
*/
private function createErrorHandler()
{
/**
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @return void
* @throws ErrorException if error is not within the error_reporting mask.
*/
return function ($errno, $errstr, $errfile, $errline) {
if (! (error_reporting() & $errno)) {
// error_reporting does not include this error
return;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
};
}
}

View File

@ -1,285 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Mysqli;
use Exception as GenericException;
use Zend\Db\Adapter\Driver\AbstractConnection;
use Zend\Db\Adapter\Exception;
class Connection extends AbstractConnection
{
/**
* @var Mysqli
*/
protected $driver = null;
/**
* @var \mysqli
*/
protected $resource = null;
/**
* Constructor
*
* @param array|mysqli|null $connectionInfo
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function __construct($connectionInfo = null)
{
if (is_array($connectionInfo)) {
$this->setConnectionParameters($connectionInfo);
} elseif ($connectionInfo instanceof \mysqli) {
$this->setResource($connectionInfo);
} elseif (null !== $connectionInfo) {
throw new Exception\InvalidArgumentException(
'$connection must be an array of parameters, a mysqli object or null'
);
}
}
/**
* @param Mysqli $driver
* @return self Provides a fluent interface
*/
public function setDriver(Mysqli $driver)
{
$this->driver = $driver;
return $this;
}
/**
* {@inheritDoc}
*/
public function getCurrentSchema()
{
if (! $this->isConnected()) {
$this->connect();
}
$result = $this->resource->query('SELECT DATABASE()');
$r = $result->fetch_row();
return $r[0];
}
/**
* Set resource
*
* @param \mysqli $resource
* @return self Provides a fluent interface
*/
public function setResource(\mysqli $resource)
{
$this->resource = $resource;
return $this;
}
/**
* {@inheritDoc}
*/
public function connect()
{
if ($this->resource instanceof \mysqli) {
return $this;
}
// localize
$p = $this->connectionParameters;
// given a list of key names, test for existence in $p
$findParameterValue = function (array $names) use ($p) {
foreach ($names as $name) {
if (isset($p[$name])) {
return $p[$name];
}
}
return;
};
$hostname = $findParameterValue(['hostname', 'host']);
$username = $findParameterValue(['username', 'user']);
$password = $findParameterValue(['password', 'passwd', 'pw']);
$database = $findParameterValue(['database', 'dbname', 'db', 'schema']);
$port = (isset($p['port'])) ? (int) $p['port'] : null;
$socket = (isset($p['socket'])) ? $p['socket'] : null;
$useSSL = (isset($p['use_ssl'])) ? $p['use_ssl'] : 0;
$clientKey = (isset($p['client_key'])) ? $p['client_key'] : null;
$clientCert = (isset($p['client_cert'])) ? $p['client_cert'] : null;
$caCert = (isset($p['ca_cert'])) ? $p['ca_cert'] : null;
$caPath = (isset($p['ca_path'])) ? $p['ca_path'] : null;
$cipher = (isset($p['cipher'])) ? $p['cipher'] : null;
$this->resource = new \mysqli();
$this->resource->init();
if (! empty($p['driver_options'])) {
foreach ($p['driver_options'] as $option => $value) {
if (is_string($option)) {
$option = strtoupper($option);
if (! defined($option)) {
continue;
}
$option = constant($option);
}
$this->resource->options($option, $value);
}
}
$flags = null;
if ($useSSL && ! $socket) {
$this->resource->ssl_set($clientKey, $clientCert, $caCert, $caPath, $cipher);
//MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT is not valid option, needs to be set as flag
if (isset($p['driver_options'])
&& isset($p['driver_options'][MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT])
) {
$flags = MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT;
}
}
try {
$this->resource->real_connect($hostname, $username, $password, $database, $port, $socket, $flags);
} catch (GenericException $e) {
throw new Exception\RuntimeException(
'Connection error',
null,
new Exception\ErrorException($this->resource->connect_error, $this->resource->connect_errno)
);
}
if ($this->resource->connect_error) {
throw new Exception\RuntimeException(
'Connection error',
null,
new Exception\ErrorException($this->resource->connect_error, $this->resource->connect_errno)
);
}
if (! empty($p['charset'])) {
$this->resource->set_charset($p['charset']);
}
return $this;
}
/**
* {@inheritDoc}
*/
public function isConnected()
{
return ($this->resource instanceof \mysqli);
}
/**
* {@inheritDoc}
*/
public function disconnect()
{
if ($this->resource instanceof \mysqli) {
$this->resource->close();
}
$this->resource = null;
}
/**
* {@inheritDoc}
*/
public function beginTransaction()
{
if (! $this->isConnected()) {
$this->connect();
}
$this->resource->autocommit(false);
$this->inTransaction = true;
return $this;
}
/**
* {@inheritDoc}
*/
public function commit()
{
if (! $this->isConnected()) {
$this->connect();
}
$this->resource->commit();
$this->inTransaction = false;
$this->resource->autocommit(true);
return $this;
}
/**
* {@inheritDoc}
*/
public function rollback()
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}
if (! $this->inTransaction) {
throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.');
}
$this->resource->rollback();
$this->resource->autocommit(true);
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\InvalidQueryException
*/
public function execute($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->profiler) {
$this->profiler->profilerStart($sql);
}
$resultResource = $this->resource->query($sql);
if ($this->profiler) {
$this->profiler->profilerFinish($sql);
}
// if the returnValue is something other than a mysqli_result, bypass wrapping it
if ($resultResource === false) {
throw new Exception\InvalidQueryException($this->resource->error);
}
$resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource);
return $resultPrototype;
}
/**
* {@inheritDoc}
*/
public function getLastGeneratedValue($name = null)
{
return $this->resource->insert_id;
}
}

View File

@ -1,262 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Mysqli;
use mysqli_stmt;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\Profiler;
class Mysqli implements DriverInterface, Profiler\ProfilerAwareInterface
{
/**
* @var Connection
*/
protected $connection = null;
/**
* @var Statement
*/
protected $statementPrototype = null;
/**
* @var Result
*/
protected $resultPrototype = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var array
*/
protected $options = [
'buffer_results' => false
];
/**
* Constructor
*
* @param array|Connection|\mysqli $connection
* @param null|Statement $statementPrototype
* @param null|Result $resultPrototype
* @param array $options
*/
public function __construct(
$connection,
Statement $statementPrototype = null,
Result $resultPrototype = null,
array $options = []
) {
if (! $connection instanceof Connection) {
$connection = new Connection($connection);
}
$options = array_intersect_key(array_merge($this->options, $options), $this->options);
$this->registerConnection($connection);
$this->registerStatementPrototype(($statementPrototype) ?: new Statement($options['buffer_results']));
$this->registerResultPrototype(($resultPrototype) ?: new Result());
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->connection instanceof Profiler\ProfilerAwareInterface) {
$this->connection->setProfiler($profiler);
}
if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) {
$this->statementPrototype->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Register connection
*
* @param Connection $connection
* @return self Provides a fluent interface
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this); // needs access to driver to createStatement()
return $this;
}
/**
* Register statement prototype
*
* @param Statement $statementPrototype
*/
public function registerStatementPrototype(Statement $statementPrototype)
{
$this->statementPrototype = $statementPrototype;
$this->statementPrototype->setDriver($this); // needs access to driver to createResult()
}
/**
* Get statement prototype
*
* @return null|Statement
*/
public function getStatementPrototype()
{
return $this->statementPrototype;
}
/**
* Register result prototype
*
* @param Result $resultPrototype
*/
public function registerResultPrototype(Result $resultPrototype)
{
$this->resultPrototype = $resultPrototype;
}
/**
* @return null|Result
*/
public function getResultPrototype()
{
return $this->resultPrototype;
}
/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
if ($nameFormat == self::NAME_FORMAT_CAMELCASE) {
return 'Mysql';
}
return 'MySQL';
}
/**
* Check environment
*
* @throws Exception\RuntimeException
* @return void
*/
public function checkEnvironment()
{
if (! extension_loaded('mysqli')) {
throw new Exception\RuntimeException(
'The Mysqli extension is required for this adapter but the extension is not loaded'
);
}
}
/**
* Get connection
*
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* Create statement
*
* @param string $sqlOrResource
* @return Statement
*/
public function createStatement($sqlOrResource = null)
{
/**
* @todo Resource tracking
if (is_resource($sqlOrResource) && !in_array($sqlOrResource, $this->resources, true)) {
$this->resources[] = $sqlOrResource;
}
*/
$statement = clone $this->statementPrototype;
if ($sqlOrResource instanceof mysqli_stmt) {
$statement->setResource($sqlOrResource);
} else {
if (is_string($sqlOrResource)) {
$statement->setSql($sqlOrResource);
}
if (! $this->connection->isConnected()) {
$this->connection->connect();
}
$statement->initialize($this->connection->getResource());
}
return $statement;
}
/**
* Create result
*
* @param resource $resource
* @param null|bool $isBuffered
* @return Result
*/
public function createResult($resource, $isBuffered = null)
{
$result = clone $this->resultPrototype;
$result->initialize($resource, $this->connection->getLastGeneratedValue(), $isBuffered);
return $result;
}
/**
* Get prepare type
*
* @return string
*/
public function getPrepareType()
{
return self::PARAMETERIZATION_POSITIONAL;
}
/**
* Format parameter name
*
* @param string $name
* @param mixed $type
* @return string
*/
public function formatParameterName($name, $type = null)
{
return '?';
}
/**
* Get last generated value
*
* @return mixed
*/
public function getLastGeneratedValue()
{
return $this->getConnection()->getLastGeneratedValue();
}
}

View File

@ -1,342 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Mysqli;
use Iterator;
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\Adapter\Exception;
class Result implements
Iterator,
ResultInterface
{
/**
* @var \mysqli|\mysqli_result|\mysqli_stmt
*/
protected $resource = null;
/**
* @var bool
*/
protected $isBuffered = null;
/**
* Cursor position
* @var int
*/
protected $position = 0;
/**
* Number of known rows
* @var int
*/
protected $numberOfRows = -1;
/**
* Is the current() operation already complete for this pointer position?
* @var bool
*/
protected $currentComplete = false;
/**
* @var bool
*/
protected $nextComplete = false;
/**
* @var mixed
*/
protected $currentData = null;
/**
*
* @var array
*/
protected $statementBindValues = ['keys' => null, 'values' => []];
/**
* @var mixed
*/
protected $generatedValue = null;
/**
* Initialize
*
* @param mixed $resource
* @param mixed $generatedValue
* @param bool|null $isBuffered
* @return self Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
public function initialize($resource, $generatedValue, $isBuffered = null)
{
if (! $resource instanceof \mysqli
&& ! $resource instanceof \mysqli_result
&& ! $resource instanceof \mysqli_stmt
) {
throw new Exception\InvalidArgumentException('Invalid resource provided.');
}
if ($isBuffered !== null) {
$this->isBuffered = $isBuffered;
} else {
if ($resource instanceof \mysqli || $resource instanceof \mysqli_result
|| $resource instanceof \mysqli_stmt && $resource->num_rows != 0) {
$this->isBuffered = true;
}
}
$this->resource = $resource;
$this->generatedValue = $generatedValue;
return $this;
}
/**
* Force buffering
*
* @throws Exception\RuntimeException
*/
public function buffer()
{
if ($this->resource instanceof \mysqli_stmt && $this->isBuffered !== true) {
if ($this->position > 0) {
throw new Exception\RuntimeException('Cannot buffer a result set that has started iteration.');
}
$this->resource->store_result();
$this->isBuffered = true;
}
}
/**
* Check if is buffered
*
* @return bool|null
*/
public function isBuffered()
{
return $this->isBuffered;
}
/**
* Return the resource
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Is query result?
*
* @return bool
*/
public function isQueryResult()
{
return ($this->resource->field_count > 0);
}
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows()
{
if ($this->resource instanceof \mysqli || $this->resource instanceof \mysqli_stmt) {
return $this->resource->affected_rows;
}
return $this->resource->num_rows;
}
/**
* Current
*
* @return mixed
*/
public function current()
{
if ($this->currentComplete) {
return $this->currentData;
}
if ($this->resource instanceof \mysqli_stmt) {
$this->loadDataFromMysqliStatement();
return $this->currentData;
} else {
$this->loadFromMysqliResult();
return $this->currentData;
}
}
/**
* Mysqli's binding and returning of statement values
*
* Mysqli requires you to bind variables to the extension in order to
* get data out. These values have to be references:
* @see http://php.net/manual/en/mysqli-stmt.bind-result.php
*
* @throws Exception\RuntimeException
* @return bool
*/
protected function loadDataFromMysqliStatement()
{
// build the default reference based bind structure, if it does not already exist
if ($this->statementBindValues['keys'] === null) {
$this->statementBindValues['keys'] = [];
$resultResource = $this->resource->result_metadata();
foreach ($resultResource->fetch_fields() as $col) {
$this->statementBindValues['keys'][] = $col->name;
}
$this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null);
$refs = [];
foreach ($this->statementBindValues['values'] as $i => &$f) {
$refs[$i] = &$f;
}
call_user_func_array([$this->resource, 'bind_result'], $this->statementBindValues['values']);
}
if (($r = $this->resource->fetch()) === null) {
if (! $this->isBuffered) {
$this->resource->close();
}
return false;
} elseif ($r === false) {
throw new Exception\RuntimeException($this->resource->error);
}
// dereference
for ($i = 0, $count = count($this->statementBindValues['keys']); $i < $count; $i++) {
$this->currentData[$this->statementBindValues['keys'][$i]] = $this->statementBindValues['values'][$i];
}
$this->currentComplete = true;
$this->nextComplete = true;
$this->position++;
return true;
}
/**
* Load from mysqli result
*
* @return bool
*/
protected function loadFromMysqliResult()
{
$this->currentData = null;
if (($data = $this->resource->fetch_assoc()) === null) {
return false;
}
$this->position++;
$this->currentData = $data;
$this->currentComplete = true;
$this->nextComplete = true;
$this->position++;
return true;
}
/**
* Next
*
* @return void
*/
public function next()
{
$this->currentComplete = false;
if ($this->nextComplete == false) {
$this->position++;
}
$this->nextComplete = false;
}
/**
* Key
*
* @return mixed
*/
public function key()
{
return $this->position;
}
/**
* Rewind
*
* @throws Exception\RuntimeException
* @return void
*/
public function rewind()
{
if (0 !== $this->position && false === $this->isBuffered) {
throw new Exception\RuntimeException('Unbuffered results cannot be rewound for multiple iterations');
}
$this->resource->data_seek(0); // works for both mysqli_result & mysqli_stmt
$this->currentComplete = false;
$this->position = 0;
}
/**
* Valid
*
* @return bool
*/
public function valid()
{
if ($this->currentComplete) {
return true;
}
if ($this->resource instanceof \mysqli_stmt) {
return $this->loadDataFromMysqliStatement();
}
return $this->loadFromMysqliResult();
}
/**
* Count
*
* @throws Exception\RuntimeException
* @return int
*/
public function count()
{
if ($this->isBuffered === false) {
throw new Exception\RuntimeException('Row count is not available in unbuffered result sets.');
}
return $this->resource->num_rows;
}
/**
* Get field count
*
* @return int
*/
public function getFieldCount()
{
return $this->resource->field_count;
}
/**
* Get generated value
*
* @return mixed|null
*/
public function getGeneratedValue()
{
return $this->generatedValue;
}
}

View File

@ -1,315 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Mysqli;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;
class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
{
/**
* @var \mysqli
*/
protected $mysqli = null;
/**
* @var Mysqli
*/
protected $driver = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var string
*/
protected $sql = '';
/**
* Parameter container
*
* @var ParameterContainer
*/
protected $parameterContainer = null;
/**
* @var \mysqli_stmt
*/
protected $resource = null;
/**
* Is prepared
*
* @var bool
*/
protected $isPrepared = false;
/**
* @var bool
*/
protected $bufferResults = false;
/**
* @param bool $bufferResults
*/
public function __construct($bufferResults = false)
{
$this->bufferResults = (bool) $bufferResults;
}
/**
* Set driver
*
* @param Mysqli $driver
* @return self Provides a fluent interface
*/
public function setDriver(Mysqli $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Initialize
*
* @param \mysqli $mysqli
* @return self Provides a fluent interface
*/
public function initialize(\mysqli $mysqli)
{
$this->mysqli = $mysqli;
return $this;
}
/**
* Set sql
*
* @param string $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Set Parameter container
*
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* Get resource
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Set resource
*
* @param \mysqli_stmt $mysqliStatement
* @return self Provides a fluent interface
*/
public function setResource(\mysqli_stmt $mysqliStatement)
{
$this->resource = $mysqliStatement;
$this->isPrepared = true;
return $this;
}
/**
* Get sql
*
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* Get parameter count
*
* @return ParameterContainer
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
/**
* Is prepared
*
* @return bool
*/
public function isPrepared()
{
return $this->isPrepared;
}
/**
* Prepare
*
* @param string $sql
* @return self Provides a fluent interface
* @throws Exception\InvalidQueryException
* @throws Exception\RuntimeException
*/
public function prepare($sql = null)
{
if ($this->isPrepared) {
throw new Exception\RuntimeException('This statement has already been prepared');
}
$sql = ($sql) ?: $this->sql;
$this->resource = $this->mysqli->prepare($sql);
if (! $this->resource instanceof \mysqli_stmt) {
throw new Exception\InvalidQueryException(
'Statement couldn\'t be produced with sql: ' . $sql,
null,
new Exception\ErrorException($this->mysqli->error, $this->mysqli->errno)
);
}
$this->isPrepared = true;
return $this;
}
/**
* Execute
*
* @param null|array|ParameterContainer $parameters
* @throws Exception\RuntimeException
* @return mixed
*/
public function execute($parameters = null)
{
if (! $this->isPrepared) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (! $this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
$return = $this->resource->execute();
if ($this->profiler) {
$this->profiler->profilerFinish();
}
if ($return === false) {
throw new Exception\RuntimeException($this->resource->error);
}
if ($this->bufferResults === true) {
$this->resource->store_result();
$this->isPrepared = false;
$buffered = true;
} else {
$buffered = false;
}
$result = $this->driver->createResult($this->resource, $buffered);
return $result;
}
/**
* Bind parameters from container
*
* @return void
*/
protected function bindParametersFromContainer()
{
$parameters = $this->parameterContainer->getNamedArray();
$type = '';
$args = [];
foreach ($parameters as $name => &$value) {
if ($this->parameterContainer->offsetHasErrata($name)) {
switch ($this->parameterContainer->offsetGetErrata($name)) {
case ParameterContainer::TYPE_DOUBLE:
$type .= 'd';
break;
case ParameterContainer::TYPE_NULL:
$value = null; // as per @see http://www.php.net/manual/en/mysqli-stmt.bind-param.php#96148
case ParameterContainer::TYPE_INTEGER:
$type .= 'i';
break;
case ParameterContainer::TYPE_STRING:
default:
$type .= 's';
break;
}
} else {
$type .= 's';
}
$args[] = &$value;
}
if ($args) {
array_unshift($args, $type);
call_user_func_array([$this->resource, 'bind_param'], $args);
}
}
}

View File

@ -1,268 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Oci8;
use Zend\Db\Adapter\Driver\AbstractConnection;
use Zend\Db\Adapter\Exception;
class Connection extends AbstractConnection
{
/**
* @var Oci8
*/
protected $driver = null;
/**
* Constructor
*
* @param array|resource|null $connectionInfo
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function __construct($connectionInfo = null)
{
if (is_array($connectionInfo)) {
$this->setConnectionParameters($connectionInfo);
} elseif ($connectionInfo instanceof \oci8) {
$this->setResource($connectionInfo);
} elseif (null !== $connectionInfo) {
throw new Exception\InvalidArgumentException(
'$connection must be an array of parameters, an oci8 resource or null'
);
}
}
/**
* @param Oci8 $driver
* @return self Provides a fluent interface
*/
public function setDriver(Oci8 $driver)
{
$this->driver = $driver;
return $this;
}
/**
* {@inheritDoc}
*/
public function getCurrentSchema()
{
if (! $this->isConnected()) {
$this->connect();
}
$query = "SELECT sys_context('USERENV', 'CURRENT_SCHEMA') as \"current_schema\" FROM DUAL";
$stmt = oci_parse($this->resource, $query);
oci_execute($stmt);
$dbNameArray = oci_fetch_array($stmt, OCI_ASSOC);
return $dbNameArray['current_schema'];
}
/**
* Set resource
*
* @param resource $resource
* @return self Provides a fluent interface
*/
public function setResource($resource)
{
if (! is_resource($resource) || get_resource_type($resource) !== 'oci8 connection') {
throw new Exception\InvalidArgumentException('A resource of type "oci8 connection" was expected');
}
$this->resource = $resource;
return $this;
}
/**
* {@inheritDoc}
*/
public function connect()
{
if (is_resource($this->resource)) {
return $this;
}
// localize
$p = $this->connectionParameters;
// given a list of key names, test for existence in $p
$findParameterValue = function (array $names) use ($p) {
foreach ($names as $name) {
if (isset($p[$name])) {
return $p[$name];
}
}
return;
};
// http://www.php.net/manual/en/function.oci-connect.php
$username = $findParameterValue(['username']);
$password = $findParameterValue(['password']);
$connectionString = $findParameterValue([
'connection_string',
'connectionstring',
'connection',
'hostname',
'instance'
]);
$characterSet = $findParameterValue(['character_set', 'charset', 'encoding']);
$sessionMode = $findParameterValue(['session_mode']);
// connection modifiers
$isUnique = $findParameterValue(['unique']);
$isPersistent = $findParameterValue(['persistent']);
if ($isUnique == true) {
$this->resource = oci_new_connect($username, $password, $connectionString, $characterSet, $sessionMode);
} elseif ($isPersistent == true) {
$this->resource = oci_pconnect($username, $password, $connectionString, $characterSet, $sessionMode);
} else {
$this->resource = oci_connect($username, $password, $connectionString, $characterSet, $sessionMode);
}
if (! $this->resource) {
$e = oci_error();
throw new Exception\RuntimeException(
'Connection error',
null,
new Exception\ErrorException($e['message'], $e['code'])
);
}
return $this;
}
/**
* {@inheritDoc}
*/
public function isConnected()
{
return (is_resource($this->resource));
}
/**
* {@inheritDoc}
*/
public function disconnect()
{
if (is_resource($this->resource)) {
oci_close($this->resource);
}
}
/**
* {@inheritDoc}
*/
public function beginTransaction()
{
if (! $this->isConnected()) {
$this->connect();
}
// A transaction begins when the first SQL statement that changes data is executed with oci_execute() using
// the OCI_NO_AUTO_COMMIT flag.
$this->inTransaction = true;
return $this;
}
/**
* {@inheritDoc}
*/
public function commit()
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->inTransaction()) {
$valid = oci_commit($this->resource);
if ($valid === false) {
$e = oci_error($this->resource);
throw new Exception\InvalidQueryException($e['message'], $e['code']);
}
$this->inTransaction = false;
}
return $this;
}
/**
* {@inheritDoc}
*/
public function rollback()
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}
if (! $this->inTransaction()) {
throw new Exception\RuntimeException('Must call commit() before you can rollback.');
}
$valid = oci_rollback($this->resource);
if ($valid === false) {
$e = oci_error($this->resource);
throw new Exception\InvalidQueryException($e['message'], $e['code']);
}
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*/
public function execute($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->profiler) {
$this->profiler->profilerStart($sql);
}
$ociStmt = oci_parse($this->resource, $sql);
if ($this->inTransaction) {
$valid = @oci_execute($ociStmt, OCI_NO_AUTO_COMMIT);
} else {
$valid = @oci_execute($ociStmt, OCI_COMMIT_ON_SUCCESS);
}
if ($this->profiler) {
$this->profiler->profilerFinish($sql);
}
if ($valid === false) {
$e = oci_error($ociStmt);
throw new Exception\InvalidQueryException($e['message'], $e['code']);
}
$resultPrototype = $this->driver->createResult($ociStmt);
return $resultPrototype;
}
/**
* {@inheritDoc}
*/
public function getLastGeneratedValue($name = null)
{
// @todo Get Last Generated Value in Connection (this might not apply)
return;
}
}

View File

@ -1,75 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Oci8\Feature;
use Zend\Db\Adapter\Driver\Feature\AbstractFeature;
use Zend\Db\Adapter\Driver\Oci8\Statement;
/**
* Class for count of results of a select
*/
class RowCounter extends AbstractFeature
{
/**
* @return string
*/
public function getName()
{
return 'RowCounter';
}
/**
* @param Statement $statement
* @return null|int
*/
public function getCountForStatement(Statement $statement)
{
$countStmt = clone $statement;
$sql = $statement->getSql();
if ($sql == '' || stripos(strtolower($sql), 'select') === false) {
return;
}
$countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')';
$countStmt->prepare($countSql);
$result = $countStmt->execute();
$countRow = $result->current();
return $countRow['count'];
}
/**
* @param string $sql
* @return null|int
*/
public function getCountForSql($sql)
{
if (stripos(strtolower($sql), 'select') === false) {
return;
}
$countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')';
$result = $this->driver->getConnection()->execute($countSql);
$countRow = $result->current();
return $countRow['count'];
}
/**
* @param \Zend\Db\Adapter\Driver\Oci8\Statement|string $context
* @return callable
*/
public function getRowCountClosure($context)
{
$rowCounter = $this;
return function () use ($rowCounter, $context) {
/** @var $rowCounter RowCounter */
return ($context instanceof Statement)
? $rowCounter->getCountForStatement($context)
: $rowCounter->getCountForSql($context);
};
}
}

View File

@ -1,302 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Oci8;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\Profiler;
use Zend\Db\Adapter\Driver\Feature\AbstractFeature;
class Oci8 implements DriverInterface, Profiler\ProfilerAwareInterface
{
const FEATURES_DEFAULT = 'default';
/**
* @var Connection
*/
protected $connection = null;
/**
* @var Statement
*/
protected $statementPrototype = null;
/**
* @var Result
*/
protected $resultPrototype = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var array
*/
protected $options = [];
/**
* @var array
*/
protected $features = [];
/**
* @param array|Connection|\oci8 $connection
* @param null|Statement $statementPrototype
* @param null|Result $resultPrototype
* @param array $options
* @param string $features
*/
public function __construct(
$connection,
Statement $statementPrototype = null,
Result $resultPrototype = null,
array $options = [],
$features = self::FEATURES_DEFAULT
) {
if (! $connection instanceof Connection) {
$connection = new Connection($connection);
}
$options = array_intersect_key(array_merge($this->options, $options), $this->options);
$this->registerConnection($connection);
$this->registerStatementPrototype(($statementPrototype) ?: new Statement());
$this->registerResultPrototype(($resultPrototype) ?: new Result());
if (is_array($features)) {
foreach ($features as $name => $feature) {
$this->addFeature($name, $feature);
}
} elseif ($features instanceof AbstractFeature) {
$this->addFeature($features->getName(), $features);
} elseif ($features === self::FEATURES_DEFAULT) {
$this->setupDefaultFeatures();
}
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->connection instanceof Profiler\ProfilerAwareInterface) {
$this->connection->setProfiler($profiler);
}
if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) {
$this->statementPrototype->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Register connection
*
* @param Connection $connection
* @return self Provides a fluent interface
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this); // needs access to driver to createStatement()
return $this;
}
/**
* Register statement prototype
*
* @param Statement $statementPrototype
* @return self Provides a fluent interface
*/
public function registerStatementPrototype(Statement $statementPrototype)
{
$this->statementPrototype = $statementPrototype;
$this->statementPrototype->setDriver($this); // needs access to driver to createResult()
return $this;
}
/**
* @return null|Statement
*/
public function getStatementPrototype()
{
return $this->statementPrototype;
}
/**
* Register result prototype
*
* @param Result $resultPrototype
* @return self Provides a fluent interface
*/
public function registerResultPrototype(Result $resultPrototype)
{
$this->resultPrototype = $resultPrototype;
return $this;
}
/**
* @return null|Result
*/
public function getResultPrototype()
{
return $this->resultPrototype;
}
/**
* Add feature
*
* @param string $name
* @param AbstractFeature $feature
* @return self Provides a fluent interface
*/
public function addFeature($name, $feature)
{
if ($feature instanceof AbstractFeature) {
$name = $feature->getName(); // overwrite the name, just in case
$feature->setDriver($this);
}
$this->features[$name] = $feature;
return $this;
}
/**
* Setup the default features for Pdo
*
* @return self Provides a fluent interface
*/
public function setupDefaultFeatures()
{
$this->addFeature(null, new Feature\RowCounter());
return $this;
}
/**
* Get feature
*
* @param string $name
* @return AbstractFeature|false
*/
public function getFeature($name)
{
if (isset($this->features[$name])) {
return $this->features[$name];
}
return false;
}
/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
return 'Oracle';
}
/**
* Check environment
*/
public function checkEnvironment()
{
if (! extension_loaded('oci8')) {
throw new Exception\RuntimeException(
'The Oci8 extension is required for this adapter but the extension is not loaded'
);
}
}
/**
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* @param string $sqlOrResource
* @return Statement
*/
public function createStatement($sqlOrResource = null)
{
$statement = clone $this->statementPrototype;
if (is_resource($sqlOrResource) && get_resource_type($sqlOrResource) == 'oci8 statement') {
$statement->setResource($sqlOrResource);
} else {
if (is_string($sqlOrResource)) {
$statement->setSql($sqlOrResource);
} elseif ($sqlOrResource !== null) {
throw new Exception\InvalidArgumentException(
'Oci8 only accepts an SQL string or an oci8 resource in ' . __FUNCTION__
);
}
if (! $this->connection->isConnected()) {
$this->connection->connect();
}
$statement->initialize($this->connection->getResource());
}
return $statement;
}
/**
* @param resource $resource
* @param null $context
* @return Result
*/
public function createResult($resource, $context = null)
{
$result = clone $this->resultPrototype;
$rowCount = null;
// special feature, oracle Oci counter
if ($context && ($rowCounter = $this->getFeature('RowCounter')) && oci_num_fields($resource) > 0) {
$rowCount = $rowCounter->getRowCountClosure($context);
}
$result->initialize($resource, null, $rowCount);
return $result;
}
/**
* @return string
*/
public function getPrepareType()
{
return self::PARAMETERIZATION_NAMED;
}
/**
* @param string $name
* @param mixed $type
* @return string
*/
public function formatParameterName($name, $type = null)
{
return ':' . $name;
}
/**
* @return mixed
*/
public function getLastGeneratedValue()
{
return $this->getConnection()->getLastGeneratedValue();
}
}

View File

@ -1,231 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Oci8;
use Iterator;
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\Adapter\Exception;
class Result implements Iterator, ResultInterface
{
/**
* @var resource
*/
protected $resource = null;
/**
* @var null|int
*/
protected $rowCount = null;
/**
* Cursor position
* @var int
*/
protected $position = 0;
/**
* Number of known rows
* @var int
*/
protected $numberOfRows = -1;
/**
* Is the current() operation already complete for this pointer position?
* @var bool
*/
protected $currentComplete = false;
/**
* @var bool|array
*/
protected $currentData = false;
/**
*
* @var array
*/
protected $statementBindValues = ['keys' => null, 'values' => []];
/**
* @var mixed
*/
protected $generatedValue = null;
/**
* Initialize
* @param resource $resource
* @param null|int $generatedValue
* @param null|int $rowCount
* @return self Provides a fluent interface
*/
public function initialize($resource, $generatedValue = null, $rowCount = null)
{
if (! is_resource($resource) && get_resource_type($resource) !== 'oci8 statement') {
throw new Exception\InvalidArgumentException('Invalid resource provided.');
}
$this->resource = $resource;
$this->generatedValue = $generatedValue;
$this->rowCount = $rowCount;
return $this;
}
/**
* Force buffering at driver level
*
* Oracle does not support this, to my knowledge (@ralphschindler)
*
* @throws Exception\RuntimeException
*/
public function buffer()
{
return;
}
/**
* Is the result buffered?
*
* @return bool
*/
public function isBuffered()
{
return false;
}
/**
* Return the resource
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Is query result?
*
* @return bool
*/
public function isQueryResult()
{
return (oci_num_fields($this->resource) > 0);
}
/**
* Get affected rows
* @return int
*/
public function getAffectedRows()
{
return oci_num_rows($this->resource);
}
/**
* Current
* @return mixed
*/
public function current()
{
if ($this->currentComplete == false) {
if ($this->loadData() === false) {
return false;
}
}
return $this->currentData;
}
/**
* Load from oci8 result
*
* @return bool
*/
protected function loadData()
{
$this->currentComplete = true;
$this->currentData = oci_fetch_assoc($this->resource);
if ($this->currentData !== false) {
$this->position++;
return true;
}
return false;
}
/**
* Next
*/
public function next()
{
return $this->loadData();
}
/**
* Key
* @return mixed
*/
public function key()
{
return $this->position;
}
/**
* Rewind
*/
public function rewind()
{
if ($this->position > 0) {
throw new Exception\RuntimeException('Oci8 results cannot be rewound for multiple iterations');
}
}
/**
* Valid
* @return bool
*/
public function valid()
{
if ($this->currentComplete) {
return ($this->currentData !== false);
}
return $this->loadData();
}
/**
* Count
* @return null|int
*/
public function count()
{
if (is_int($this->rowCount)) {
return $this->rowCount;
}
if (is_callable($this->rowCount)) {
$this->rowCount = (int) call_user_func($this->rowCount);
return $this->rowCount;
}
return;
}
/**
* @return int
*/
public function getFieldCount()
{
return oci_num_fields($this->resource);
}
/**
* @return null
*/
public function getGeneratedValue()
{
// @todo OCI8 generated value in Driver Result
return;
}
}

View File

@ -1,327 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Oci8;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;
class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
{
/**
* @var resource
*/
protected $oci8 = null;
/**
* @var Oci8
*/
protected $driver = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var string
*/
protected $sql = '';
/**
* Parameter container
*
* @var ParameterContainer
*/
protected $parameterContainer = null;
/**
* @var resource
*/
protected $resource = null;
/**
* Is prepared
*
* @var bool
*/
protected $isPrepared = false;
/**
* @var bool
*/
protected $bufferResults = false;
/**
* Set driver
*
* @param Oci8 $driver
* @return self Provides a fluent interface
*/
public function setDriver($driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Initialize
*
* @param resource $oci8
* @return self Provides a fluent interface
*/
public function initialize($oci8)
{
$this->oci8 = $oci8;
return $this;
}
/**
* Set sql
*
* @param string $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Set Parameter container
*
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* Get resource
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Set resource
*
* @param resource $oci8Statement
* @return self Provides a fluent interface
*/
public function setResource($oci8Statement)
{
$type = oci_statement_type($oci8Statement);
if (false === $type || 'UNKNOWN' == $type) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid statement provided to %s',
__METHOD__
));
}
$this->resource = $oci8Statement;
$this->isPrepared = true;
return $this;
}
/**
* Get sql
*
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* @return ParameterContainer
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
/**
* @return bool
*/
public function isPrepared()
{
return $this->isPrepared;
}
/**
* @param string $sql
* @return self Provides a fluent interface
*/
public function prepare($sql = null)
{
if ($this->isPrepared) {
throw new Exception\RuntimeException('This statement has already been prepared');
}
$sql = ($sql) ?: $this->sql;
// get oci8 statement resource
$this->resource = oci_parse($this->oci8, $sql);
if (! $this->resource) {
$e = oci_error($this->oci8);
throw new Exception\InvalidQueryException(
'Statement couldn\'t be produced with sql: ' . $sql,
null,
new Exception\ErrorException($e['message'], $e['code'])
);
}
$this->isPrepared = true;
return $this;
}
/**
* Execute
*
* @param null|array|ParameterContainer $parameters
* @return mixed
*/
public function execute($parameters = null)
{
if (! $this->isPrepared) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (! $this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
if ($this->driver->getConnection()->inTransaction()) {
$ret = @oci_execute($this->resource, OCI_NO_AUTO_COMMIT);
} else {
$ret = @oci_execute($this->resource, OCI_COMMIT_ON_SUCCESS);
}
if ($this->profiler) {
$this->profiler->profilerFinish();
}
if ($ret === false) {
$e = oci_error($this->resource);
throw new Exception\RuntimeException($e['message'], $e['code']);
}
$result = $this->driver->createResult($this->resource, $this);
return $result;
}
/**
* Bind parameters from container
*/
protected function bindParametersFromContainer()
{
$parameters = $this->parameterContainer->getNamedArray();
foreach ($parameters as $name => &$value) {
if ($this->parameterContainer->offsetHasErrata($name)) {
switch ($this->parameterContainer->offsetGetErrata($name)) {
case ParameterContainer::TYPE_NULL:
$type = null;
$value = null;
break;
case ParameterContainer::TYPE_DOUBLE:
case ParameterContainer::TYPE_INTEGER:
$type = SQLT_INT;
if (is_string($value)) {
$value = (int) $value;
}
break;
case ParameterContainer::TYPE_BINARY:
$type = SQLT_BIN;
break;
case ParameterContainer::TYPE_LOB:
$type = OCI_B_CLOB;
$clob = oci_new_descriptor($this->driver->getConnection()->getResource(), OCI_DTYPE_LOB);
$clob->writetemporary($value, OCI_TEMP_CLOB);
$value = $clob;
break;
case ParameterContainer::TYPE_STRING:
default:
$type = SQLT_CHR;
break;
}
} else {
$type = SQLT_CHR;
}
$maxLength = -1;
if ($this->parameterContainer->offsetHasMaxLength($name)) {
$maxLength = $this->parameterContainer->offsetGetMaxLength($name);
}
oci_bind_by_name($this->resource, $name, $value, $maxLength, $type);
}
}
/**
* Perform a deep clone
*/
public function __clone()
{
$this->isPrepared = false;
$this->parametersBound = false;
$this->resource = null;
if ($this->parameterContainer) {
$this->parameterContainer = clone $this->parameterContainer;
}
}
}

View File

@ -1,432 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pdo;
use Zend\Db\Adapter\Driver\AbstractConnection;
use Zend\Db\Adapter\Exception;
class Connection extends AbstractConnection
{
/**
* @var Pdo
*/
protected $driver = null;
/**
* @var \PDO
*/
protected $resource = null;
/**
* @var string
*/
protected $dsn = null;
/**
* Constructor
*
* @param array|\PDO|null $connectionParameters
* @throws Exception\InvalidArgumentException
*/
public function __construct($connectionParameters = null)
{
if (is_array($connectionParameters)) {
$this->setConnectionParameters($connectionParameters);
} elseif ($connectionParameters instanceof \PDO) {
$this->setResource($connectionParameters);
} elseif (null !== $connectionParameters) {
throw new Exception\InvalidArgumentException(
'$connection must be an array of parameters, a PDO object or null'
);
}
}
/**
* Set driver
*
* @param Pdo $driver
* @return self Provides a fluent interface
*/
public function setDriver(Pdo $driver)
{
$this->driver = $driver;
return $this;
}
/**
* {@inheritDoc}
*/
public function setConnectionParameters(array $connectionParameters)
{
$this->connectionParameters = $connectionParameters;
if (isset($connectionParameters['dsn'])) {
$this->driverName = substr(
$connectionParameters['dsn'],
0,
strpos($connectionParameters['dsn'], ':')
);
} elseif (isset($connectionParameters['pdodriver'])) {
$this->driverName = strtolower($connectionParameters['pdodriver']);
} elseif (isset($connectionParameters['driver'])) {
$this->driverName = strtolower(substr(
str_replace(['-', '_', ' '], '', $connectionParameters['driver']),
3
));
}
}
/**
* Get the dsn string for this connection
* @throws \Zend\Db\Adapter\Exception\RunTimeException
* @return string
*/
public function getDsn()
{
if (! $this->dsn) {
throw new Exception\RuntimeException(
'The DSN has not been set or constructed from parameters in connect() for this Connection'
);
}
return $this->dsn;
}
/**
* {@inheritDoc}
*/
public function getCurrentSchema()
{
if (! $this->isConnected()) {
$this->connect();
}
switch ($this->driverName) {
case 'mysql':
$sql = 'SELECT DATABASE()';
break;
case 'sqlite':
return 'main';
case 'sqlsrv':
case 'dblib':
$sql = 'SELECT SCHEMA_NAME()';
break;
case 'pgsql':
default:
$sql = 'SELECT CURRENT_SCHEMA';
break;
}
/** @var $result \PDOStatement */
$result = $this->resource->query($sql);
if ($result instanceof \PDOStatement) {
return $result->fetchColumn();
}
return false;
}
/**
* Set resource
*
* @param \PDO $resource
* @return self Provides a fluent interface
*/
public function setResource(\PDO $resource)
{
$this->resource = $resource;
$this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME));
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\InvalidConnectionParametersException
* @throws Exception\RuntimeException
*/
public function connect()
{
if ($this->resource) {
return $this;
}
$dsn = $username = $password = $hostname = $database = null;
$options = [];
foreach ($this->connectionParameters as $key => $value) {
switch (strtolower($key)) {
case 'dsn':
$dsn = $value;
break;
case 'driver':
$value = strtolower((string) $value);
if (strpos($value, 'pdo') === 0) {
$pdoDriver = str_replace(['-', '_', ' '], '', $value);
$pdoDriver = substr($pdoDriver, 3) ?: '';
}
break;
case 'pdodriver':
$pdoDriver = (string) $value;
break;
case 'user':
case 'username':
$username = (string) $value;
break;
case 'pass':
case 'password':
$password = (string) $value;
break;
case 'host':
case 'hostname':
$hostname = (string) $value;
break;
case 'port':
$port = (int) $value;
break;
case 'database':
case 'dbname':
$database = (string) $value;
break;
case 'charset':
$charset = (string) $value;
break;
case 'unix_socket':
$unix_socket = (string) $value;
break;
case 'version':
$version = (string) $value;
break;
case 'driver_options':
case 'options':
$value = (array) $value;
$options = array_diff_key($options, $value) + $value;
break;
default:
$options[$key] = $value;
break;
}
}
if (isset($hostname) && isset($unix_socket)) {
throw new Exception\InvalidConnectionParametersException(
'Ambiguous connection parameters, both hostname and unix_socket parameters were set',
$this->connectionParameters
);
}
if (! isset($dsn) && isset($pdoDriver)) {
$dsn = [];
switch ($pdoDriver) {
case 'sqlite':
$dsn[] = $database;
break;
case 'sqlsrv':
if (isset($database)) {
$dsn[] = "database={$database}";
}
if (isset($hostname)) {
$dsn[] = "server={$hostname}";
}
break;
default:
if (isset($database)) {
$dsn[] = "dbname={$database}";
}
if (isset($hostname)) {
$dsn[] = "host={$hostname}";
}
if (isset($port)) {
$dsn[] = "port={$port}";
}
if (isset($charset) && $pdoDriver != 'pgsql') {
$dsn[] = "charset={$charset}";
}
if (isset($unix_socket)) {
$dsn[] = "unix_socket={$unix_socket}";
}
if (isset($version)) {
$dsn[] = "version={$version}";
}
break;
}
$dsn = $pdoDriver . ':' . implode(';', $dsn);
} elseif (! isset($dsn)) {
throw new Exception\InvalidConnectionParametersException(
'A dsn was not provided or could not be constructed from your parameters',
$this->connectionParameters
);
}
$this->dsn = $dsn;
try {
$this->resource = new \PDO($dsn, $username, $password, $options);
$this->resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
if (isset($charset) && $pdoDriver == 'pgsql') {
$this->resource->exec('SET NAMES ' . $this->resource->quote($charset));
}
$this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME));
} catch (\PDOException $e) {
$code = $e->getCode();
if (! is_long($code)) {
$code = null;
}
throw new Exception\RuntimeException('Connect Error: ' . $e->getMessage(), $code, $e);
}
return $this;
}
/**
* {@inheritDoc}
*/
public function isConnected()
{
return ($this->resource instanceof \PDO);
}
/**
* {@inheritDoc}
*/
public function beginTransaction()
{
if (! $this->isConnected()) {
$this->connect();
}
if (0 === $this->nestedTransactionsCount) {
$this->resource->beginTransaction();
$this->inTransaction = true;
}
$this->nestedTransactionsCount ++;
return $this;
}
/**
* {@inheritDoc}
*/
public function commit()
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->inTransaction) {
$this->nestedTransactionsCount -= 1;
}
/*
* This shouldn't check for being in a transaction since
* after issuing a SET autocommit=0; we have to commit too.
*/
if (0 === $this->nestedTransactionsCount) {
$this->resource->commit();
$this->inTransaction = false;
}
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\RuntimeException
*/
public function rollback()
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback');
}
if (! $this->inTransaction()) {
throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback');
}
$this->resource->rollBack();
$this->inTransaction = false;
$this->nestedTransactionsCount = 0;
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\InvalidQueryException
*/
public function execute($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->profiler) {
$this->profiler->profilerStart($sql);
}
$resultResource = $this->resource->query($sql);
if ($this->profiler) {
$this->profiler->profilerFinish($sql);
}
if ($resultResource === false) {
$errorInfo = $this->resource->errorInfo();
throw new Exception\InvalidQueryException($errorInfo[2]);
}
$result = $this->driver->createResult($resultResource, $sql);
return $result;
}
/**
* Prepare
*
* @param string $sql
* @return Statement
*/
public function prepare($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
$statement = $this->driver->createStatement($sql);
return $statement;
}
/**
* {@inheritDoc}
*
* @param string $name
* @return string|null|false
*/
public function getLastGeneratedValue($name = null)
{
if ($name === null
&& ($this->driverName == 'pgsql' || $this->driverName == 'firebird')) {
return;
}
try {
return $this->resource->lastInsertId($name);
} catch (\Exception $e) {
// do nothing
}
return false;
}
}

View File

@ -1,76 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pdo\Feature;
use Zend\Db\Adapter\Driver\Feature\AbstractFeature;
use Zend\Db\Adapter\Driver\Pdo;
/**
* OracleRowCounter
*/
class OracleRowCounter extends AbstractFeature
{
/**
* @return string
*/
public function getName()
{
return 'OracleRowCounter';
}
/**
* @param \Zend\Db\Adapter\Driver\Pdo\Statement $statement
* @return int
*/
public function getCountForStatement(Pdo\Statement $statement)
{
$countStmt = clone $statement;
$sql = $statement->getSql();
if ($sql == '' || stripos($sql, 'select') === false) {
return;
}
$countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')';
$countStmt->prepare($countSql);
$result = $countStmt->execute();
$countRow = $result->getResource()->fetch(\PDO::FETCH_ASSOC);
unset($statement, $result);
return $countRow['count'];
}
/**
* @param $sql
* @return null|int
*/
public function getCountForSql($sql)
{
if (stripos($sql, 'select') === false) {
return;
}
$countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')';
/** @var $pdo \PDO */
$pdo = $this->driver->getConnection()->getResource();
$result = $pdo->query($countSql);
$countRow = $result->fetch(\PDO::FETCH_ASSOC);
return $countRow['count'];
}
/**
* @param $context
* @return \Closure
*/
public function getRowCountClosure($context)
{
return function () use ($context) {
return ($context instanceof Pdo\Statement)
? $this->getCountForStatement($context)
: $this->getCountForSql($context);
};
}
}

View File

@ -1,76 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pdo\Feature;
use Zend\Db\Adapter\Driver\Feature\AbstractFeature;
use Zend\Db\Adapter\Driver\Pdo;
/**
* SqliteRowCounter
*/
class SqliteRowCounter extends AbstractFeature
{
/**
* @return string
*/
public function getName()
{
return 'SqliteRowCounter';
}
/**
* @param \Zend\Db\Adapter\Driver\Pdo\Statement $statement
* @return int
*/
public function getCountForStatement(Pdo\Statement $statement)
{
$countStmt = clone $statement;
$sql = $statement->getSql();
if ($sql == '' || stripos($sql, 'select') === false) {
return;
}
$countSql = 'SELECT COUNT(*) as "count" FROM (' . $sql . ')';
$countStmt->prepare($countSql);
$result = $countStmt->execute();
$countRow = $result->getResource()->fetch(\PDO::FETCH_ASSOC);
unset($statement, $result);
return $countRow['count'];
}
/**
* @param $sql
* @return null|int
*/
public function getCountForSql($sql)
{
if (stripos($sql, 'select') === false) {
return;
}
$countSql = 'SELECT COUNT(*) as count FROM (' . $sql . ')';
/** @var $pdo \PDO */
$pdo = $this->driver->getConnection()->getResource();
$result = $pdo->query($countSql);
$countRow = $result->fetch(\PDO::FETCH_ASSOC);
return $countRow['count'];
}
/**
* @param $context
* @return \Closure
*/
public function getRowCountClosure($context)
{
return function () use ($context) {
return ($context instanceof Pdo\Statement)
? $this->getCountForStatement($context)
: $this->getCountForSql($context);
};
}
}

View File

@ -1,331 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pdo;
use PDOStatement;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Feature\AbstractFeature;
use Zend\Db\Adapter\Driver\Feature\DriverFeatureInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\Profiler;
class Pdo implements DriverInterface, DriverFeatureInterface, Profiler\ProfilerAwareInterface
{
/**
* @const
*/
const FEATURES_DEFAULT = 'default';
/**
* @var Connection
*/
protected $connection = null;
/**
* @var Statement
*/
protected $statementPrototype = null;
/**
* @var Result
*/
protected $resultPrototype = null;
/**
* @var array
*/
protected $features = [];
/**
* @param array|Connection|\PDO $connection
* @param null|Statement $statementPrototype
* @param null|Result $resultPrototype
* @param string $features
*/
public function __construct(
$connection,
Statement $statementPrototype = null,
Result $resultPrototype = null,
$features = self::FEATURES_DEFAULT
) {
if (! $connection instanceof Connection) {
$connection = new Connection($connection);
}
$this->registerConnection($connection);
$this->registerStatementPrototype(($statementPrototype) ?: new Statement());
$this->registerResultPrototype(($resultPrototype) ?: new Result());
if (is_array($features)) {
foreach ($features as $name => $feature) {
$this->addFeature($name, $feature);
}
} elseif ($features instanceof AbstractFeature) {
$this->addFeature($features->getName(), $features);
} elseif ($features === self::FEATURES_DEFAULT) {
$this->setupDefaultFeatures();
}
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->connection instanceof Profiler\ProfilerAwareInterface) {
$this->connection->setProfiler($profiler);
}
if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) {
$this->statementPrototype->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Register connection
*
* @param Connection $connection
* @return self Provides a fluent interface
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this);
return $this;
}
/**
* Register statement prototype
*
* @param Statement $statementPrototype
*/
public function registerStatementPrototype(Statement $statementPrototype)
{
$this->statementPrototype = $statementPrototype;
$this->statementPrototype->setDriver($this);
}
/**
* Register result prototype
*
* @param Result $resultPrototype
*/
public function registerResultPrototype(Result $resultPrototype)
{
$this->resultPrototype = $resultPrototype;
}
/**
* Add feature
*
* @param string $name
* @param AbstractFeature $feature
* @return self Provides a fluent interface
*/
public function addFeature($name, $feature)
{
if ($feature instanceof AbstractFeature) {
$name = $feature->getName(); // overwrite the name, just in case
$feature->setDriver($this);
}
$this->features[$name] = $feature;
return $this;
}
/**
* Setup the default features for Pdo
*
* @return self Provides a fluent interface
*/
public function setupDefaultFeatures()
{
$driverName = $this->connection->getDriverName();
if ($driverName == 'sqlite') {
$this->addFeature(null, new Feature\SqliteRowCounter);
} elseif ($driverName == 'oci') {
$this->addFeature(null, new Feature\OracleRowCounter);
}
return $this;
}
/**
* Get feature
*
* @param $name
* @return AbstractFeature|false
*/
public function getFeature($name)
{
if (isset($this->features[$name])) {
return $this->features[$name];
}
return false;
}
/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
$name = $this->getConnection()->getDriverName();
if ($nameFormat == self::NAME_FORMAT_CAMELCASE) {
switch ($name) {
case 'pgsql':
return 'Postgresql';
case 'oci':
return 'Oracle';
case 'dblib':
case 'sqlsrv':
return 'SqlServer';
default:
return ucfirst($name);
}
} else {
switch ($name) {
case 'sqlite':
return 'SQLite';
case 'mysql':
return 'MySQL';
case 'pgsql':
return 'PostgreSQL';
case 'oci':
return 'Oracle';
case 'dblib':
case 'sqlsrv':
return 'SQLServer';
default:
return ucfirst($name);
}
}
}
/**
* Check environment
*/
public function checkEnvironment()
{
if (! extension_loaded('PDO')) {
throw new Exception\RuntimeException(
'The PDO extension is required for this adapter but the extension is not loaded'
);
}
}
/**
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* @param string|PDOStatement $sqlOrResource
* @return Statement
*/
public function createStatement($sqlOrResource = null)
{
$statement = clone $this->statementPrototype;
if ($sqlOrResource instanceof PDOStatement) {
$statement->setResource($sqlOrResource);
} else {
if (is_string($sqlOrResource)) {
$statement->setSql($sqlOrResource);
}
if (! $this->connection->isConnected()) {
$this->connection->connect();
}
$statement->initialize($this->connection->getResource());
}
return $statement;
}
/**
* @param resource $resource
* @param mixed $context
* @return Result
*/
public function createResult($resource, $context = null)
{
$result = clone $this->resultPrototype;
$rowCount = null;
// special feature, sqlite PDO counter
if ($this->connection->getDriverName() == 'sqlite'
&& ($sqliteRowCounter = $this->getFeature('SqliteRowCounter'))
&& $resource->columnCount() > 0) {
$rowCount = $sqliteRowCounter->getRowCountClosure($context);
}
// special feature, oracle PDO counter
if ($this->connection->getDriverName() == 'oci'
&& ($oracleRowCounter = $this->getFeature('OracleRowCounter'))
&& $resource->columnCount() > 0) {
$rowCount = $oracleRowCounter->getRowCountClosure($context);
}
$result->initialize($resource, $this->connection->getLastGeneratedValue(), $rowCount);
return $result;
}
/**
* @return string
*/
public function getPrepareType()
{
return self::PARAMETERIZATION_NAMED;
}
/**
* @param string $name
* @param string|null $type
* @return string
*/
public function formatParameterName($name, $type = null)
{
if ($type === null && ! is_numeric($name) || $type == self::PARAMETERIZATION_NAMED) {
$name = ltrim($name, ':');
// @see https://bugs.php.net/bug.php?id=43130
if (preg_match('/[^a-zA-Z0-9_]/', $name)) {
throw new Exception\RuntimeException(sprintf(
'The PDO param %s contains invalid characters.'
. ' Only alphabetic characters, digits, and underscores (_)'
. ' are allowed.',
$name
));
}
return ':' . $name;
}
return '?';
}
/**
* @param string|null $name
* @return string|null|false
*/
public function getLastGeneratedValue($name = null)
{
return $this->connection->getLastGeneratedValue($name);
}
}

View File

@ -1,254 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pdo;
use Iterator;
use PDOStatement;
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\Adapter\Exception;
class Result implements Iterator, ResultInterface
{
const STATEMENT_MODE_SCROLLABLE = 'scrollable';
const STATEMENT_MODE_FORWARD = 'forward';
/**
*
* @var string
*/
protected $statementMode = self::STATEMENT_MODE_FORWARD;
/**
* @var int
*/
protected $fetchMode = \PDO::FETCH_ASSOC;
/**
* @var PDOStatement
*/
protected $resource = null;
/**
* @var array Result options
*/
protected $options;
/**
* Is the current complete?
* @var bool
*/
protected $currentComplete = false;
/**
* Track current item in recordset
* @var mixed
*/
protected $currentData = null;
/**
* Current position of scrollable statement
* @var int
*/
protected $position = -1;
/**
* @var mixed
*/
protected $generatedValue = null;
/**
* @var null
*/
protected $rowCount = null;
/**
* Initialize
*
* @param PDOStatement $resource
* @param $generatedValue
* @param int $rowCount
* @return self Provides a fluent interface
*/
public function initialize(PDOStatement $resource, $generatedValue, $rowCount = null)
{
$this->resource = $resource;
$this->generatedValue = $generatedValue;
$this->rowCount = $rowCount;
return $this;
}
/**
* @return null
*/
public function buffer()
{
return;
}
/**
* @return bool|null
*/
public function isBuffered()
{
return false;
}
/**
* @param int $fetchMode
* @throws Exception\InvalidArgumentException on invalid fetch mode
*/
public function setFetchMode($fetchMode)
{
if ($fetchMode < 1 || $fetchMode > 10) {
throw new Exception\InvalidArgumentException(
'The fetch mode must be one of the PDO::FETCH_* constants.'
);
}
$this->fetchMode = (int) $fetchMode;
}
/**
* @return int
*/
public function getFetchMode()
{
return $this->fetchMode;
}
/**
* Get resource
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Get the data
* @return array
*/
public function current()
{
if ($this->currentComplete) {
return $this->currentData;
}
$this->currentData = $this->resource->fetch($this->fetchMode);
$this->currentComplete = true;
return $this->currentData;
}
/**
* Next
*
* @return mixed
*/
public function next()
{
$this->currentData = $this->resource->fetch($this->fetchMode);
$this->currentComplete = true;
$this->position++;
return $this->currentData;
}
/**
* Key
*
* @return mixed
*/
public function key()
{
return $this->position;
}
/**
* @throws Exception\RuntimeException
* @return void
*/
public function rewind()
{
if ($this->statementMode == self::STATEMENT_MODE_FORWARD && $this->position > 0) {
throw new Exception\RuntimeException(
'This result is a forward only result set, calling rewind() after moving forward is not supported'
);
}
$this->currentData = $this->resource->fetch($this->fetchMode);
$this->currentComplete = true;
$this->position = 0;
}
/**
* Valid
*
* @return bool
*/
public function valid()
{
return ($this->currentData !== false);
}
/**
* Count
*
* @return int
*/
public function count()
{
if (is_int($this->rowCount)) {
return $this->rowCount;
}
if ($this->rowCount instanceof \Closure) {
$this->rowCount = (int) call_user_func($this->rowCount);
} else {
$this->rowCount = (int) $this->resource->rowCount();
}
return $this->rowCount;
}
/**
* @return int
*/
public function getFieldCount()
{
return $this->resource->columnCount();
}
/**
* Is query result
*
* @return bool
*/
public function isQueryResult()
{
return ($this->resource->columnCount() > 0);
}
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows()
{
return $this->resource->rowCount();
}
/**
* @return mixed|null
*/
public function getGeneratedValue()
{
return $this->generatedValue;
}
}

View File

@ -1,310 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pdo;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;
class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
{
/**
* @var \PDO
*/
protected $pdo = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var Pdo
*/
protected $driver = null;
/**
*
* @var string
*/
protected $sql = '';
/**
*
* @var bool
*/
protected $isQuery = null;
/**
*
* @var ParameterContainer
*/
protected $parameterContainer = null;
/**
* @var bool
*/
protected $parametersBound = false;
/**
* @var \PDOStatement
*/
protected $resource = null;
/**
*
* @var bool
*/
protected $isPrepared = false;
/**
* Set driver
*
* @param Pdo $driver
* @return self Provides a fluent interface
*/
public function setDriver(Pdo $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Initialize
*
* @param \PDO $connectionResource
* @return self Provides a fluent interface
*/
public function initialize(\PDO $connectionResource)
{
$this->pdo = $connectionResource;
return $this;
}
/**
* Set resource
*
* @param \PDOStatement $pdoStatement
* @return self Provides a fluent interface
*/
public function setResource(\PDOStatement $pdoStatement)
{
$this->resource = $pdoStatement;
return $this;
}
/**
* Get resource
*
* @return mixed
*/
public function getResource()
{
return $this->resource;
}
/**
* Set sql
*
* @param string $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Get sql
*
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* @return ParameterContainer
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
/**
* @param string $sql
* @throws Exception\RuntimeException
*/
public function prepare($sql = null)
{
if ($this->isPrepared) {
throw new Exception\RuntimeException('This statement has been prepared already');
}
if ($sql === null) {
$sql = $this->sql;
}
$this->resource = $this->pdo->prepare($sql);
if ($this->resource === false) {
$error = $this->pdo->errorInfo();
throw new Exception\RuntimeException($error[2]);
}
$this->isPrepared = true;
}
/**
* @return bool
*/
public function isPrepared()
{
return $this->isPrepared;
}
/**
* @param null|array|ParameterContainer $parameters
* @throws Exception\InvalidQueryException
* @return Result
*/
public function execute($parameters = null)
{
if (! $this->isPrepared) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (! $this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
try {
$this->resource->execute();
} catch (\PDOException $e) {
if ($this->profiler) {
$this->profiler->profilerFinish();
}
throw new Exception\InvalidQueryException(
'Statement could not be executed (' . implode(' - ', $this->resource->errorInfo()) . ')',
null,
$e
);
}
if ($this->profiler) {
$this->profiler->profilerFinish();
}
$result = $this->driver->createResult($this->resource, $this);
return $result;
}
/**
* Bind parameters from container
*/
protected function bindParametersFromContainer()
{
if ($this->parametersBound) {
return;
}
$parameters = $this->parameterContainer->getNamedArray();
foreach ($parameters as $name => &$value) {
if (is_bool($value)) {
$type = \PDO::PARAM_BOOL;
} elseif (is_int($value)) {
$type = \PDO::PARAM_INT;
} else {
$type = \PDO::PARAM_STR;
}
if ($this->parameterContainer->offsetHasErrata($name)) {
switch ($this->parameterContainer->offsetGetErrata($name)) {
case ParameterContainer::TYPE_INTEGER:
$type = \PDO::PARAM_INT;
break;
case ParameterContainer::TYPE_NULL:
$type = \PDO::PARAM_NULL;
break;
case ParameterContainer::TYPE_LOB:
$type = \PDO::PARAM_LOB;
break;
}
}
// parameter is named or positional, value is reference
$parameter = is_int($name) ? ($name + 1) : $this->driver->formatParameterName($name);
$this->resource->bindParam($parameter, $value, $type);
}
}
/**
* Perform a deep clone
* @return Statement A cloned statement
*/
public function __clone()
{
$this->isPrepared = false;
$this->parametersBound = false;
$this->resource = null;
if ($this->parameterContainer) {
$this->parameterContainer = clone $this->parameterContainer;
}
}
}

View File

@ -1,313 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pgsql;
use Zend\Db\Adapter\Driver\AbstractConnection;
use Zend\Db\Adapter\Exception;
class Connection extends AbstractConnection
{
/**
* @var Pgsql
*/
protected $driver = null;
/**
* @var resource
*/
protected $resource = null;
/**
* @var null|int PostgreSQL connection type
*/
protected $type = null;
/**
* Constructor
*
* @param resource|array|null $connectionInfo
*/
public function __construct($connectionInfo = null)
{
if (is_array($connectionInfo)) {
$this->setConnectionParameters($connectionInfo);
} elseif (is_resource($connectionInfo)) {
$this->setResource($connectionInfo);
}
}
/**
* Set resource
*
* @param resource $resource
* @return self Provides a fluent interface
*/
public function setResource($resource)
{
$this->resource = $resource;
return $this;
}
/**
* Set driver
*
* @param Pgsql $driver
* @return self Provides a fluent interface
*/
public function setDriver(Pgsql $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param int|null $type
* @return self Provides a fluent interface
*/
public function setType($type)
{
$invalidConectionType = ($type !== PGSQL_CONNECT_FORCE_NEW);
// Compatibility with PHP < 5.6
if ($invalidConectionType && defined('PGSQL_CONNECT_ASYNC')) {
$invalidConectionType = ($type !== PGSQL_CONNECT_ASYNC);
}
if ($invalidConectionType) {
throw new Exception\InvalidArgumentException(
'Connection type is not valid. (See: http://php.net/manual/en/function.pg-connect.php)'
);
}
$this->type = $type;
return $this;
}
/**
* {@inheritDoc}
*
* @return null|string
*/
public function getCurrentSchema()
{
if (! $this->isConnected()) {
$this->connect();
}
$result = pg_query($this->resource, 'SELECT CURRENT_SCHEMA AS "currentschema"');
if ($result == false) {
return;
}
return pg_fetch_result($result, 0, 'currentschema');
}
/**
* {@inheritDoc}
*
* @throws Exception\RuntimeException on failure
*/
public function connect()
{
if (is_resource($this->resource)) {
return $this;
}
$connection = $this->getConnectionString();
set_error_handler(function ($number, $string) {
throw new Exception\RuntimeException(
__METHOD__ . ': Unable to connect to database',
null,
new Exception\ErrorException($string, $number)
);
});
$this->resource = pg_connect($connection);
restore_error_handler();
if ($this->resource === false) {
throw new Exception\RuntimeException(sprintf(
'%s: Unable to connect to database',
__METHOD__
));
}
$p = $this->connectionParameters;
if (! empty($p['charset'])) {
if (-1 === pg_set_client_encoding($this->resource, $p['charset'])) {
throw new Exception\RuntimeException(sprintf(
"%s: Unable to set client encoding '%s'",
__METHOD__,
$p['charset']
));
}
}
return $this;
}
/**
* {@inheritDoc}
*/
public function isConnected()
{
return (is_resource($this->resource));
}
/**
* {@inheritDoc}
*/
public function disconnect()
{
pg_close($this->resource);
return $this;
}
/**
* {@inheritDoc}
*/
public function beginTransaction()
{
if ($this->inTransaction()) {
throw new Exception\RuntimeException('Nested transactions are not supported');
}
if (! $this->isConnected()) {
$this->connect();
}
pg_query($this->resource, 'BEGIN');
$this->inTransaction = true;
return $this;
}
/**
* {@inheritDoc}
*/
public function commit()
{
if (! $this->isConnected()) {
$this->connect();
}
if (! $this->inTransaction()) {
return; // We ignore attempts to commit non-existing transaction
}
pg_query($this->resource, 'COMMIT');
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*/
public function rollback()
{
if (! $this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback');
}
if (! $this->inTransaction()) {
throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback');
}
pg_query($this->resource, 'ROLLBACK');
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\InvalidQueryException
* @return resource|\Zend\Db\ResultSet\ResultSetInterface
*/
public function execute($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
if ($this->profiler) {
$this->profiler->profilerStart($sql);
}
$resultResource = pg_query($this->resource, $sql);
if ($this->profiler) {
$this->profiler->profilerFinish($sql);
}
// if the returnValue is something other than a pg result resource, bypass wrapping it
if ($resultResource === false) {
throw new Exception\InvalidQueryException(pg_errormessage());
}
$resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource);
return $resultPrototype;
}
/**
* {@inheritDoc}
*
* @return string
*/
public function getLastGeneratedValue($name = null)
{
if ($name === null) {
return;
}
$result = pg_query(
$this->resource,
'SELECT CURRVAL(\'' . str_replace('\'', '\\\'', $name) . '\') as "currval"'
);
return pg_fetch_result($result, 0, 'currval');
}
/**
* Get Connection String
*
* @return string
*/
private function getConnectionString()
{
// localize
$p = $this->connectionParameters;
// given a list of key names, test for existence in $p
$findParameterValue = function (array $names) use ($p) {
foreach ($names as $name) {
if (isset($p[$name])) {
return $p[$name];
}
}
return;
};
$connectionParameters = [
'host' => $findParameterValue(['hostname', 'host']),
'user' => $findParameterValue(['username', 'user']),
'password' => $findParameterValue(['password', 'passwd', 'pw']),
'dbname' => $findParameterValue(['database', 'dbname', 'db', 'schema']),
'port' => isset($p['port']) ? (int) $p['port'] : null,
'socket' => isset($p['socket']) ? $p['socket'] : null,
];
return urldecode(http_build_query(array_filter($connectionParameters), null, ' '));
}
}

View File

@ -1,237 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pgsql;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\Profiler;
class Pgsql implements DriverInterface, Profiler\ProfilerAwareInterface
{
/**
* @var Connection
*/
protected $connection = null;
/**
* @var Statement
*/
protected $statementPrototype = null;
/**
* @var Result
*/
protected $resultPrototype = null;
/**
* @var null|Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var array
*/
protected $options = [
'buffer_results' => false
];
/**
* Constructor
*
* @param array|Connection|resource $connection
* @param null|Statement $statementPrototype
* @param null|Result $resultPrototype
* @param array $options
*/
public function __construct(
$connection,
Statement $statementPrototype = null,
Result $resultPrototype = null,
$options = null
) {
if (! $connection instanceof Connection) {
$connection = new Connection($connection);
}
$this->registerConnection($connection);
$this->registerStatementPrototype(($statementPrototype) ?: new Statement());
$this->registerResultPrototype(($resultPrototype) ?: new Result());
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->connection instanceof Profiler\ProfilerAwareInterface) {
$this->connection->setProfiler($profiler);
}
if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) {
$this->statementPrototype->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Register connection
*
* @param Connection $connection
* @return self Provides a fluent interface
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this);
return $this;
}
/**
* Register statement prototype
*
* @param Statement $statement
* @return self Provides a fluent interface
*/
public function registerStatementPrototype(Statement $statement)
{
$this->statementPrototype = $statement;
$this->statementPrototype->setDriver($this); // needs access to driver to createResult()
return $this;
}
/**
* Register result prototype
*
* @param Result $result
* @return self Provides a fluent interface
*/
public function registerResultPrototype(Result $result)
{
$this->resultPrototype = $result;
return $this;
}
/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
if ($nameFormat == self::NAME_FORMAT_CAMELCASE) {
return 'Postgresql';
}
return 'PostgreSQL';
}
/**
* Check environment
*
* @throws Exception\RuntimeException
* @return bool
*/
public function checkEnvironment()
{
if (! extension_loaded('pgsql')) {
throw new Exception\RuntimeException(
'The PostgreSQL (pgsql) extension is required for this adapter but the extension is not loaded'
);
}
}
/**
* Get connection
*
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* Create statement
*
* @param string|null $sqlOrResource
* @return Statement
*/
public function createStatement($sqlOrResource = null)
{
$statement = clone $this->statementPrototype;
if (is_string($sqlOrResource)) {
$statement->setSql($sqlOrResource);
}
if (! $this->connection->isConnected()) {
$this->connection->connect();
}
$statement->initialize($this->connection->getResource());
return $statement;
}
/**
* Create result
*
* @param resource $resource
* @return Result
*/
public function createResult($resource)
{
$result = clone $this->resultPrototype;
$result->initialize($resource, $this->connection->getLastGeneratedValue());
return $result;
}
/**
* Get prepare Type
*
* @return string
*/
public function getPrepareType()
{
return self::PARAMETERIZATION_POSITIONAL;
}
/**
* Format parameter name
*
* @param string $name
* @param mixed $type
* @return string
*/
public function formatParameterName($name, $type = null)
{
return '$#';
}
/**
* Get last generated value
*
* @param string $name
* @return mixed
*/
public function getLastGeneratedValue($name = null)
{
return $this->connection->getLastGeneratedValue($name);
}
}

View File

@ -1,192 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pgsql;
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\Adapter\Exception;
class Result implements ResultInterface
{
/**
* @var resource
*/
protected $resource = null;
/**
* @var int
*/
protected $position = 0;
/**
* @var int
*/
protected $count = 0;
/**
* @var null|mixed
*/
protected $generatedValue = null;
/**
* Initialize
*
* @param $resource
* @param $generatedValue
* @return void
* @throws Exception\InvalidArgumentException
*/
public function initialize($resource, $generatedValue)
{
if (! is_resource($resource) || get_resource_type($resource) != 'pgsql result') {
throw new Exception\InvalidArgumentException('Resource not of the correct type.');
}
$this->resource = $resource;
$this->count = pg_num_rows($this->resource);
$this->generatedValue = $generatedValue;
}
/**
* Current
*
* @return array|bool|mixed
*/
public function current()
{
if ($this->count === 0) {
return false;
}
return pg_fetch_assoc($this->resource, $this->position);
}
/**
* Next
*
* @return void
*/
public function next()
{
$this->position++;
}
/**
* Key
*
* @return int|mixed
*/
public function key()
{
return $this->position;
}
/**
* Valid
*
* @return bool
*/
public function valid()
{
return ($this->position < $this->count);
}
/**
* Rewind
*
* @return void
*/
public function rewind()
{
$this->position = 0;
}
/**
* Buffer
*
* @return null
*/
public function buffer()
{
return;
}
/**
* Is buffered
*
* @return false
*/
public function isBuffered()
{
return false;
}
/**
* Is query result
*
* @return bool
*/
public function isQueryResult()
{
return (pg_num_fields($this->resource) > 0);
}
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows()
{
return pg_affected_rows($this->resource);
}
/**
* Get generated value
*
* @return mixed|null
*/
public function getGeneratedValue()
{
return $this->generatedValue;
}
/**
* Get resource
*/
public function getResource()
{
// TODO: Implement getResource() method.
}
/**
* Count
*
* (PHP 5 &gt;= 5.1.0)<br/>
* Count elements of an object
* @link http://php.net/manual/en/countable.count.php
* @return int The custom count as an integer.
* </p>
* <p>
* The return value is cast to an integer.
*/
public function count()
{
return $this->count;
}
/**
* Get field count
*
* @return int
*/
public function getFieldCount()
{
return pg_num_fields($this->resource);
}
}

View File

@ -1,242 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Pgsql;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;
class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
{
/**
* @var int
*/
protected static $statementIndex = 0;
/**
* @var string
*/
protected $statementName = '';
/**
* @var Pgsql
*/
protected $driver = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var resource
*/
protected $pgsql = null;
/**
* @var resource
*/
protected $resource = null;
/**
* @var string
*/
protected $sql;
/**
* @var ParameterContainer
*/
protected $parameterContainer;
/**
* @param Pgsql $driver
* @return self Provides a fluent interface
*/
public function setDriver(Pgsql $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Initialize
*
* @param resource $pgsql
* @return void
* @throws Exception\RuntimeException for invalid or missing postgresql connection
*/
public function initialize($pgsql)
{
if (! is_resource($pgsql) || get_resource_type($pgsql) !== 'pgsql link') {
throw new Exception\RuntimeException(sprintf(
'%s: Invalid or missing postgresql connection; received "%s"',
__METHOD__,
get_resource_type($pgsql)
));
}
$this->pgsql = $pgsql;
}
/**
* Get resource
*
* @return resource
*/
public function getResource()
{
// TODO: Implement getResource() method.
}
/**
* Set sql
*
* @param string $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Get sql
*
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* Set parameter container
*
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* Get parameter container
*
* @return ParameterContainer
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
/**
* Prepare
*
* @param string $sql
*/
public function prepare($sql = null)
{
$sql = ($sql) ?: $this->sql;
$pCount = 1;
$sql = preg_replace_callback(
'#\$\##',
function () use (&$pCount) {
return '$' . $pCount++;
},
$sql
);
$this->sql = $sql;
$this->statementName = 'statement' . ++static::$statementIndex;
$this->resource = pg_prepare($this->pgsql, $this->statementName, $sql);
}
/**
* Is prepared
*
* @return bool
*/
public function isPrepared()
{
return isset($this->resource);
}
/**
* Execute
*
* @param null|array|ParameterContainer $parameters
* @throws Exception\InvalidQueryException
* @return Result
*/
public function execute($parameters = null)
{
if (! $this->isPrepared()) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (! $this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$parameters = $this->parameterContainer->getPositionalArray();
}
/** END Standard ParameterContainer Merging Block */
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
$resultResource = pg_execute($this->pgsql, $this->statementName, (array) $parameters);
if ($this->profiler) {
$this->profiler->profilerFinish();
}
if ($resultResource === false) {
throw new Exception\InvalidQueryException(pg_last_error());
}
$result = $this->driver->createResult($resultResource);
return $result;
}
}

View File

@ -1,67 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver;
use Countable;
use Iterator;
interface ResultInterface extends
Countable,
Iterator
{
/**
* Force buffering
*
* @return void
*/
public function buffer();
/**
* Check if is buffered
*
* @return bool|null
*/
public function isBuffered();
/**
* Is query result?
*
* @return bool
*/
public function isQueryResult();
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows();
/**
* Get generated value
*
* @return mixed|null
*/
public function getGeneratedValue();
/**
* Get the resource
*
* @return mixed
*/
public function getResource();
/**
* Get field count
*
* @return int
*/
public function getFieldCount();
}

View File

@ -1,289 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Sqlsrv;
use Zend\Db\Adapter\Driver\AbstractConnection;
use Zend\Db\Adapter\Driver\Sqlsrv\Exception\ErrorException;
use Zend\Db\Adapter\Exception;
class Connection extends AbstractConnection
{
/**
* @var Sqlsrv
*/
protected $driver = null;
/**
* Constructor
*
* @param array|resource $connectionInfo
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function __construct($connectionInfo)
{
if (is_array($connectionInfo)) {
$this->setConnectionParameters($connectionInfo);
} elseif (is_resource($connectionInfo)) {
$this->setResource($connectionInfo);
} else {
throw new Exception\InvalidArgumentException('$connection must be an array of parameters or a resource');
}
}
/**
* Set driver
*
* @param Sqlsrv $driver
* @return self Provides a fluent interface
*/
public function setDriver(Sqlsrv $driver)
{
$this->driver = $driver;
return $this;
}
/**
* {@inheritDoc}
*/
public function getCurrentSchema()
{
if (! $this->isConnected()) {
$this->connect();
}
$result = sqlsrv_query($this->resource, 'SELECT SCHEMA_NAME()');
$r = sqlsrv_fetch_array($result);
return $r[0];
}
/**
* Set resource
*
* @param resource $resource
* @return self Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
public function setResource($resource)
{
if (get_resource_type($resource) !== 'SQL Server Connection') {
throw new Exception\InvalidArgumentException('Resource provided was not of type SQL Server Connection');
}
$this->resource = $resource;
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\RuntimeException
*/
public function connect()
{
if ($this->resource) {
return $this;
}
$serverName = '.';
$params = [
'ReturnDatesAsStrings' => true
];
foreach ($this->connectionParameters as $key => $value) {
switch (strtolower($key)) {
case 'hostname':
case 'servername':
$serverName = (string) $value;
break;
case 'username':
case 'uid':
$params['UID'] = (string) $value;
break;
case 'password':
case 'pwd':
$params['PWD'] = (string) $value;
break;
case 'database':
case 'dbname':
$params['Database'] = (string) $value;
break;
case 'charset':
$params['CharacterSet'] = (string) $value;
break;
case 'driver_options':
case 'options':
$params = array_merge($params, (array) $value);
break;
}
}
$this->resource = sqlsrv_connect($serverName, $params);
if (! $this->resource) {
throw new Exception\RuntimeException(
'Connect Error',
null,
new ErrorException(sqlsrv_errors())
);
}
return $this;
}
/**
* {@inheritDoc}
*/
public function isConnected()
{
return (is_resource($this->resource));
}
/**
* {@inheritDoc}
*/
public function disconnect()
{
sqlsrv_close($this->resource);
$this->resource = null;
}
/**
* {@inheritDoc}
*/
public function beginTransaction()
{
if (! $this->isConnected()) {
$this->connect();
}
if (sqlsrv_begin_transaction($this->resource) === false) {
throw new Exception\RuntimeException(
new ErrorException(sqlsrv_errors())
);
}
$this->inTransaction = true;
return $this;
}
/**
* {@inheritDoc}
*/
public function commit()
{
// http://msdn.microsoft.com/en-us/library/cc296194.aspx
if (! $this->isConnected()) {
$this->connect();
}
sqlsrv_commit($this->resource);
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*/
public function rollback()
{
// http://msdn.microsoft.com/en-us/library/cc296176.aspx
if (! $this->isConnected()) {
throw new Exception\RuntimeException('Must be connected before you can rollback.');
}
sqlsrv_rollback($this->resource);
$this->inTransaction = false;
return $this;
}
/**
* {@inheritDoc}
*
* @throws Exception\RuntimeException
*/
public function execute($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
if (! $this->driver instanceof Sqlsrv) {
throw new Exception\RuntimeException('Connection is missing an instance of Sqlsrv');
}
if ($this->profiler) {
$this->profiler->profilerStart($sql);
}
$returnValue = sqlsrv_query($this->resource, $sql);
if ($this->profiler) {
$this->profiler->profilerFinish($sql);
}
// if the returnValue is something other than a Sqlsrv_result, bypass wrapping it
if ($returnValue === false) {
$errors = sqlsrv_errors();
// ignore general warnings
if ($errors[0]['SQLSTATE'] != '01000') {
throw new Exception\RuntimeException(
'An exception occurred while trying to execute the provided $sql',
null,
new ErrorException($errors)
);
}
}
$result = $this->driver->createResult($returnValue);
return $result;
}
/**
* Prepare
*
* @param string $sql
* @return string
*/
public function prepare($sql)
{
if (! $this->isConnected()) {
$this->connect();
}
$statement = $this->driver->createStatement($sql);
return $statement;
}
/**
* {@inheritDoc}
*
* @return mixed
*/
public function getLastGeneratedValue($name = null)
{
if (! $this->resource) {
$this->connect();
}
$sql = 'SELECT @@IDENTITY as Current_Identity';
$result = sqlsrv_query($this->resource, $sql);
$row = sqlsrv_fetch_array($result);
return $row['Current_Identity'];
}
}

View File

@ -1,32 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Sqlsrv\Exception;
use Zend\Db\Adapter\Exception;
class ErrorException extends Exception\ErrorException implements ExceptionInterface
{
/**
* Errors
*
* @var array
*/
protected $errors = [];
/**
* Construct
*
* @param bool $errors
*/
public function __construct($errors = false)
{
$this->errors = ($errors === false) ? sqlsrv_errors() : $errors;
}
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Sqlsrv\Exception;
use Zend\Db\Adapter\Exception;
interface ExceptionInterface extends Exception\ExceptionInterface
{
}

View File

@ -1,208 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Sqlsrv;
use Iterator;
use Zend\Db\Adapter\Driver\ResultInterface;
class Result implements Iterator, ResultInterface
{
/**
* @var resource
*/
protected $resource = null;
/**
* @var bool
*/
protected $currentData = false;
/**
*
* @var bool
*/
protected $currentComplete = false;
/**
*
* @var int
*/
protected $position = -1;
/**
* @var mixed
*/
protected $generatedValue = null;
/**
* Initialize
*
* @param resource $resource
* @param mixed $generatedValue
* @return self Provides a fluent interface
*/
public function initialize($resource, $generatedValue = null)
{
$this->resource = $resource;
$this->generatedValue = $generatedValue;
return $this;
}
/**
* @return null
*/
public function buffer()
{
return;
}
/**
* @return bool
*/
public function isBuffered()
{
return false;
}
/**
* Get resource
*
* @return resource
*/
public function getResource()
{
return $this->resource;
}
/**
* Current
*
* @return mixed
*/
public function current()
{
if ($this->currentComplete) {
return $this->currentData;
}
$this->load();
return $this->currentData;
}
/**
* Next
*
* @return bool
*/
public function next()
{
$this->load();
return true;
}
/**
* Load
*
* @param int $row
* @return mixed
*/
protected function load($row = SQLSRV_SCROLL_NEXT)
{
$this->currentData = sqlsrv_fetch_array($this->resource, SQLSRV_FETCH_ASSOC, $row);
$this->currentComplete = true;
$this->position++;
return $this->currentData;
}
/**
* Key
*
* @return mixed
*/
public function key()
{
return $this->position;
}
/**
* Rewind
*
* @return bool
*/
public function rewind()
{
$this->position = 0;
$this->load(SQLSRV_SCROLL_FIRST);
return true;
}
/**
* Valid
*
* @return bool
*/
public function valid()
{
if ($this->currentComplete && $this->currentData) {
return true;
}
return $this->load();
}
/**
* Count
*
* @return int
*/
public function count()
{
return sqlsrv_num_rows($this->resource);
}
/**
* @return bool|int
*/
public function getFieldCount()
{
return sqlsrv_num_fields($this->resource);
}
/**
* Is query result
*
* @return bool
*/
public function isQueryResult()
{
if (is_bool($this->resource)) {
return false;
}
return (sqlsrv_num_fields($this->resource) > 0);
}
/**
* Get affected rows
*
* @return int
*/
public function getAffectedRows()
{
return sqlsrv_rows_affected($this->resource);
}
/**
* @return mixed|null
*/
public function getGeneratedValue()
{
return $this->generatedValue;
}
}

View File

@ -1,215 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Sqlsrv;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\Profiler;
class Sqlsrv implements DriverInterface, Profiler\ProfilerAwareInterface
{
/**
* @var Connection
*/
protected $connection = null;
/**
* @var Statement
*/
protected $statementPrototype = null;
/**
* @var Result
*/
protected $resultPrototype = null;
/**
* @var null|Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @param array|Connection|resource $connection
* @param null|Statement $statementPrototype
* @param null|Result $resultPrototype
*/
public function __construct($connection, Statement $statementPrototype = null, Result $resultPrototype = null)
{
if (! $connection instanceof Connection) {
$connection = new Connection($connection);
}
$this->registerConnection($connection);
$this->registerStatementPrototype(($statementPrototype) ?: new Statement());
$this->registerResultPrototype(($resultPrototype) ?: new Result());
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
if ($this->connection instanceof Profiler\ProfilerAwareInterface) {
$this->connection->setProfiler($profiler);
}
if ($this->statementPrototype instanceof Profiler\ProfilerAwareInterface) {
$this->statementPrototype->setProfiler($profiler);
}
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
* Register connection
*
* @param Connection $connection
* @return self Provides a fluent interface
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this);
return $this;
}
/**
* Register statement prototype
*
* @param Statement $statementPrototype
* @return self Provides a fluent interface
*/
public function registerStatementPrototype(Statement $statementPrototype)
{
$this->statementPrototype = $statementPrototype;
$this->statementPrototype->setDriver($this);
return $this;
}
/**
* Register result prototype
*
* @param Result $resultPrototype
* @return self Provides a fluent interface
*/
public function registerResultPrototype(Result $resultPrototype)
{
$this->resultPrototype = $resultPrototype;
return $this;
}
/**
* Get database paltform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
if ($nameFormat == self::NAME_FORMAT_CAMELCASE) {
return 'SqlServer';
}
return 'SQLServer';
}
/**
* Check environment
*
* @throws Exception\RuntimeException
* @return void
*/
public function checkEnvironment()
{
if (! extension_loaded('sqlsrv')) {
throw new Exception\RuntimeException(
'The Sqlsrv extension is required for this adapter but the extension is not loaded'
);
}
}
/**
* @return Connection
*/
public function getConnection()
{
return $this->connection;
}
/**
* @param string|resource $sqlOrResource
* @return Statement
*/
public function createStatement($sqlOrResource = null)
{
$statement = clone $this->statementPrototype;
if (is_resource($sqlOrResource)) {
$statement->initialize($sqlOrResource);
} else {
if (! $this->connection->isConnected()) {
$this->connection->connect();
}
$statement->initialize($this->connection->getResource());
if (is_string($sqlOrResource)) {
$statement->setSql($sqlOrResource);
} elseif ($sqlOrResource !== null) {
throw new Exception\InvalidArgumentException(
'createStatement() only accepts an SQL string or a Sqlsrv resource'
);
}
}
return $statement;
}
/**
* @param resource $resource
* @return Result
*/
public function createResult($resource)
{
$result = clone $this->resultPrototype;
$result->initialize($resource, $this->connection->getLastGeneratedValue());
return $result;
}
/**
* @return string
*/
public function getPrepareType()
{
return self::PARAMETERIZATION_POSITIONAL;
}
/**
* @param string $name
* @param mixed $type
* @return string
*/
public function formatParameterName($name, $type = null)
{
return '?';
}
/**
* @return mixed
*/
public function getLastGeneratedValue()
{
return $this->getConnection()->getLastGeneratedValue();
}
}

View File

@ -1,318 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver\Sqlsrv;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Adapter\Exception;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\Profiler;
class Statement implements StatementInterface, Profiler\ProfilerAwareInterface
{
/**
* @var resource
*/
protected $sqlsrv = null;
/**
* @var Sqlsrv
*/
protected $driver = null;
/**
* @var Profiler\ProfilerInterface
*/
protected $profiler = null;
/**
* @var string
*/
protected $sql = null;
/**
* @var bool
*/
protected $isQuery = null;
/**
* @var array
*/
protected $parameterReferences = [];
/**
* @var ParameterContainer
*/
protected $parameterContainer = null;
/**
* @var resource
*/
protected $resource = null;
/**
*
* @var bool
*/
protected $isPrepared = false;
/**
* @var array
*/
protected $prepareParams = [];
/**
* @var array
*/
protected $prepareOptions = [];
/**
* @var array
*/
protected $parameterReferenceValues = [];
/**
* Set driver
*
* @param Sqlsrv $driver
* @return self Provides a fluent interface
*/
public function setDriver(Sqlsrv $driver)
{
$this->driver = $driver;
return $this;
}
/**
* @param Profiler\ProfilerInterface $profiler
* @return self Provides a fluent interface
*/
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;
return $this;
}
/**
* @return null|Profiler\ProfilerInterface
*/
public function getProfiler()
{
return $this->profiler;
}
/**
*
* One of two resource types will be provided here:
* a) "SQL Server Connection" when a prepared statement needs to still be produced
* b) "SQL Server Statement" when a prepared statement has been already produced
* (there will need to already be a bound param set if it applies to this query)
*
* @param resource $resource
* @return self Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
public function initialize($resource)
{
$resourceType = get_resource_type($resource);
if ($resourceType == 'SQL Server Connection') {
$this->sqlsrv = $resource;
} elseif ($resourceType == 'SQL Server Statement') {
$this->resource = $resource;
$this->isPrepared = true;
} else {
throw new Exception\InvalidArgumentException('Invalid resource provided to ' . __CLASS__);
}
return $this;
}
/**
* Set parameter container
*
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* @return ParameterContainer
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
/**
* @param $resource
* @return self Provides a fluent interface
*/
public function setResource($resource)
{
$this->resource = $resource;
return $this;
}
/**
* Get resource
*
* @return resource
*/
public function getResource()
{
return $this->resource;
}
/**
* @param string $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* Get sql
*
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* @param string $sql
* @param array $options
* @return self Provides a fluent interface
* @throws Exception\RuntimeException
*/
public function prepare($sql = null, array $options = [])
{
if ($this->isPrepared) {
throw new Exception\RuntimeException('Already prepared');
}
$sql = ($sql) ?: $this->sql;
$options = ($options) ?: $this->prepareOptions;
$pRef = &$this->parameterReferences;
for ($position = 0, $count = substr_count($sql, '?'); $position < $count; $position++) {
if (! isset($this->prepareParams[$position])) {
$pRef[$position] = [&$this->parameterReferenceValues[$position], SQLSRV_PARAM_IN, null, null];
} else {
$pRef[$position] = &$this->prepareParams[$position];
}
}
$this->resource = sqlsrv_prepare($this->sqlsrv, $sql, $pRef, $options);
$this->isPrepared = true;
return $this;
}
/**
* @return bool
*/
public function isPrepared()
{
return $this->isPrepared;
}
/**
* Execute
*
* @param null|array|ParameterContainer $parameters
* @throws Exception\RuntimeException
* @return Result
*/
public function execute($parameters = null)
{
/** END Standard ParameterContainer Merging Block */
if (! $this->isPrepared) {
$this->prepare();
}
/** START Standard ParameterContainer Merging Block */
if (! $this->parameterContainer instanceof ParameterContainer) {
if ($parameters instanceof ParameterContainer) {
$this->parameterContainer = $parameters;
$parameters = null;
} else {
$this->parameterContainer = new ParameterContainer();
}
}
if (is_array($parameters)) {
$this->parameterContainer->setFromArray($parameters);
}
if ($this->parameterContainer->count() > 0) {
$this->bindParametersFromContainer();
}
if ($this->profiler) {
$this->profiler->profilerStart($this);
}
$resultValue = sqlsrv_execute($this->resource);
if ($this->profiler) {
$this->profiler->profilerFinish();
}
if ($resultValue === false) {
$errors = sqlsrv_errors();
// ignore general warnings
if ($errors[0]['SQLSTATE'] != '01000') {
throw new Exception\RuntimeException($errors[0]['message']);
}
}
$result = $this->driver->createResult($this->resource);
return $result;
}
/**
* Bind parameters from container
*
*/
protected function bindParametersFromContainer()
{
$values = $this->parameterContainer->getPositionalArray();
$position = 0;
foreach ($values as $value) {
$this->parameterReferences[$position++][0] = $value;
}
}
/**
* @param array $prepareParams
*/
public function setPrepareParams(array $prepareParams)
{
$this->prepareParams = $prepareParams;
}
/**
* @param array $prepareOptions
*/
public function setPrepareOptions(array $prepareOptions)
{
$this->prepareOptions = $prepareOptions;
}
}

View File

@ -1,45 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Driver;
use Zend\Db\Adapter\ParameterContainer;
use Zend\Db\Adapter\StatementContainerInterface;
interface StatementInterface extends StatementContainerInterface
{
/**
* Get resource
*
* @return resource
*/
public function getResource();
/**
* Prepare sql
*
* @param string $sql
*/
public function prepare($sql = null);
/**
* Check if is prepared
*
* @return bool
*/
public function isPrepared();
/**
* Execute
*
* @param null|array|ParameterContainer $parameters
* @return ResultInterface
*/
public function execute($parameters = null);
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
use Zend\Db\Exception;
class ErrorException extends Exception\ErrorException implements ExceptionInterface
{
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
use Zend\Db\Exception;
interface ExceptionInterface extends Exception\ExceptionInterface
{
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
use Zend\Db\Exception;
class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface
{
}

View File

@ -1,28 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
class InvalidConnectionParametersException extends RuntimeException implements ExceptionInterface
{
/**
* @var int
*/
protected $parameters;
/**
* @param string $message
* @param int $parameters
*/
public function __construct($message, $parameters)
{
parent::__construct($message);
$this->parameters = $parameters;
}
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
class InvalidQueryException extends UnexpectedValueException implements ExceptionInterface
{
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
use Zend\Db\Exception;
class RuntimeException extends Exception\RuntimeException implements ExceptionInterface
{
}

View File

@ -1,16 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Exception;
use Zend\Db\Exception;
class UnexpectedValueException extends Exception\UnexpectedValueException implements ExceptionInterface
{
}

View File

@ -1,422 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
use ArrayAccess;
use Countable;
use Iterator;
class ParameterContainer implements Iterator, ArrayAccess, Countable
{
const TYPE_AUTO = 'auto';
const TYPE_NULL = 'null';
const TYPE_DOUBLE = 'double';
const TYPE_INTEGER = 'integer';
const TYPE_BINARY = 'binary';
const TYPE_STRING = 'string';
const TYPE_LOB = 'lob';
/**
* Data
*
* @var array
*/
protected $data = [];
/**
* @var array
*/
protected $positions = [];
/**
* Errata
*
* @var array
*/
protected $errata = [];
/**
* Max length
*
* @var array
*/
protected $maxLength = [];
/**
* Constructor
*
* @param array $data
*/
public function __construct(array $data = [])
{
if ($data) {
$this->setFromArray($data);
}
}
/**
* Offset exists
*
* @param string $name
* @return bool
*/
public function offsetExists($name)
{
return (isset($this->data[$name]));
}
/**
* Offset get
*
* @param string $name
* @return mixed
*/
public function offsetGet($name)
{
return (isset($this->data[$name])) ? $this->data[$name] : null;
}
/**
* @param $name
* @param $from
*/
public function offsetSetReference($name, $from)
{
$this->data[$name] =& $this->data[$from];
}
/**
* Offset set
*
* @param string|int $name
* @param mixed $value
* @param mixed $errata
* @param mixed $maxLength
* @throws Exception\InvalidArgumentException
*/
public function offsetSet($name, $value, $errata = null, $maxLength = null)
{
$position = false;
// if integer, get name for this position
if (is_int($name)) {
if (isset($this->positions[$name])) {
$position = $name;
$name = $this->positions[$name];
} else {
$name = (string) $name;
}
} elseif (is_string($name)) {
// is a string:
$position = array_key_exists($name, $this->data);
} elseif ($name === null) {
$name = (string) count($this->data);
} else {
throw new Exception\InvalidArgumentException('Keys must be string, integer or null');
}
if ($position === false) {
$this->positions[] = $name;
}
$this->data[$name] = $value;
if ($errata) {
$this->offsetSetErrata($name, $errata);
}
if ($maxLength) {
$this->offsetSetMaxLength($name, $maxLength);
}
}
/**
* Offset unset
*
* @param string $name
* @return self Provides a fluent interface
*/
public function offsetUnset($name)
{
if (is_int($name) && isset($this->positions[$name])) {
$name = $this->positions[$name];
}
unset($this->data[$name]);
return $this;
}
/**
* Set from array
*
* @param array $data
* @return self Provides a fluent interface
*/
public function setFromArray(array $data)
{
foreach ($data as $n => $v) {
$this->offsetSet($n, $v);
}
return $this;
}
/**
* Offset set max length
*
* @param string|int $name
* @param mixed $maxLength
*/
public function offsetSetMaxLength($name, $maxLength)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
$this->maxLength[$name] = $maxLength;
}
/**
* Offset get max length
*
* @param string|int $name
* @throws Exception\InvalidArgumentException
* @return mixed
*/
public function offsetGetMaxLength($name)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
if (! array_key_exists($name, $this->data)) {
throw new Exception\InvalidArgumentException('Data does not exist for this name/position');
}
return $this->maxLength[$name];
}
/**
* Offset has max length
*
* @param string|int $name
* @return bool
*/
public function offsetHasMaxLength($name)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
return (isset($this->maxLength[$name]));
}
/**
* Offset unset max length
*
* @param string|int $name
* @throws Exception\InvalidArgumentException
*/
public function offsetUnsetMaxLength($name)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
if (! array_key_exists($name, $this->maxLength)) {
throw new Exception\InvalidArgumentException('Data does not exist for this name/position');
}
$this->maxLength[$name] = null;
}
/**
* Get max length iterator
*
* @return \ArrayIterator
*/
public function getMaxLengthIterator()
{
return new \ArrayIterator($this->maxLength);
}
/**
* Offset set errata
*
* @param string|int $name
* @param mixed $errata
*/
public function offsetSetErrata($name, $errata)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
$this->errata[$name] = $errata;
}
/**
* Offset get errata
*
* @param string|int $name
* @throws Exception\InvalidArgumentException
* @return mixed
*/
public function offsetGetErrata($name)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
if (! array_key_exists($name, $this->data)) {
throw new Exception\InvalidArgumentException('Data does not exist for this name/position');
}
return $this->errata[$name];
}
/**
* Offset has errata
*
* @param string|int $name
* @return bool
*/
public function offsetHasErrata($name)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
return (isset($this->errata[$name]));
}
/**
* Offset unset errata
*
* @param string|int $name
* @throws Exception\InvalidArgumentException
*/
public function offsetUnsetErrata($name)
{
if (is_int($name)) {
$name = $this->positions[$name];
}
if (! array_key_exists($name, $this->errata)) {
throw new Exception\InvalidArgumentException('Data does not exist for this name/position');
}
$this->errata[$name] = null;
}
/**
* Get errata iterator
*
* @return \ArrayIterator
*/
public function getErrataIterator()
{
return new \ArrayIterator($this->errata);
}
/**
* getNamedArray
*
* @return array
*/
public function getNamedArray()
{
return $this->data;
}
/**
* getNamedArray
*
* @return array
*/
public function getPositionalArray()
{
return array_values($this->data);
}
/**
* count
*
* @return int
*/
public function count()
{
return count($this->data);
}
/**
* Current
*
* @return mixed
*/
public function current()
{
return current($this->data);
}
/**
* Next
*
* @return mixed
*/
public function next()
{
return next($this->data);
}
/**
* Key
*
* @return mixed
*/
public function key()
{
return key($this->data);
}
/**
* Valid
*
* @return bool
*/
public function valid()
{
return (current($this->data) !== false);
}
/**
* Rewind
*/
public function rewind()
{
reset($this->data);
}
/**
* @param array|ParameterContainer $parameters
* @return self Provides a fluent interface
* @throws Exception\InvalidArgumentException
*/
public function merge($parameters)
{
if (! is_array($parameters) && ! $parameters instanceof ParameterContainer) {
throw new Exception\InvalidArgumentException(
'$parameters must be an array or an instance of ParameterContainer'
);
}
if (count($parameters) == 0) {
return $this;
}
if ($parameters instanceof ParameterContainer) {
$parameters = $parameters->getNamedArray();
}
foreach ($parameters as $key => $value) {
if (is_int($key)) {
$key = null;
}
$this->offsetSet($key, $value);
}
return $this;
}
}

View File

@ -1,142 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
abstract class AbstractPlatform implements PlatformInterface
{
/**
* @var string[]
*/
protected $quoteIdentifier = ['"', '"'];
/**
* @var string
*/
protected $quoteIdentifierTo = '\'';
/**
* @var bool
*/
protected $quoteIdentifiers = true;
/**
* @var string
*/
protected $quoteIdentifierFragmentPattern = '/([^0-9,a-z,A-Z$_:])/i';
/**
* {@inheritDoc}
*/
public function quoteIdentifierInFragment($identifier, array $safeWords = [])
{
if (! $this->quoteIdentifiers) {
return $identifier;
}
$safeWordsInt = ['*' => true, ' ' => true, '.' => true, 'as' => true];
foreach ($safeWords as $sWord) {
$safeWordsInt[strtolower($sWord)] = true;
}
$parts = preg_split(
$this->quoteIdentifierFragmentPattern,
$identifier,
-1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
$identifier = '';
foreach ($parts as $part) {
$identifier .= isset($safeWordsInt[strtolower($part)])
? $part
: $this->quoteIdentifier[0]
. str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $part)
. $this->quoteIdentifier[1];
}
return $identifier;
}
/**
* {@inheritDoc}
*/
public function quoteIdentifier($identifier)
{
if (! $this->quoteIdentifiers) {
return $identifier;
}
return $this->quoteIdentifier[0]
. str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $identifier)
. $this->quoteIdentifier[1];
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"';
}
/**
* {@inheritDoc}
*/
public function getQuoteIdentifierSymbol()
{
return $this->quoteIdentifier[0];
}
/**
* {@inheritDoc}
*/
public function getQuoteValueSymbol()
{
return '\'';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
trigger_error(
'Attempting to quote a value in ' . get_class($this) .
' without extension/driver support can introduce security vulnerabilities in a production environment'
);
return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\'';
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
return '\'' . addcslashes((string) $value, "\x00\n\r\\'\"\x1a") . '\'';
}
/**
* {@inheritDoc}
*/
public function quoteValueList($valueList)
{
return implode(', ', array_map([$this, 'quoteValue'], (array) $valueList));
}
/**
* {@inheritDoc}
*/
public function getIdentifierSeparator()
{
return '.';
}
}

View File

@ -1,125 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
class IbmDb2 extends AbstractPlatform
{
/**
* @var string
*/
protected $identifierSeparator = '.';
/**
* @param array $options
*/
public function __construct($options = [])
{
if (isset($options['quote_identifiers'])
&& ($options['quote_identifiers'] == false
|| $options['quote_identifiers'] === 'false')
) {
$this->quoteIdentifiers = false;
}
if (isset($options['identifier_separator'])) {
$this->identifierSeparator = $options['identifier_separator'];
}
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'IBM DB2';
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierInFragment($identifier, array $safeWords = [])
{
if (! $this->quoteIdentifiers) {
return $identifier;
}
$safeWordsInt = ['*' => true, ' ' => true, '.' => true, 'as' => true];
foreach ($safeWords as $sWord) {
$safeWordsInt[strtolower($sWord)] = true;
}
$parts = preg_split(
'/([^0-9,a-z,A-Z$#_:])/i',
$identifier,
-1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
);
$identifier = '';
foreach ($parts as $part) {
$identifier .= isset($safeWordsInt[strtolower($part)])
? $part
: $this->quoteIdentifier[0]
. str_replace($this->quoteIdentifier[0], $this->quoteIdentifierTo, $part)
. $this->quoteIdentifier[1];
}
return $identifier;
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
if ($this->quoteIdentifiers === false) {
if (is_array($identifierChain)) {
return implode($this->identifierSeparator, $identifierChain);
} else {
return $identifierChain;
}
}
$identifierChain = str_replace('"', '\\"', $identifierChain);
if (is_array($identifierChain)) {
$identifierChain = implode('"' . $this->identifierSeparator . '"', $identifierChain);
}
return '"' . $identifierChain . '"';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
if (function_exists('db2_escape_string')) {
return '\'' . db2_escape_string($value) . '\'';
}
trigger_error(
'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support '
. 'can introduce security vulnerabilities in a production environment.'
);
return '\'' . str_replace("'", "''", $value) . '\'';
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
if (function_exists('db2_escape_string')) {
return '\'' . db2_escape_string($value) . '\'';
}
return '\'' . str_replace("'", "''", $value) . '\'';
}
/**
* {@inheritDoc}
*/
public function getIdentifierSeparator()
{
return $this->identifierSeparator;
}
}

View File

@ -1,122 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Mysqli;
use Zend\Db\Adapter\Driver\Pdo;
use Zend\Db\Adapter\Exception;
class Mysql extends AbstractPlatform
{
/**
* {@inheritDoc}
*/
protected $quoteIdentifier = ['`', '`'];
/**
* {@inheritDoc}
*/
protected $quoteIdentifierTo = '``';
/**
* @var \mysqli|\PDO
*/
protected $resource = null;
/**
* NOTE: Include dashes for MySQL only, need tests for others platforms
*
* @var string
*/
protected $quoteIdentifierFragmentPattern = '/([^0-9,a-z,A-Z$_\-:])/i';
/**
* @param null|\Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo|\mysqli|\PDO $driver
*/
public function __construct($driver = null)
{
if ($driver) {
$this->setDriver($driver);
}
}
/**
* @param \Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo|\mysqli|\PDO $driver
* @return self Provides a fluent interface
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function setDriver($driver)
{
// handle Zend\Db drivers
if ($driver instanceof Mysqli\Mysqli
|| ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Mysql')
|| ($driver instanceof \mysqli)
|| ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql')
) {
$this->resource = $driver;
return $this;
}
throw new Exception\InvalidArgumentException(
'$driver must be a Mysqli or Mysql PDO Zend\Db\Adapter\Driver, Mysqli instance or MySQL PDO instance'
);
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'MySQL';
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '`' . implode('`.`', (array) str_replace('`', '``', $identifierChain)) . '`';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if ($this->resource instanceof \mysqli) {
return '\'' . $this->resource->real_escape_string($value) . '\'';
}
if ($this->resource instanceof \PDO) {
return $this->resource->quote($value);
}
return parent::quoteValue($value);
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if ($this->resource instanceof \mysqli) {
return '\'' . $this->resource->real_escape_string($value) . '\'';
}
if ($this->resource instanceof \PDO) {
return $this->resource->quote($value);
}
return parent::quoteTrustedValue($value);
}
}

View File

@ -1,129 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Oci8\Oci8;
use Zend\Db\Adapter\Driver\Pdo\Pdo;
use \Zend\Db\Adapter\Exception\InvalidArgumentException;
class Oracle extends AbstractPlatform
{
/**
* @var null|Pdo|Oci8
*/
protected $resource = null;
/**
* @param array $options
* @param null|Oci8|Pdo $driver
*/
public function __construct($options = [], $driver = null)
{
if (isset($options['quote_identifiers'])
&& ($options['quote_identifiers'] == false
|| $options['quote_identifiers'] === 'false')
) {
$this->quoteIdentifiers = false;
}
if ($driver) {
$this->setDriver($driver);
}
}
/**
* @param Pdo|Oci8 $driver
* @return self Provides a fluent interface
* @throws InvalidArgumentException
*/
public function setDriver($driver)
{
if ($driver instanceof Oci8
|| ($driver instanceof Pdo && $driver->getDatabasePlatformName() == 'Oracle')
|| ($driver instanceof Pdo && $driver->getDatabasePlatformName() == 'Sqlite')
|| ($driver instanceof \oci8)
|| ($driver instanceof PDO && $driver->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci')
) {
$this->resource = $driver;
return $this;
}
throw new InvalidArgumentException(
'$driver must be a Oci8 or Oracle PDO Zend\Db\Adapter\Driver, '
. 'Oci8 instance, or Oci PDO instance'
);
}
/**
* @return null|Pdo|Oci8
*/
public function getDriver()
{
return $this->resource;
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'Oracle';
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
if ($this->quoteIdentifiers === false) {
return implode('.', (array) $identifierChain);
}
return '"' . implode('"."', (array) str_replace('"', '\\"', $identifierChain)) . '"';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if ($this->resource) {
if ($this->resource instanceof PDO) {
return $this->resource->quote($value);
}
if (get_resource_type($this->resource) == 'oci8 connection'
|| get_resource_type($this->resource) == 'oci8 persistent connection'
) {
return "'" . addcslashes(str_replace("'", "''", $value), "\x00\n\r\"\x1a") . "'";
}
}
trigger_error(
'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support '
. 'can introduce security vulnerabilities in a production environment.'
);
return "'" . addcslashes(str_replace("'", "''", $value), "\x00\n\r\"\x1a") . "'";
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
return "'" . addcslashes(str_replace('\'', '\'\'', $value), "\x00\n\r\"\x1a") . "'";
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
interface PlatformInterface
{
/**
* Get name
*
* @return string
*/
public function getName();
/**
* Get quote identifier symbol
*
* @return string
*/
public function getQuoteIdentifierSymbol();
/**
* Quote identifier
*
* @param string $identifier
* @return string
*/
public function quoteIdentifier($identifier);
/**
* Quote identifier chain
*
* @param string|string[] $identifierChain
* @return string
*/
public function quoteIdentifierChain($identifierChain);
/**
* Get quote value symbol
*
* @return string
*/
public function getQuoteValueSymbol();
/**
* Quote value
*
* Will throw a notice when used in a workflow that can be considered "unsafe"
*
* @param string $value
* @return string
*/
public function quoteValue($value);
/**
* Quote Trusted Value
*
* The ability to quote values without notices
*
* @param $value
* @return mixed
*/
public function quoteTrustedValue($value);
/**
* Quote value list
*
* @param string|string[] $valueList
* @return string
*/
public function quoteValueList($valueList);
/**
* Get identifier separator
*
* @return string
*/
public function getIdentifierSeparator();
/**
* Quote identifier in fragment
*
* @param string $identifier
* @param array $additionalSafeWords
* @return string
*/
public function quoteIdentifierInFragment($identifier, array $additionalSafeWords = []);
}

View File

@ -1,112 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Pdo;
use Zend\Db\Adapter\Driver\Pgsql;
use Zend\Db\Adapter\Exception;
class Postgresql extends AbstractPlatform
{
/**
* Overrides value from AbstractPlatform to use proper escaping for Postgres
*
* @var string
*/
protected $quoteIdentifierTo = '""';
/**
* @var resource|\PDO
*/
protected $resource = null;
/**
* @param null|\Zend\Db\Adapter\Driver\Pgsql\Pgsql|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver
*/
public function __construct($driver = null)
{
if ($driver) {
$this->setDriver($driver);
}
}
/**
* @param \Zend\Db\Adapter\Driver\Pgsql\Pgsql|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver
* @return self Provides a fluent interface
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function setDriver($driver)
{
if ($driver instanceof Pgsql\Pgsql
|| ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Postgresql')
|| (is_resource($driver) && (in_array(get_resource_type($driver), ['pgsql link', 'pgsql link persistent'])))
|| ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql')
) {
$this->resource = $driver;
return $this;
}
throw new Exception\InvalidArgumentException(
'$driver must be a Pgsql or Postgresql PDO Zend\Db\Adapter\Driver, pgsql link resource or Postgresql PDO '
. 'instance'
);
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'PostgreSQL';
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '"' . implode('"."', (array) str_replace('"', '""', $identifierChain)) . '"';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if (is_resource($this->resource)) {
return '\'' . pg_escape_string($this->resource, $value) . '\'';
}
if ($this->resource instanceof \PDO) {
return $this->resource->quote($value);
}
return 'E' . parent::quoteValue($value);
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if (is_resource($this->resource)) {
return '\'' . pg_escape_string($this->resource, $value) . '\'';
}
if ($this->resource instanceof \PDO) {
return $this->resource->quote($value);
}
return 'E' . parent::quoteTrustedValue($value);
}
}

View File

@ -1,33 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
class Sql92 extends AbstractPlatform
{
/**
* {@inheritDoc}
*/
public function getName()
{
return 'SQL92';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
trigger_error(
'Attempting to quote a value without specific driver level support'
. ' can introduce security vulnerabilities in a production environment.'
);
return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
}
}

View File

@ -1,119 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Pdo;
use Zend\Db\Adapter\Exception;
class SqlServer extends AbstractPlatform
{
/**
* {@inheritDoc}
*/
protected $quoteIdentifier = ['[',']'];
/**
* {@inheritDoc}
*/
protected $quoteIdentifierTo = '\\';
/**
* @var resource|\PDO
*/
protected $resource = null;
/**
* @param null|\Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver
*/
public function __construct($driver = null)
{
if ($driver) {
$this->setDriver($driver);
}
}
/**
* @param \Zend\Db\Adapter\Driver\Sqlsrv\Sqlsrv|\Zend\Db\Adapter\Driver\Pdo\Pdo|resource|\PDO $driver
* @return self Provides a fluent interface
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function setDriver($driver)
{
// handle Zend\Db drivers
if (($driver instanceof Pdo\Pdo && in_array($driver->getDatabasePlatformName(), ['SqlServer', 'Dblib']))
|| ($driver instanceof \PDO && in_array($driver->getAttribute(\PDO::ATTR_DRIVER_NAME), ['sqlsrv', 'dblib']))
) {
$this->resource = $driver;
return $this;
}
throw new Exception\InvalidArgumentException(
'$driver must be a Sqlsrv PDO Zend\Db\Adapter\Driver or Sqlsrv PDO instance'
);
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'SQLServer';
}
/**
* {@inheritDoc}
*/
public function getQuoteIdentifierSymbol()
{
return $this->quoteIdentifier;
}
/**
* {@inheritDoc}
*/
public function quoteIdentifierChain($identifierChain)
{
return '[' . implode('].[', (array) $identifierChain) . ']';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if ($this->resource instanceof \PDO) {
return $this->resource->quote($value);
}
trigger_error(
'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support '
. 'can introduce security vulnerabilities in a production environment.'
);
return '\'' . str_replace('\'', '\'\'', addcslashes($value, "\000\032")) . '\'';
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
if ($this->resource instanceof DriverInterface) {
$this->resource = $this->resource->getConnection()->getResource();
}
if ($this->resource instanceof \PDO) {
return $this->resource->quote($value);
}
return '\'' . str_replace('\'', '\'\'', $value) . '\'';
}
}

View File

@ -1,105 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Platform;
use Zend\Db\Adapter\Driver\DriverInterface;
use Zend\Db\Adapter\Driver\Pdo;
use Zend\Db\Adapter\Exception;
class Sqlite extends AbstractPlatform
{
/**
* {@inheritDoc}
*/
protected $quoteIdentifier = ['"','"'];
/**
* {@inheritDoc}
*/
protected $quoteIdentifierTo = '\'';
/**
* @var \PDO
*/
protected $resource = null;
/**
* @param null|\Zend\Db\Adapter\Driver\Pdo\Pdo||\PDO $driver
*/
public function __construct($driver = null)
{
if ($driver) {
$this->setDriver($driver);
}
}
/**
* @param \Zend\Db\Adapter\Driver\Pdo\Pdo|\PDO $driver
* @return self Provides a fluent interface
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function setDriver($driver)
{
if (($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'sqlite')
|| ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Sqlite')
) {
$this->resource = $driver;
return $this;
}
throw new Exception\InvalidArgumentException(
'$driver must be a Sqlite PDO Zend\Db\Adapter\Driver, Sqlite PDO instance'
);
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'SQLite';
}
/**
* {@inheritDoc}
*/
public function quoteValue($value)
{
$resource = $this->resource;
if ($resource instanceof DriverInterface) {
$resource = $resource->getConnection()->getResource();
}
if ($resource instanceof \PDO) {
return $resource->quote($value);
}
return parent::quoteValue($value);
}
/**
* {@inheritDoc}
*/
public function quoteTrustedValue($value)
{
$resource = $this->resource;
if ($resource instanceof DriverInterface) {
$resource = $resource->getConnection()->getResource();
}
if ($resource instanceof \PDO) {
return $resource->quote($value);
}
return parent::quoteTrustedValue($value);
}
}

View File

@ -1,89 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Profiler;
use Zend\Db\Adapter\StatementContainerInterface;
use Zend\Db\Adapter\Exception;
class Profiler implements ProfilerInterface
{
/**
* @var array
*/
protected $profiles = [];
/**
* @var null
*/
protected $currentIndex = 0;
/**
* @param string|StatementContainerInterface $target
* @return self Provides a fluent interface
* @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
*/
public function profilerStart($target)
{
$profileInformation = [
'sql' => '',
'parameters' => null,
'start' => microtime(true),
'end' => null,
'elapse' => null
];
if ($target instanceof StatementContainerInterface) {
$profileInformation['sql'] = $target->getSql();
$profileInformation['parameters'] = clone $target->getParameterContainer();
} elseif (is_string($target)) {
$profileInformation['sql'] = $target;
} else {
throw new Exception\InvalidArgumentException(
__FUNCTION__ . ' takes either a StatementContainer or a string'
);
}
$this->profiles[$this->currentIndex] = $profileInformation;
return $this;
}
/**
* @return self Provides a fluent interface
*/
public function profilerFinish()
{
if (! isset($this->profiles[$this->currentIndex])) {
throw new Exception\RuntimeException(
'A profile must be started before ' . __FUNCTION__ . ' can be called.'
);
}
$current = &$this->profiles[$this->currentIndex];
$current['end'] = microtime(true);
$current['elapse'] = $current['end'] - $current['start'];
$this->currentIndex++;
return $this;
}
/**
* @return array|null
*/
public function getLastProfile()
{
return end($this->profiles);
}
/**
* @return array
*/
public function getProfiles()
{
return $this->profiles;
}
}

View File

@ -1,18 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Profiler;
interface ProfilerAwareInterface
{
/**
* @param ProfilerInterface $profiler
*/
public function setProfiler(ProfilerInterface $profiler);
}

View File

@ -1,20 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter\Profiler;
interface ProfilerInterface
{
/**
* @param string|\Zend\Db\Adapter\StatementContainerInterface $target
* @return mixed
*/
public function profilerStart($target);
public function profilerFinish();
}

View File

@ -1,71 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
class StatementContainer implements StatementContainerInterface
{
/**
* @var string
*/
protected $sql = '';
/**
* @var ParameterContainer
*/
protected $parameterContainer = null;
/**
* @param string|null $sql
* @param ParameterContainer|null $parameterContainer
*/
public function __construct($sql = null, ParameterContainer $parameterContainer = null)
{
if ($sql) {
$this->setSql($sql);
}
$this->parameterContainer = ($parameterContainer) ?: new ParameterContainer;
}
/**
* @param $sql
* @return self Provides a fluent interface
*/
public function setSql($sql)
{
$this->sql = $sql;
return $this;
}
/**
* @return string
*/
public function getSql()
{
return $this->sql;
}
/**
* @param ParameterContainer $parameterContainer
* @return self Provides a fluent interface
*/
public function setParameterContainer(ParameterContainer $parameterContainer)
{
$this->parameterContainer = $parameterContainer;
return $this;
}
/**
* @return null|ParameterContainer
*/
public function getParameterContainer()
{
return $this->parameterContainer;
}
}

View File

@ -1,43 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Adapter;
interface StatementContainerInterface
{
/**
* Set sql
*
* @param $sql
* @return mixed
*/
public function setSql($sql);
/**
* Get sql
*
* @return mixed
*/
public function getSql();
/**
* Set parameter container
*
* @param ParameterContainer $parameterContainer
* @return mixed
*/
public function setParameterContainer(ParameterContainer $parameterContainer);
/**
* Get parameter container
*
* @return mixed
*/
public function getParameterContainer();
}

View File

@ -1,43 +0,0 @@
<?php
/**
* @link http://github.com/zendframework/zend-db for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db;
class ConfigProvider
{
/**
* Retrieve zend-db default configuration.
*
* @return array
*/
public function __invoke()
{
return [
'dependencies' => $this->getDependencyConfig(),
];
}
/**
* Retrieve zend-db default dependency configuration.
*
* @return array
*/
public function getDependencyConfig()
{
return [
'abstract_factories' => [
Adapter\AdapterAbstractServiceFactory::class,
],
'factories' => [
Adapter\AdapterInterface::class => Adapter\AdapterServiceFactory::class,
],
'aliases' => [
Adapter\Adapter::class => Adapter\AdapterInterface::class,
],
];
}
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Exception;
class ErrorException extends \Exception implements ExceptionInterface
{
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Exception;
interface ExceptionInterface
{
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Exception;
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Exception;
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Exception;
class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface
{
}

View File

@ -1,161 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata;
use Zend\Db\Adapter\Adapter;
/**
* @deprecated Use Zend\Db\Metadata\Source\Factory::createSourceFromAdapter($adapter)
*/
class Metadata implements MetadataInterface
{
/**
* @var MetadataInterface
*/
protected $source = null;
/**
* Constructor
*
* @param Adapter $adapter
*/
public function __construct(Adapter $adapter)
{
$this->source = Source\Factory::createSourceFromAdapter($adapter);
}
/**
* {@inheritdoc}
*/
public function getTables($schema = null, $includeViews = false)
{
return $this->source->getTables($schema, $includeViews);
}
/**
* {@inheritdoc}
*/
public function getViews($schema = null)
{
return $this->source->getViews($schema);
}
/**
* {@inheritdoc}
*/
public function getTriggers($schema = null)
{
return $this->source->getTriggers($schema);
}
/**
* {@inheritdoc}
*/
public function getConstraints($table, $schema = null)
{
return $this->source->getConstraints($table, $schema);
}
/**
* {@inheritdoc}
*/
public function getColumns($table, $schema = null)
{
return $this->source->getColumns($table, $schema);
}
/**
* {@inheritdoc}
*/
public function getConstraintKeys($constraint, $table, $schema = null)
{
return $this->source->getConstraintKeys($constraint, $table, $schema);
}
/**
* {@inheritdoc}
*/
public function getConstraint($constraintName, $table, $schema = null)
{
return $this->source->getConstraint($constraintName, $table, $schema);
}
/**
* {@inheritdoc}
*/
public function getSchemas()
{
return $this->source->getSchemas();
}
/**
* {@inheritdoc}
*/
public function getTableNames($schema = null, $includeViews = false)
{
return $this->source->getTableNames($schema, $includeViews);
}
/**
* {@inheritdoc}
*/
public function getTable($tableName, $schema = null)
{
return $this->source->getTable($tableName, $schema);
}
/**
* {@inheritdoc}
*/
public function getViewNames($schema = null)
{
return $this->source->getViewNames($schema);
}
/**
* {@inheritdoc}
*/
public function getView($viewName, $schema = null)
{
return $this->source->getView($viewName, $schema);
}
/**
* {@inheritdoc}
*/
public function getTriggerNames($schema = null)
{
return $this->source->getTriggerNames($schema);
}
/**
* {@inheritdoc}
*/
public function getTrigger($triggerName, $schema = null)
{
return $this->source->getTrigger($triggerName, $schema);
}
/**
* {@inheritdoc}
*/
public function getColumnNames($table, $schema = null)
{
return $this->source->getColumnNames($table, $schema);
}
/**
* {@inheritdoc}
*/
public function getColumn($columnName, $table, $schema = null)
{
return $this->source->getColumn($columnName, $table, $schema);
}
}

View File

@ -1,154 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata;
interface MetadataInterface
{
/**
* Get schemas.
*
* @return string[]
*/
public function getSchemas();
/**
* Get table names.
*
* @param null|string $schema
* @param bool $includeViews
* @return string[]
*/
public function getTableNames($schema = null, $includeViews = false);
/**
* Get tables.
*
* @param null|string $schema
* @param bool $includeViews
* @return Object\TableObject[]
*/
public function getTables($schema = null, $includeViews = false);
/**
* Get table
*
* @param string $tableName
* @param null|string $schema
* @return Object\TableObject
*/
public function getTable($tableName, $schema = null);
/**
* Get view names
*
* @param null|string $schema
* @return string[]
*/
public function getViewNames($schema = null);
/**
* Get views
*
* @param null|string $schema
* @return Object\ViewObject[]
*/
public function getViews($schema = null);
/**
* Get view
*
* @param string $viewName
* @param null|string $schema
* @return Object\ViewObject
*/
public function getView($viewName, $schema = null);
/**
* Get column names
*
* @param string $table
* @param null|string $schema
* @return string[]
*/
public function getColumnNames($table, $schema = null);
/**
* Get columns
*
* @param string $table
* @param null|string $schema
* @return Object\ColumnObject[]
*/
public function getColumns($table, $schema = null);
/**
* Get column
*
* @param string $columnName
* @param string $table
* @param null|string $schema
* @return Object\ColumnObject
*/
public function getColumn($columnName, $table, $schema = null);
/**
* Get constraints
*
* @param string $table
* @param null|string $schema
* @return Object\ConstraintObject[]
*/
public function getConstraints($table, $schema = null);
/**
* Get constraint
*
* @param string $constraintName
* @param string $table
* @param null|string $schema
* @return Object\ConstraintObject
*/
public function getConstraint($constraintName, $table, $schema = null);
/**
* Get constraint keys
*
* @param string $constraint
* @param string $table
* @param null|string $schema
* @return Object\ConstraintKeyObject[]
*/
public function getConstraintKeys($constraint, $table, $schema = null);
/**
* Get trigger names
*
* @param null|string $schema
* @return string[]
*/
public function getTriggerNames($schema = null);
/**
* Get triggers
*
* @param null|string $schema
* @return Object\TriggerObject[]
*/
public function getTriggers($schema = null);
/**
* Get trigger
*
* @param string $triggerName
* @param null|string $schema
* @return Object\TriggerObject
*/
public function getTrigger($triggerName, $schema = null);
}

View File

@ -1,114 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata\Object;
abstract class AbstractTableObject
{
/*
protected $catalogName = null;
protected $schemaName = null;
*/
/**
*
* @var string
*/
protected $name = null;
/**
*
* @var string
*/
protected $type = null;
/**
*
* @var array
*/
protected $columns = null;
/**
*
* @var array
*/
protected $constraints = null;
/**
* Constructor
*
* @param string $name
*/
public function __construct($name)
{
if ($name) {
$this->setName($name);
}
}
/**
* Set columns
*
* @param array $columns
*/
public function setColumns(array $columns)
{
$this->columns = $columns;
}
/**
* Get columns
*
* @return array
*/
public function getColumns()
{
return $this->columns;
}
/**
* Set constraints
*
* @param array $constraints
*/
public function setConstraints($constraints)
{
$this->constraints = $constraints;
}
/**
* Get constraints
*
* @return array
*/
public function getConstraints()
{
return $this->constraints;
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
}

View File

@ -1,388 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata\Object;
class ColumnObject
{
/**
*
* @var string
*/
protected $name = null;
/**
*
* @var string
*/
protected $tableName = null;
/**
*
* @var string
*/
protected $schemaName = null;
/**
*
* @var
*/
protected $ordinalPosition = null;
/**
*
* @var string
*/
protected $columnDefault = null;
/**
*
* @var bool
*/
protected $isNullable = null;
/**
*
* @var string
*/
protected $dataType = null;
/**
*
* @var int
*/
protected $characterMaximumLength = null;
/**
*
* @var int
*/
protected $characterOctetLength = null;
/**
*
* @var int
*/
protected $numericPrecision = null;
/**
*
* @var int
*/
protected $numericScale = null;
/**
*
* @var bool
*/
protected $numericUnsigned = null;
/**
*
* @var array
*/
protected $errata = [];
/**
* Constructor
*
* @param string $name
* @param string $tableName
* @param string $schemaName
*/
public function __construct($name, $tableName, $schemaName = null)
{
$this->setName($name);
$this->setTableName($tableName);
$this->setSchemaName($schemaName);
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get table name
*
* @return string
*/
public function getTableName()
{
return $this->tableName;
}
/**
* Set table name
*
* @param string $tableName
* @return self Provides a fluent interface
*/
public function setTableName($tableName)
{
$this->tableName = $tableName;
return $this;
}
/**
* Set schema name
*
* @param string $schemaName
*/
public function setSchemaName($schemaName)
{
$this->schemaName = $schemaName;
}
/**
* Get schema name
*
* @return string
*/
public function getSchemaName()
{
return $this->schemaName;
}
/**
* @return int $ordinalPosition
*/
public function getOrdinalPosition()
{
return $this->ordinalPosition;
}
/**
* @param int $ordinalPosition to set
* @return self Provides a fluent interface
*/
public function setOrdinalPosition($ordinalPosition)
{
$this->ordinalPosition = $ordinalPosition;
return $this;
}
/**
* @return null|string the $columnDefault
*/
public function getColumnDefault()
{
return $this->columnDefault;
}
/**
* @param mixed $columnDefault to set
* @return self Provides a fluent interface
*/
public function setColumnDefault($columnDefault)
{
$this->columnDefault = $columnDefault;
return $this;
}
/**
* @return bool $isNullable
*/
public function getIsNullable()
{
return $this->isNullable;
}
/**
* @param bool $isNullable to set
* @return self Provides a fluent interface
*/
public function setIsNullable($isNullable)
{
$this->isNullable = $isNullable;
return $this;
}
/**
* @return bool $isNullable
*/
public function isNullable()
{
return $this->isNullable;
}
/**
* @return null|string the $dataType
*/
public function getDataType()
{
return $this->dataType;
}
/**
* @param string $dataType the $dataType to set
* @return self Provides a fluent interface
*/
public function setDataType($dataType)
{
$this->dataType = $dataType;
return $this;
}
/**
* @return int|null the $characterMaximumLength
*/
public function getCharacterMaximumLength()
{
return $this->characterMaximumLength;
}
/**
* @param int $characterMaximumLength the $characterMaximumLength to set
* @return self Provides a fluent interface
*/
public function setCharacterMaximumLength($characterMaximumLength)
{
$this->characterMaximumLength = $characterMaximumLength;
return $this;
}
/**
* @return int|null the $characterOctetLength
*/
public function getCharacterOctetLength()
{
return $this->characterOctetLength;
}
/**
* @param int $characterOctetLength the $characterOctetLength to set
* @return self Provides a fluent interface
*/
public function setCharacterOctetLength($characterOctetLength)
{
$this->characterOctetLength = $characterOctetLength;
return $this;
}
/**
* @return int the $numericPrecision
*/
public function getNumericPrecision()
{
return $this->numericPrecision;
}
/**
* @param int $numericPrecision the $numericPrevision to set
* @return self Provides a fluent interface
*/
public function setNumericPrecision($numericPrecision)
{
$this->numericPrecision = $numericPrecision;
return $this;
}
/**
* @return int the $numericScale
*/
public function getNumericScale()
{
return $this->numericScale;
}
/**
* @param int $numericScale the $numericScale to set
* @return self Provides a fluent interface
*/
public function setNumericScale($numericScale)
{
$this->numericScale = $numericScale;
return $this;
}
/**
* @return bool
*/
public function getNumericUnsigned()
{
return $this->numericUnsigned;
}
/**
* @param bool $numericUnsigned
* @return self Provides a fluent interface
*/
public function setNumericUnsigned($numericUnsigned)
{
$this->numericUnsigned = $numericUnsigned;
return $this;
}
/**
* @return bool
*/
public function isNumericUnsigned()
{
return $this->numericUnsigned;
}
/**
* @return array the $errata
*/
public function getErratas()
{
return $this->errata;
}
/**
* @param array $erratas
* @return self Provides a fluent interface
*/
public function setErratas(array $erratas)
{
foreach ($erratas as $name => $value) {
$this->setErrata($name, $value);
}
return $this;
}
/**
* @param string $errataName
* @return mixed
*/
public function getErrata($errataName)
{
if (array_key_exists($errataName, $this->errata)) {
return $this->errata[$errataName];
}
return;
}
/**
* @param string $errataName
* @param mixed $errataValue
* @return self Provides a fluent interface
*/
public function setErrata($errataName, $errataValue)
{
$this->errata[$errataName] = $errataValue;
return $this;
}
}

View File

@ -1,249 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata\Object;
class ConstraintKeyObject
{
const FK_CASCADE = 'CASCADE';
const FK_SET_NULL = 'SET NULL';
const FK_NO_ACTION = 'NO ACTION';
const FK_RESTRICT = 'RESTRICT';
const FK_SET_DEFAULT = 'SET DEFAULT';
/**
*
* @var string
*/
protected $columnName = null;
/**
*
* @var int
*/
protected $ordinalPosition = null;
/**
*
* @var bool
*/
protected $positionInUniqueConstraint = null;
/**
*
* @var string
*/
protected $referencedTableSchema = null;
/**
*
* @var string
*/
protected $referencedTableName = null;
/**
*
* @var string
*/
protected $referencedColumnName = null;
/**
*
* @var string
*/
protected $foreignKeyUpdateRule = null;
/**
*
* @var string
*/
protected $foreignKeyDeleteRule = null;
/**
* Constructor
*
* @param string $column
*/
public function __construct($column)
{
$this->setColumnName($column);
}
/**
* Get column name
*
* @return string
*/
public function getColumnName()
{
return $this->columnName;
}
/**
* Set column name
*
* @param string $columnName
* @return self Provides a fluent interface
*/
public function setColumnName($columnName)
{
$this->columnName = $columnName;
return $this;
}
/**
* Get ordinal position
*
* @return int
*/
public function getOrdinalPosition()
{
return $this->ordinalPosition;
}
/**
* Set ordinal position
*
* @param int $ordinalPosition
* @return self Provides a fluent interface
*/
public function setOrdinalPosition($ordinalPosition)
{
$this->ordinalPosition = $ordinalPosition;
return $this;
}
/**
* Get position in unique constraint
*
* @return bool
*/
public function getPositionInUniqueConstraint()
{
return $this->positionInUniqueConstraint;
}
/**
* Set position in unique constraint
*
* @param bool $positionInUniqueConstraint
* @return self Provides a fluent interface
*/
public function setPositionInUniqueConstraint($positionInUniqueConstraint)
{
$this->positionInUniqueConstraint = $positionInUniqueConstraint;
return $this;
}
/**
* Get referencred table schema
*
* @return string
*/
public function getReferencedTableSchema()
{
return $this->referencedTableSchema;
}
/**
* Set referenced table schema
*
* @param string $referencedTableSchema
* @return self Provides a fluent interface
*/
public function setReferencedTableSchema($referencedTableSchema)
{
$this->referencedTableSchema = $referencedTableSchema;
return $this;
}
/**
* Get referenced table name
*
* @return string
*/
public function getReferencedTableName()
{
return $this->referencedTableName;
}
/**
* Set Referenced table name
*
* @param string $referencedTableName
* @return self Provides a fluent interface
*/
public function setReferencedTableName($referencedTableName)
{
$this->referencedTableName = $referencedTableName;
return $this;
}
/**
* Get referenced column name
*
* @return string
*/
public function getReferencedColumnName()
{
return $this->referencedColumnName;
}
/**
* Set referenced column name
*
* @param string $referencedColumnName
* @return self Provides a fluent interface
*/
public function setReferencedColumnName($referencedColumnName)
{
$this->referencedColumnName = $referencedColumnName;
return $this;
}
/**
* set foreign key update rule
*
* @param string $foreignKeyUpdateRule
*/
public function setForeignKeyUpdateRule($foreignKeyUpdateRule)
{
$this->foreignKeyUpdateRule = $foreignKeyUpdateRule;
}
/**
* Get foreign key update rule
*
* @return string
*/
public function getForeignKeyUpdateRule()
{
return $this->foreignKeyUpdateRule;
}
/**
* Set foreign key delete rule
*
* @param string $foreignKeyDeleteRule
*/
public function setForeignKeyDeleteRule($foreignKeyDeleteRule)
{
$this->foreignKeyDeleteRule = $foreignKeyDeleteRule;
}
/**
* get foreign key delete rule
*
* @return string
*/
public function getForeignKeyDeleteRule()
{
return $this->foreignKeyDeleteRule;
}
}

View File

@ -1,411 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata\Object;
class ConstraintObject
{
/**
*
* @var string
*/
protected $name = null;
/**
*
* @var string
*/
protected $tableName = null;
/**
*
* @var string
*/
protected $schemaName = null;
/**
* One of "PRIMARY KEY", "UNIQUE", "FOREIGN KEY", or "CHECK"
*
* @var string
*/
protected $type = null;
/**
*
*
* @var string[]
*/
protected $columns = [];
/**
*
*
* @var string
*/
protected $referencedTableSchema;
/**
*
*
* @var string
*/
protected $referencedTableName;
/**
*
*
* @var string[]
*/
protected $referencedColumns;
/**
*
*
* @var string
*/
protected $matchOption;
/**
*
*
* @var string
*/
protected $updateRule;
/**
*
*
* @var string
*/
protected $deleteRule;
/**
*
*
* @var string
*/
protected $checkClause;
/**
* Constructor
*
* @param string $name
* @param string $tableName
* @param string $schemaName
*/
public function __construct($name, $tableName, $schemaName = null)
{
$this->setName($name);
$this->setTableName($tableName);
$this->setSchemaName($schemaName);
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set schema name
*
* @param string $schemaName
*/
public function setSchemaName($schemaName)
{
$this->schemaName = $schemaName;
}
/**
* Get schema name
*
* @return string
*/
public function getSchemaName()
{
return $this->schemaName;
}
/**
* Get table name
*
* @return string
*/
public function getTableName()
{
return $this->tableName;
}
/**
* Set table name
*
* @param string $tableName
* @return self Provides a fluent interface
*/
public function setTableName($tableName)
{
$this->tableName = $tableName;
return $this;
}
/**
* Set type
*
* @param string $type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Get type
*
* @return string
*/
public function getType()
{
return $this->type;
}
public function hasColumns()
{
return (! empty($this->columns));
}
/**
* Get Columns.
*
* @return string[]
*/
public function getColumns()
{
return $this->columns;
}
/**
* Set Columns.
*
* @param string[] $columns
* @return self Provides a fluent interface
*/
public function setColumns(array $columns)
{
$this->columns = $columns;
return $this;
}
/**
* Get Referenced Table Schema.
*
* @return string
*/
public function getReferencedTableSchema()
{
return $this->referencedTableSchema;
}
/**
* Set Referenced Table Schema.
*
* @param string $referencedTableSchema
* @return self Provides a fluent interface
*/
public function setReferencedTableSchema($referencedTableSchema)
{
$this->referencedTableSchema = $referencedTableSchema;
return $this;
}
/**
* Get Referenced Table Name.
*
* @return string
*/
public function getReferencedTableName()
{
return $this->referencedTableName;
}
/**
* Set Referenced Table Name.
*
* @param string $referencedTableName
* @return self Provides a fluent interface
*/
public function setReferencedTableName($referencedTableName)
{
$this->referencedTableName = $referencedTableName;
return $this;
}
/**
* Get Referenced Columns.
*
* @return string[]
*/
public function getReferencedColumns()
{
return $this->referencedColumns;
}
/**
* Set Referenced Columns.
*
* @param string[] $referencedColumns
* @return self Provides a fluent interface
*/
public function setReferencedColumns(array $referencedColumns)
{
$this->referencedColumns = $referencedColumns;
return $this;
}
/**
* Get Match Option.
*
* @return string
*/
public function getMatchOption()
{
return $this->matchOption;
}
/**
* Set Match Option.
*
* @param string $matchOption
* @return self Provides a fluent interface
*/
public function setMatchOption($matchOption)
{
$this->matchOption = $matchOption;
return $this;
}
/**
* Get Update Rule.
*
* @return string
*/
public function getUpdateRule()
{
return $this->updateRule;
}
/**
* Set Update Rule.
*
* @param string $updateRule
* @return self Provides a fluent interface
*/
public function setUpdateRule($updateRule)
{
$this->updateRule = $updateRule;
return $this;
}
/**
* Get Delete Rule.
*
* @return string
*/
public function getDeleteRule()
{
return $this->deleteRule;
}
/**
* Set Delete Rule.
*
* @param string $deleteRule
* @return self Provides a fluent interface
*/
public function setDeleteRule($deleteRule)
{
$this->deleteRule = $deleteRule;
return $this;
}
/**
* Get Check Clause.
*
* @return string
*/
public function getCheckClause()
{
return $this->checkClause;
}
/**
* Set Check Clause.
*
* @param string $checkClause
* @return self Provides a fluent interface
*/
public function setCheckClause($checkClause)
{
$this->checkClause = $checkClause;
return $this;
}
/**
* Is primary key
*
* @return bool
*/
public function isPrimaryKey()
{
return ('PRIMARY KEY' == $this->type);
}
/**
* Is unique key
*
* @return bool
*/
public function isUnique()
{
return ('UNIQUE' == $this->type);
}
/**
* Is foreign key
*
* @return bool
*/
public function isForeignKey()
{
return ('FOREIGN KEY' == $this->type);
}
/**
* Is foreign key
*
* @return bool
*/
public function isCheck()
{
return ('CHECK' == $this->type);
}
}

View File

@ -1,14 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata\Object;
class TableObject extends AbstractTableObject
{
}

View File

@ -1,448 +0,0 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Zend\Db\Metadata\Object;
class TriggerObject
{
/**
*
*
* @var string
*/
protected $name;
/**
*
*
* @var string
*/
protected $eventManipulation;
/**
*
*
* @var string
*/
protected $eventObjectCatalog;
/**
*
*
* @var string
*/
protected $eventObjectSchema;
/**
*
*
* @var string
*/
protected $eventObjectTable;
/**
*
*
* @var string
*/
protected $actionOrder;
/**
*
*
* @var string
*/
protected $actionCondition;
/**
*
*
* @var string
*/
protected $actionStatement;
/**
*
*
* @var string
*/
protected $actionOrientation;
/**
*
*
* @var string
*/
protected $actionTiming;
/**
*
*
* @var string
*/
protected $actionReferenceOldTable;
/**
*
*
* @var string
*/
protected $actionReferenceNewTable;
/**
*
*
* @var string
*/
protected $actionReferenceOldRow;
/**
*
*
* @var string
*/
protected $actionReferenceNewRow;
/**
*
*
* @var \DateTime
*/
protected $created;
/**
* Get Name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set Name.
*
* @param string $name
* @return self Provides a fluent interface
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get Event Manipulation.
*
* @return string
*/
public function getEventManipulation()
{
return $this->eventManipulation;
}
/**
* Set Event Manipulation.
*
* @param string $eventManipulation
* @return self Provides a fluent interface
*/
public function setEventManipulation($eventManipulation)
{
$this->eventManipulation = $eventManipulation;
return $this;
}
/**
* Get Event Object Catalog.
*
* @return string
*/
public function getEventObjectCatalog()
{
return $this->eventObjectCatalog;
}
/**
* Set Event Object Catalog.
*
* @param string $eventObjectCatalog
* @return self Provides a fluent interface
*/
public function setEventObjectCatalog($eventObjectCatalog)
{
$this->eventObjectCatalog = $eventObjectCatalog;
return $this;
}
/**
* Get Event Object Schema.
*
* @return string
*/
public function getEventObjectSchema()
{
return $this->eventObjectSchema;
}
/**
* Set Event Object Schema.
*
* @param string $eventObjectSchema
* @return self Provides a fluent interface
*/
public function setEventObjectSchema($eventObjectSchema)
{
$this->eventObjectSchema = $eventObjectSchema;
return $this;
}
/**
* Get Event Object Table.
*
* @return string
*/
public function getEventObjectTable()
{
return $this->eventObjectTable;
}
/**
* Set Event Object Table.
*
* @param string $eventObjectTable
* @return self Provides a fluent interface
*/
public function setEventObjectTable($eventObjectTable)
{
$this->eventObjectTable = $eventObjectTable;
return $this;
}
/**
* Get Action Order.
*
* @return string
*/
public function getActionOrder()
{
return $this->actionOrder;
}
/**
* Set Action Order.
*
* @param string $actionOrder
* @return self Provides a fluent interface
*/
public function setActionOrder($actionOrder)
{
$this->actionOrder = $actionOrder;
return $this;
}
/**
* Get Action Condition.
*
* @return string
*/
public function getActionCondition()
{
return $this->actionCondition;
}
/**
* Set Action Condition.
*
* @param string $actionCondition
* @return self Provides a fluent interface
*/
public function setActionCondition($actionCondition)
{
$this->actionCondition = $actionCondition;
return $this;
}
/**
* Get Action Statement.
*
* @return string
*/
public function getActionStatement()
{
return $this->actionStatement;
}
/**
* Set Action Statement.
*
* @param string $actionStatement
* @return self Provides a fluent interface
*/
public function setActionStatement($actionStatement)
{
$this->actionStatement = $actionStatement;
return $this;
}
/**
* Get Action Orientation.
*
* @return string
*/
public function getActionOrientation()
{
return $this->actionOrientation;
}
/**
* Set Action Orientation.
*
* @param string $actionOrientation
* @return self Provides a fluent interface
*/
public function setActionOrientation($actionOrientation)
{
$this->actionOrientation = $actionOrientation;
return $this;
}
/**
* Get Action Timing.
*
* @return string
*/
public function getActionTiming()
{
return $this->actionTiming;
}
/**
* Set Action Timing.
*
* @param string $actionTiming
* @return self Provides a fluent interface
*/
public function setActionTiming($actionTiming)
{
$this->actionTiming = $actionTiming;
return $this;
}
/**
* Get Action Reference Old Table.
*
* @return string
*/
public function getActionReferenceOldTable()
{
return $this->actionReferenceOldTable;
}
/**
* Set Action Reference Old Table.
*
* @param string $actionReferenceOldTable
* @return self Provides a fluent interface
*/
public function setActionReferenceOldTable($actionReferenceOldTable)
{
$this->actionReferenceOldTable = $actionReferenceOldTable;
return $this;
}
/**
* Get Action Reference New Table.
*
* @return string
*/
public function getActionReferenceNewTable()
{
return $this->actionReferenceNewTable;
}
/**
* Set Action Reference New Table.
*
* @param string $actionReferenceNewTable
* @return self Provides a fluent interface
*/
public function setActionReferenceNewTable($actionReferenceNewTable)
{
$this->actionReferenceNewTable = $actionReferenceNewTable;
return $this;
}
/**
* Get Action Reference Old Row.
*
* @return string
*/
public function getActionReferenceOldRow()
{
return $this->actionReferenceOldRow;
}
/**
* Set Action Reference Old Row.
*
* @param string $actionReferenceOldRow
* @return self Provides a fluent interface
*/
public function setActionReferenceOldRow($actionReferenceOldRow)
{
$this->actionReferenceOldRow = $actionReferenceOldRow;
return $this;
}
/**
* Get Action Reference New Row.
*
* @return string
*/
public function getActionReferenceNewRow()
{
return $this->actionReferenceNewRow;
}
/**
* Set Action Reference New Row.
*
* @param string $actionReferenceNewRow
* @return self Provides a fluent interface
*/
public function setActionReferenceNewRow($actionReferenceNewRow)
{
$this->actionReferenceNewRow = $actionReferenceNewRow;
return $this;
}
/**
* Get Created.
*
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set Created.
*
* @param \DateTime $created
* @return self Provides a fluent interface
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
}

Some files were not shown because too many files have changed in this diff Show More