Commit 9d60a957 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Did some more work on DBAL ReST documentation.

parent 9f535744
...@@ -9,25 +9,24 @@ Welcome to Doctrine DBAL's documentation! ...@@ -9,25 +9,24 @@ Welcome to Doctrine DBAL's documentation!
Contents: Contents:
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 1
:numbered:
introduction reference/introduction
architecture reference/architecture
configuration reference/configuration
data-retrieval-and-manipulation reference/data-retrieval-and-manipulation
transactions reference/transactions
platforms reference/platforms
types reference/types
schema-manager reference/schema-manager
schema-representation reference/schema-representation
events reference/events
supporting-other-databases reference/supporting-other-databases
known-vendor-issues reference/known-vendor-issues
Indices and tables Indices and tables
================== ==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search` * :ref:`search`
...@@ -7,7 +7,7 @@ Getting a Connection ...@@ -7,7 +7,7 @@ Getting a Connection
You can get a DBAL Connection through the You can get a DBAL Connection through the
``Doctrine\DBAL\DriverManager`` class. ``Doctrine\DBAL\DriverManager`` class.
:: .. code-block:: php
<?php <?php
$config = new \Doctrine\DBAL\Configuration(); $config = new \Doctrine\DBAL\Configuration();
...@@ -143,7 +143,6 @@ Custom Driver Options ...@@ -143,7 +143,6 @@ Custom Driver Options
The ``driverOptions`` option allows to pass arbitrary options The ``driverOptions`` option allows to pass arbitrary options
through to the driver. This is equivalent to the 4th argument of through to the driver. This is equivalent to the 4th argument of
the the `PDO constructor <http://php.net/manual/en/pdo.construct.php>`_.
`PDO constructor <http://php.net/manual/en/pdo.construct.php>`_.
...@@ -12,7 +12,7 @@ prepare() ...@@ -12,7 +12,7 @@ prepare()
Prepare a given sql statement and return the Prepare a given sql statement and return the
``\Doctrine\DBAL\Driver\Statement`` instance: ``\Doctrine\DBAL\Driver\Statement`` instance:
:: .. code-block:: php
<?php <?php
$statement = $conn->prepare('SELECT * FROM user'); $statement = $conn->prepare('SELECT * FROM user');
...@@ -34,7 +34,7 @@ executeUpdate() ...@@ -34,7 +34,7 @@ executeUpdate()
Executes a prepared statement with the given sql and parameters and Executes a prepared statement with the given sql and parameters and
returns the affected rows count: returns the affected rows count:
:: .. code-block:: php
<?php <?php
$count = $conn->executeUpdate('UPDATE user SET username = ? WHERE id = ?', array('jwage', 1)); $count = $conn->executeUpdate('UPDATE user SET username = ? WHERE id = ?', array('jwage', 1));
...@@ -51,7 +51,7 @@ executeQuery() ...@@ -51,7 +51,7 @@ executeQuery()
Creates a prepared statement for the given sql and passes the Creates a prepared statement for the given sql and passes the
parameters to the execute method, then returning the statement: parameters to the execute method, then returning the statement:
:: .. code-block:: php
<?php <?php
$statement = $conn->execute('SELECT * FROM user WHERE username = ?', array('jwage')); $statement = $conn->execute('SELECT * FROM user WHERE username = ?', array('jwage'));
...@@ -74,7 +74,7 @@ fetchAll() ...@@ -74,7 +74,7 @@ fetchAll()
Execute the query and fetch all results into an array: Execute the query and fetch all results into an array:
:: .. code-block:: php
<?php <?php
$users = $conn->fetchAll('SELECT * FROM user'); $users = $conn->fetchAll('SELECT * FROM user');
...@@ -93,7 +93,7 @@ fetchArray() ...@@ -93,7 +93,7 @@ fetchArray()
Numeric index retrieval of first result row of the given query: Numeric index retrieval of first result row of the given query:
:: .. code-block:: php
<?php <?php
$user = $conn->fetchArray('SELECT * FROM user WHERE username = ?', array('jwage')); $user = $conn->fetchArray('SELECT * FROM user WHERE username = ?', array('jwage'));
...@@ -110,7 +110,7 @@ fetchColumn() ...@@ -110,7 +110,7 @@ fetchColumn()
Retrieve only the given column of the first result row. Retrieve only the given column of the first result row.
:: .. code-block:: php
<?php <?php
$username = $conn->fetchColumn('SELECT username FROM user WHERE id = ?', array(1), 0); $username = $conn->fetchColumn('SELECT username FROM user WHERE id = ?', array(1), 0);
...@@ -121,7 +121,7 @@ fetchAssoc() ...@@ -121,7 +121,7 @@ fetchAssoc()
Retrieve assoc row of the first result row. Retrieve assoc row of the first result row.
:: .. code-block:: php
<?php <?php
$user = $conn->fetchAssoc('SELECT * FROM user WHERE username = ?', array('jwage')); $user = $conn->fetchAssoc('SELECT * FROM user WHERE username = ?', array('jwage'));
...@@ -140,7 +140,7 @@ delete() ...@@ -140,7 +140,7 @@ delete()
Delete all rows of a table matching the given identifier, where Delete all rows of a table matching the given identifier, where
keys are column names. keys are column names.
:: .. code-block:: php
<?php <?php
$conn->delete('user', array('id' => 1)); $conn->delete('user', array('id' => 1));
...@@ -152,7 +152,7 @@ insert() ...@@ -152,7 +152,7 @@ insert()
Insert a row into the given table name using the key value pairs of Insert a row into the given table name using the key value pairs of
data. data.
:: .. code-block:: php
<?php <?php
$conn->insert('user', array('username' => 'jwage')); $conn->insert('user', array('username' => 'jwage'));
...@@ -164,7 +164,7 @@ update() ...@@ -164,7 +164,7 @@ update()
Update all rows for the matching key value identifiers with the Update all rows for the matching key value identifiers with the
given data. given data.
:: .. code-block:: php
<?php <?php
$conn->update('user', array('username' => 'jwage'), array('id' => 1)); $conn->update('user', array('username' => 'jwage'), array('id' => 1));
...@@ -182,7 +182,7 @@ quote() ...@@ -182,7 +182,7 @@ quote()
Quote a value: Quote a value:
:: .. code-block:: php
<?php <?php
$quoted = $conn->quote('value'); $quoted = $conn->quote('value');
...@@ -193,7 +193,7 @@ quoteIdentifier() ...@@ -193,7 +193,7 @@ quoteIdentifier()
Quote an identifier according to the platform details. Quote an identifier according to the platform details.
:: .. code-block:: php
<?php <?php
$quoted = $conn->quoteIdentifier('id'); $quoted = $conn->quoteIdentifier('id');
......
...@@ -32,7 +32,7 @@ Doctrine is already shipped with two implementations for the ...@@ -32,7 +32,7 @@ Doctrine is already shipped with two implementations for the
You can register events by subscribing them to the ``EventManager`` You can register events by subscribing them to the ``EventManager``
instance passed to the Connection factory: instance passed to the Connection factory:
:: .. code-block:: php
<?php <?php
$evm = new EventManager(); $evm = new EventManager();
......
...@@ -19,7 +19,7 @@ the ``Doctrine\Common`` and ``Doctrine\DBAL`` namespaces. Once you ...@@ -19,7 +19,7 @@ the ``Doctrine\Common`` and ``Doctrine\DBAL`` namespaces. Once you
have the Common and DBAL namespaces you must setup a class loader have the Common and DBAL namespaces you must setup a class loader
to be able to autoload the classes: to be able to autoload the classes:
:: .. code-block:: php
<?php <?php
use Doctrine\Common\ClassLoader; use Doctrine\Common\ClassLoader;
......
...@@ -105,15 +105,15 @@ OCI8: SQL Queries with Question Marks ...@@ -105,15 +105,15 @@ OCI8: SQL Queries with Question Marks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We had to implement a question mark to named parameter translation We had to implement a question mark to named parameter translation
inside the OCI8 DBAL Driver. This means that you cannot execute inside the OCI8 DBAL Driver. It works as a very simple parser with two states: Inside Literal, Outside Literal.
queries that contain question marks in the SQL string. For From our perspective it should be working in all cases, but you have to be careful with certain
example: queries:
.. code-block:: sql .. code-block:: sql
SELECT * FROM users WHERE name = 'bar?' SELECT * FROM users WHERE name = 'bar?'
Will be rewritten into: Could in case of a bug with the parser be rewritten into:
.. code-block:: sql .. code-block:: sql
...@@ -123,17 +123,13 @@ For this reason you should always use prepared statements with ...@@ -123,17 +123,13 @@ For this reason you should always use prepared statements with
Oracle OCI8, never use string literals inside the queries. A query Oracle OCI8, never use string literals inside the queries. A query
for the user 'bar?' should look like: for the user 'bar?' should look like:
:: .. code-block:: php
$sql = 'SELECT * FROM users WHERE name = ?' $sql = 'SELECT * FROM users WHERE name = ?'
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->bindValue(1, 'bar?'); $stmt->bindValue(1, 'bar?');
$stmt->execute(); $stmt->execute();
We will probably fix this issue in the future by implementing a
little parser inside the OCI8 Driver that can detect the difference
between question mark needles and literal questions marks.
OCI-LOB instances OCI-LOB instances
~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
......
...@@ -8,7 +8,7 @@ and Indexes. ...@@ -8,7 +8,7 @@ and Indexes.
To retrieve the ``SchemaManager`` for your connection you can use To retrieve the ``SchemaManager`` for your connection you can use
the ``getSchemaManager()`` method: the ``getSchemaManager()`` method:
:: .. code-block:: php
<?php <?php
$sm = $conn->getSchemaManager(); $sm = $conn->getSchemaManager();
...@@ -31,7 +31,7 @@ listDatabases() ...@@ -31,7 +31,7 @@ listDatabases()
Retrieve an array of databases on the configured connection: Retrieve an array of databases on the configured connection:
:: .. code-block:: php
<?php <?php
$databases = $sm->listDatabases(); $databases = $sm->listDatabases();
...@@ -42,21 +42,21 @@ listSequences() ...@@ -42,21 +42,21 @@ listSequences()
Retrieve an array of ``Doctrine\DBAL\Schema\Sequence`` instances Retrieve an array of ``Doctrine\DBAL\Schema\Sequence`` instances
that exist for a database: that exist for a database:
:: .. code-block:: php
<?php <?php
$sequences = $sm->listSequences(); $sequences = $sm->listSequences();
Or if you want to manually specify a database name: Or if you want to manually specify a database name:
:: .. code-block:: php
<?php <?php
$sequences = $sm->listSequences('dbname'); $sequences = $sm->listSequences('dbname');
Now you can loop over the array inspecting each sequence object: Now you can loop over the array inspecting each sequence object:
:: .. code-block:: php
<?php <?php
foreach ($sequences as $sequence) { foreach ($sequences as $sequence) {
...@@ -69,14 +69,14 @@ listTableColumns() ...@@ -69,14 +69,14 @@ listTableColumns()
Retrieve an array of ``Doctrine\DBAL\Schema\Column`` instances that Retrieve an array of ``Doctrine\DBAL\Schema\Column`` instances that
exist for the given table: exist for the given table:
:: .. code-block:: php
<?php <?php
$columns = $sm->listTableColumns('user'); $columns = $sm->listTableColumns('user');
Now you can loop over the array inspecting each column object: Now you can loop over the array inspecting each column object:
:: .. code-block:: php
<?php <?php
foreach ($columns as $column) { foreach ($columns as $column) {
...@@ -89,7 +89,7 @@ listTableDetails() ...@@ -89,7 +89,7 @@ listTableDetails()
Retrieve a single ``Doctrine\DBAL\Schema\Table`` instance that Retrieve a single ``Doctrine\DBAL\Schema\Table`` instance that
encapsulates all the details of the given table: encapsulates all the details of the given table:
:: .. code-block:: php
<?php <?php
$table = $sm->listTableDetails('user'); $table = $sm->listTableDetails('user');
...@@ -97,7 +97,7 @@ encapsulates all the details of the given table: ...@@ -97,7 +97,7 @@ encapsulates all the details of the given table:
Now you can call methods on the table to manipulate the in memory Now you can call methods on the table to manipulate the in memory
schema for that table. For example we can add a new column: schema for that table. For example we can add a new column:
:: .. code-block:: php
<?php <?php
$table->addColumn('email_address', 'string'); $table->addColumn('email_address', 'string');
...@@ -108,7 +108,7 @@ listTableForeignKeys() ...@@ -108,7 +108,7 @@ listTableForeignKeys()
Retrieve an array of ``Doctrine\DBAL\Schema\ForeignKeyConstraint`` Retrieve an array of ``Doctrine\DBAL\Schema\ForeignKeyConstraint``
instances that exist for the given table: instances that exist for the given table:
:: .. code-block:: php
<?php <?php
$foreignKeys = $sm->listTableForeignKeys('user'); $foreignKeys = $sm->listTableForeignKeys('user');
...@@ -116,7 +116,7 @@ instances that exist for the given table: ...@@ -116,7 +116,7 @@ instances that exist for the given table:
Now you can loop over the array inspecting each foreign key Now you can loop over the array inspecting each foreign key
object: object:
:: .. code-block:: php
<?php <?php
foreach ($foreignKeys as $foreignKey) { foreach ($foreignKeys as $foreignKey) {
...@@ -129,14 +129,14 @@ listTableIndexes() ...@@ -129,14 +129,14 @@ listTableIndexes()
Retrieve an array of ``Doctrine\DBAL\Schema\Index`` instances that Retrieve an array of ``Doctrine\DBAL\Schema\Index`` instances that
exist for the given table: exist for the given table:
:: .. code-block:: php
<?php <?php
$indexes = $sm->listTableIndexes('user'); $indexes = $sm->listTableIndexes('user');
Now you can loop over the array inspecting each index object: Now you can loop over the array inspecting each index object:
:: .. code-block:: php
<?php <?php
foreach ($indexes as $index) { foreach ($indexes as $index) {
...@@ -149,7 +149,7 @@ listTables() ...@@ -149,7 +149,7 @@ listTables()
Retrieve an array of ``Doctrine\DBAL\Schema\Table`` instances that Retrieve an array of ``Doctrine\DBAL\Schema\Table`` instances that
exist in the connections database: exist in the connections database:
:: .. code-block:: php
<?php <?php
$tables = $sm->listTables(); $tables = $sm->listTables();
...@@ -159,7 +159,7 @@ information provided by all the above methods. So it encapsulates ...@@ -159,7 +159,7 @@ information provided by all the above methods. So it encapsulates
an array of ``Doctrine\DBAL\Schema\Column`` instances that can be an array of ``Doctrine\DBAL\Schema\Column`` instances that can be
retrieved with the ``getColumns()`` method: retrieved with the ``getColumns()`` method:
:: .. code-block:: php
<?php <?php
foreach ($tables as $table) { foreach ($tables as $table) {
...@@ -175,14 +175,14 @@ listViews() ...@@ -175,14 +175,14 @@ listViews()
Retrieve an array of ``Doctrine\DBAL\Schema\View`` instances that Retrieve an array of ``Doctrine\DBAL\Schema\View`` instances that
exist in the connections database: exist in the connections database:
:: .. code-block:: php
<?php <?php
$views = $sm->listViews(); $views = $sm->listViews();
Now you can loop over the array inspecting each view object: Now you can loop over the array inspecting each view object:
:: .. code-block:: php
<?php <?php
foreach ($views as $view) { foreach ($views as $view) {
...@@ -197,7 +197,7 @@ the ``createSchema()`` method which returns an instance of ...@@ -197,7 +197,7 @@ the ``createSchema()`` method which returns an instance of
``Doctrine\DBAL\Schema\Schema``, which you can use in conjunction ``Doctrine\DBAL\Schema\Schema``, which you can use in conjunction
with the SchemaTool or Schema Comparator. with the SchemaTool or Schema Comparator.
:: .. code-block:: php
<?php <?php
$fromSchema = $sm->createSchema(); $fromSchema = $sm->createSchema();
...@@ -205,7 +205,7 @@ with the SchemaTool or Schema Comparator. ...@@ -205,7 +205,7 @@ with the SchemaTool or Schema Comparator.
Now we can clone the ``$fromSchema`` to ``$toSchema`` and drop a Now we can clone the ``$fromSchema`` to ``$toSchema`` and drop a
table: table:
:: .. code-block:: php
<?php <?php
$toSchema = clone $fromSchema; $toSchema = clone $fromSchema;
...@@ -215,7 +215,7 @@ Now we can compare the two schema instances in order to calculate ...@@ -215,7 +215,7 @@ Now we can compare the two schema instances in order to calculate
the differences between them and return the sql required to make the differences between them and return the sql required to make
the changes on the database: the changes on the database:
:: .. code-block:: php
<?php <?php
$sql = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform()); $sql = $fromSchema->getMigrateToSql($toSchema, $conn->getDatabasePlatform());
...@@ -223,7 +223,7 @@ the changes on the database: ...@@ -223,7 +223,7 @@ the changes on the database:
The ``$sql`` array should give you a sql query to drop the user The ``$sql`` array should give you a sql query to drop the user
table: table:
:: .. code-block:: php
<?php <?php
print_r($sql); print_r($sql);
......
...@@ -19,7 +19,7 @@ or for SQL schema generation for any metadata model that your ...@@ -19,7 +19,7 @@ or for SQL schema generation for any metadata model that your
application has. You can easily generate a Schema, as a simple application has. You can easily generate a Schema, as a simple
example shows: example shows:
:: .. code-block:: php
<?php <?php
$schema = new \Doctrine\DBAL\Schema\Schema(); $schema = new \Doctrine\DBAL\Schema\Schema();
...@@ -43,7 +43,7 @@ use the ``Comparator`` class to get instances of ``SchemaDiff``, ...@@ -43,7 +43,7 @@ use the ``Comparator`` class to get instances of ``SchemaDiff``,
``TableDiff`` and ``ColumnDiff``, aswell as information about other ``TableDiff`` and ``ColumnDiff``, aswell as information about other
foreign key, sequence and index changes. foreign key, sequence and index changes.
:: .. code-block:: php
<?php <?php
$comparator = new \Doctrine\DBAL\Schema\Comparator(); $comparator = new \Doctrine\DBAL\Schema\Comparator();
......
...@@ -124,17 +124,18 @@ All that is guaruanteed to the inner transaction is that it still ...@@ -124,17 +124,18 @@ All that is guaruanteed to the inner transaction is that it still
happens atomically, all or nothing, the transaction just gets a happens atomically, all or nothing, the transaction just gets a
wider scope and the control is handed to the outer scope. wider scope and the control is handed to the outer scope.
**CAUTION** The transaction nesting described here is a debated .. note::
The transaction nesting described here is a debated
feature that has it's critics. Form your own opinion. We recommend feature that has it's critics. Form your own opinion. We recommend
avoiding nesting transaction blocks when possible, and most of the avoiding nesting transaction blocks when possible, and most of the
time, it is possible. Transaction control should mostly be left to time, it is possible. Transaction control should mostly be left to
a service layer and not be handled in data access objects or a service layer and not be handled in data access objects or
similar. similar.
.. warning::
- Directly invoking ``PDO#beginTransaction()``,
**CAUTION** Directly invoking ``PDO#beginTransaction()``,
``PDO#commit()`` or ``PDO#rollback()`` or the corresponding methods ``PDO#commit()`` or ``PDO#rollback()`` or the corresponding methods
on the particular ``Doctrine\DBAL\Driver\Connection`` instance in on the particular ``Doctrine\DBAL\Driver\Connection`` instance in
use bybasses the transparent transaction nesting that is provided use bybasses the transparent transaction nesting that is provided
......
#!/bin/bash #!/bin/bash
sphinx-build reference/en /var/www/docs sphinx-build en /var/www/docs
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment