Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
34da8376
Commit
34da8376
authored
May 30, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Fixing __call() in AbstractSchemaManager, doc blocks, clean up
parent
ac8492d2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
179 additions
and
924 deletions
+179
-924
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+2
-2
Db2Platform.php
lib/Doctrine/DBAL/Platforms/Db2Platform.php
+0
-22
FirebirdPlatform.php
lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php
+0
-113
InformixPlatform.php
lib/Doctrine/DBAL/Platforms/InformixPlatform.php
+0
-21
AbstractSchemaManager.php
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
+177
-81
FirebirdSchemaManager.php
lib/Doctrine/DBAL/Schema/FirebirdSchemaManager.php
+0
-629
InformixSchemaManager.php
lib/Doctrine/DBAL/Schema/InformixSchemaManager.php
+0
-56
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
34da8376
...
...
@@ -513,9 +513,9 @@ abstract class AbstractPlatform
return
'DROP TABLE '
.
$table
;
}
public
function
getDropIndexSql
(
$
index
,
$name
)
public
function
getDropIndexSql
(
$
table
,
$name
)
{
return
'DROP INDEX '
.
$
index
;
return
'DROP INDEX '
.
$
name
;
}
public
function
getDropConstraintSql
(
$table
,
$name
,
$primary
=
false
)
...
...
lib/Doctrine/DBAL/Platforms/Db2Platform.php
deleted
100644 → 0
View file @
ac8492d2
<?php
namespace
Doctrine\DBAL\Platforms
;
class
Db2Platform
extends
AbstractPlatform
{
public
function
getSequenceNextValSql
(
$sequenceName
)
{
return
'SELECT NEXTVAL FOR '
.
$this
->
quoteIdentifier
(
$sequenceName
)
.
' FROM SYSIBM.SYSDUMMY1'
;
}
/**
* Get the platform name for this instance
*
* @return string
*/
public
function
getName
()
{
return
'db2'
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Platforms/FirebirdPlatform.php
deleted
100644 → 0
View file @
ac8492d2
<?php
namespace
Doctrine\DBAL\Platforms
;
class
FirebirdPlatform
extends
AbstractPlatform
{
/**
* Constructor.
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query query to modify
* @param integer $limit limit the number of rows
* @param integer $offset start reading from given offset
* @return string modified query
* @override
*/
public
function
writeLimitClause
(
$query
,
$limit
,
$offset
)
{
if
(
!
$offset
)
{
$offset
=
0
;
}
if
(
$limit
>
0
)
{
$query
=
preg_replace
(
'/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i'
,
"SELECT FIRST
$limit
SKIP
$offset
"
,
$query
);
}
return
$query
;
}
/**
* return string for internal table used when calling only a function
*
* @return string for internal table used when calling only a function
*/
public
function
getFunctionTableExpression
()
{
return
' FROM RDB$DATABASE'
;
}
/**
* build string to define escape pattern string
*
* @return string define escape pattern
* @override
*/
public
function
getPatternEscapeStringExpression
()
{
return
" ESCAPE '"
.
$this
->
_properties
[
'escape_pattern'
]
.
"'"
;
}
/**
* Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $charset name of the charset
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET
* of a field declaration.
*/
public
function
getCharsetFieldDeclaration
(
$charset
)
{
return
'CHARACTER SET '
.
$charset
;
}
/**
* Obtain DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration to be used in statements like CREATE TABLE.
*
* @param string $collation name of the collation
* @return string DBMS specific SQL code portion needed to set the COLLATION
* of a field declaration.
*/
public
function
getCollationFieldDeclaration
(
$collation
)
{
return
'COLLATE '
.
$collation
;
}
public
function
getSequenceNextValSql
(
$sequenceName
)
{
return
'SELECT GEN_ID('
.
$this
->
quoteIdentifier
(
$sequenceName
)
.
', 1) FROM RDB$DATABASE'
;
}
protected
function
_getTransactionIsolationLevelSql
(
$level
)
{
switch
(
$level
)
{
case
Doctrine_DBAL_Connection
::
TRANSACTION_READ_UNCOMMITTED
:
return
'READ COMMITTED RECORD_VERSION'
;
case
Doctrine_DBAL_Connection
::
TRANSACTION_READ_COMMITTED
:
return
'READ COMMITTED NO RECORD_VERSION'
;
case
Doctrine_DBAL_Connection
::
TRANSACTION_REPEATABLE_READ
:
return
'SNAPSHOT'
;
case
Doctrine_DBAL_Connection
::
TRANSACTION_SERIALIZABLE
:
return
'SNAPSHOT TABLE STABILITY'
;
default
:
return
parent
::
_getTransactionIsolationLevelSql
(
$level
);
}
}
public
function
getSetTransactionIsolationSql
(
$level
)
{
return
'SET TRANSACTION ISOLATION LEVEL '
.
$this
->
_getTransactionIsolationLevelSql
(
$level
);
}
public
function
getName
()
{
return
'firebird'
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Platforms/InformixPlatform.php
deleted
100644 → 0
View file @
ac8492d2
<?php
namespace
Doctrine\DBAL\Platforms
;
class
InformixPlatform
extends
AbstractPlatform
{
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Get the platform name for this instance
*
* @return string
*/
public
function
getName
()
{
return
'informix'
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
View file @
34da8376
...
...
@@ -63,6 +63,34 @@ abstract class AbstractSchemaManager
$this
->
_platform
=
$this
->
_conn
->
getDatabasePlatform
();
}
/**
* Try any method on the schema manager. Normally a method throws an
* exception when your DBMS doesn't support it or if an error occurs.
* This method allows you to try and method on your SchemaManager
* instance and will return false if it does not work or is not supported.
*
* <code>
* $result = $sm->tryMethod('dropView', 'view_name');
* </code>
*
* @return mixed
*/
public
function
tryMethod
()
{
$args
=
func_get_args
();
$method
=
$args
[
0
];
unset
(
$args
[
0
]);
$args
=
array_values
(
$args
);
try
{
return
call_user_func_array
(
array
(
$this
,
$method
),
$args
);
}
catch
(
\Exception
$e
)
{
return
false
;
}
}
/* list*() Methods */
/**
* List the available databases for this connection
*
...
...
@@ -226,6 +254,8 @@ abstract class AbstractSchemaManager
return
$this
->
_getPortableTableForeignKeysList
(
$tableForeignKeys
);
}
/* drop*() Methods */
/**
* Drops a database.
*
...
...
@@ -235,7 +265,7 @@ abstract class AbstractSchemaManager
*/
public
function
dropDatabase
(
$database
)
{
$this
->
_
conn
->
exec
(
$this
->
_platform
->
getDropDatabaseSql
(
$database
));
$this
->
_
execSql
(
$this
->
_platform
->
getDropDatabaseSql
(
$database
));
}
/**
...
...
@@ -256,9 +286,6 @@ abstract class AbstractSchemaManager
*/
public
function
dropIndex
(
$table
,
$name
)
{
//FIXME: Something is wrong here. The signature of getDropIndexSql is:
// public function getDropIndexSql($index, $name)
// $table == $index ???
$this
->
_execSql
(
$this
->
_platform
->
getDropIndexSql
(
$table
,
$name
));
}
...
...
@@ -297,6 +324,19 @@ abstract class AbstractSchemaManager
$this
->
_execSql
(
$this
->
_platform
->
getDropSequenceSql
(
$name
));
}
/**
* Drop a view
*
* @param string $name The name of the view
* @return boolean $result
*/
public
function
dropView
(
$name
)
{
return
$this
->
_execSql
(
$this
->
_platform
->
getDropViewSql
(
$name
));
}
/* create*() Methods */
/**
* Creates a new database.
*
...
...
@@ -311,7 +351,7 @@ abstract class AbstractSchemaManager
* Create a new table.
*
* @param string $name Name of the database that should be created
* @param array $
field
s Associative array that contains the definition of each field of the new table
* @param array $
column
s Associative array that contains the definition of each field of the new table
* @param array $options An associative array of table options.
*/
public
function
createTable
(
$name
,
array
$columns
,
array
$options
=
array
())
...
...
@@ -336,12 +376,7 @@ abstract class AbstractSchemaManager
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* );
* @param array $allocationSize The size to allocate for sequence
* @throws Doctrine\DBAL\ConnectionException if something fails at database level
*/
public
function
createSequence
(
$seqName
,
$start
=
1
,
$allocationSize
=
1
)
...
...
@@ -410,7 +445,7 @@ abstract class AbstractSchemaManager
}
/**
*
createForeignK
ey
*
Create a new foreign k
ey
*
* @param string $table name of the table on which the foreign key is to be created
* @param array $definition associative array that defines properties of the foreign key to be created.
...
...
@@ -431,17 +466,137 @@ abstract class AbstractSchemaManager
return
$this
->
_execSql
(
$this
->
_platform
->
getCreateViewSql
(
$name
,
$sql
));
}
/* dropAndCreate*() Methods */
/**
* Drop a view
* Drop and create a constraint
*
* @param string $table name of the table on which the constraint is to be created
* @param string $name name of the constraint to be created
* @param array $definition associative array that defines properties of the constraint to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the constraint fields as array
* constraints. Each entry of this array is set to another type of associative
* array that specifies properties of the constraint that are specific to
* each field.
*
* Example
* array(
* 'fields' => array(
* 'user_name' => array(),
* 'last_login' => array()
* )
* )
* @param boolean $primary Whether or not it is a primary constraint
* @see dropConstraint()
* @see createConstraint()
*/
public
function
dropAndCreateConstraint
(
$table
,
$name
,
$definition
,
$primary
=
false
)
{
$this
->
tryMethod
(
'dropConstraint'
,
$table
,
$name
,
$primary
);
$this
->
createConstraint
(
$table
,
$name
,
$definition
);
}
/**
* Drop and create a new index on a table
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* each field.
*
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
*
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function supports() to determine whether the DBMS driver can manage indexes.
*
* Example
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => 'ascending'
* ),
* 'last_login' => array()
* )
* )
*/
public
function
dropAndCreateIndex
(
$table
,
$name
,
array
$definition
)
{
$this
->
tryMethod
(
'dropIndex'
,
$table
,
$name
);
$this
->
createIndex
(
$table
,
$name
,
$definition
);
}
/**
* Drop and create a new foreign key
*
* @param string $table name of the table on which the foreign key is to be created
* @param array $definition associative array that defines properties of the foreign key to be created.
*/
public
function
dropAndCreateForeignKey
(
$table
,
$definition
)
{
$this
->
tryMethod
(
'dropForeignKey'
,
$table
,
$definition
[
'name'
]);
$this
->
createForeignKey
(
$table
,
$definition
);
}
/**
* Drop and create a new sequence
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $allocationSize The size to allocate for sequence
* @throws Doctrine\DBAL\ConnectionException if something fails at database level
*/
public
function
dropAndCreateSequence
(
$seqName
,
$start
=
1
,
$allocationSize
=
1
)
{
$this
->
tryMethod
(
'createSequence'
,
$seqName
,
$start
,
$allocationSize
);
$this
->
createSequence
(
$seqName
,
$start
,
$allocationSize
);
}
/**
* Drop and create a new table.
*
* @param string $name Name of the database that should be created
* @param array $columns Associative array that contains the definition of each field of the new table
* @param array $options An associative array of table options.
*/
public
function
dropAndCreateTable
(
$name
,
array
$columns
,
array
$options
=
array
())
{
$this
->
tryMethod
(
'dropTable'
,
$name
);
$this
->
createTable
(
$name
,
$columns
,
$options
);
}
/**
* Drop and creates a new database.
*
* @param string $database The name of the database to create.
*/
public
function
dropAndCreateDatabase
(
$database
)
{
$this
->
tryMethod
(
'dropDatabase'
,
$database
);
$this
->
createDatabase
(
$database
);
}
/**
* Drop and create a new view
*
* @param string $name The name of the view
* @
return boolean $result
* @
param string $sql The sql to set to the view
*/
public
function
drop
View
(
$name
)
public
function
drop
AndCreateView
(
$name
,
$sql
)
{
return
$this
->
_execSql
(
$this
->
_platform
->
getDropViewSql
(
$name
));
$this
->
tryMethod
(
'dropView'
,
$name
);
$this
->
createView
(
$name
,
$sql
);
}
/* alterTable() Methods */
/**
* Alter an existing tables schema
*
...
...
@@ -623,6 +778,11 @@ abstract class AbstractSchemaManager
$this
->
alterTable
(
$name
,
$change
);
}
/**
* Methods for filtering return values of list*() methods to convert
* the native DBMS data definition to a portable Doctrine definition
*/
protected
function
_getPortableDatabasesList
(
$databases
)
{
$list
=
array
();
...
...
@@ -801,75 +961,11 @@ abstract class AbstractSchemaManager
{
return
$tableForeignKey
;
}
/**
* Executes one or more SQL statements using Connection#exec.
*
* @param string|array $sql The SQL to execute.
*/
protected
function
_execSql
(
$sql
)
{
foreach
((
array
)
$sql
as
$query
)
{
$this
->
_conn
->
exec
(
$query
);
}
}
public
function
tryMethod
()
{
$args
=
func_get_args
();
$method
=
$args
[
0
];
unset
(
$args
[
0
]);
$args
=
array_values
(
$args
);
try
{
return
call_user_func_array
(
array
(
$this
,
$method
),
$args
);
}
catch
(
\Exception
$e
)
{
//FIXME: Exception silencing is dangerous and hard to debug :(
return
false
;
}
}
private
function
_handleDropAndCreate
(
$method
,
$arguments
)
{
if
(
substr
(
$method
,
0
,
13
)
==
'dropAndCreate'
)
{
$base
=
substr
(
$method
,
13
,
strlen
(
$method
));
$dropMethod
=
'drop'
.
$base
;
$createMethod
=
'create'
.
$base
;
call_user_func_array
(
array
(
$this
,
'tryMethod'
),
array_merge
(
array
(
$dropMethod
),
$arguments
));
call_user_func_array
(
array
(
$this
,
'tryMethod'
),
array_merge
(
array
(
$createMethod
),
$arguments
));
return
true
;
}
return
false
;
}
private
function
_handleTryMethod
(
$method
,
$arguments
)
{
if
(
substr
(
$method
,
0
,
3
)
==
'try'
)
{
$method
=
substr
(
$method
,
3
,
strlen
(
$method
));
$method
=
strtolower
(
$method
[
0
])
.
substr
(
$method
,
1
,
strlen
(
$method
));
return
call_user_func_array
(
array
(
$this
,
'tryMethod'
),
array_merge
(
array
(
$method
),
$arguments
));
}
}
//FIXME: Turn into explicit, public, documented method.
public
function
__call
(
$method
,
$arguments
)
{
if
(
$result
=
$this
->
_handleDropAndCreate
(
$method
,
$arguments
))
{
return
$result
;
}
if
(
$result
=
$this
->
_handleTryMethod
(
$method
,
$arguments
))
{
return
$result
;
}
throw
DoctrineException
::
updateMe
(
"Invalid method named `"
.
$method
.
"` on class `"
.
__CLASS__
.
"`"
);
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Schema/FirebirdSchemaManager.php
deleted
100644 → 0
View file @
ac8492d2
<?php
/*
* $Id$
*
* 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.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
namespace
Doctrine\DBAL\Schema
;
/**
* xxx
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @version $Revision$
* @since 2.0
*/
class
FirebirdSchemaManager
extends
AbstractSchemaManager
{
/**
* list all tables in the current database
*
* @return array data array
*/
public
function
listTables
(
$database
=
null
)
{
$query
=
'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NULL'
;
return
$this
->
conn
->
fetchColumn
(
$query
);
}
/**
* list all fields in a tables in the current database
*
* @param string $table name of table that should be used in method
* @return mixed data array on success, a MDB2 error on failure
* @access public
*/
public
function
listTableFields
(
$table
)
{
$table
=
$this
->
_conn
->
quote
(
strtoupper
(
$table
),
'text'
);
$query
=
'SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE UPPER(RDB$RELATION_NAME) = '
.
$table
;
return
$this
->
_conn
->
fetchColumn
(
$query
);
}
/**
* list all users
*
* @return array data array containing all database users
*/
public
function
listUsers
()
{
return
$this
->
_conn
->
fetchColumn
(
'SELECT DISTINCT RDB$USER FROM RDB$USER_PRIVILEGES'
);
}
/**
* list the views in the database
*
* @return array data array containing all database views
*/
public
function
listViews
(
$database
=
null
)
{
return
$this
->
_conn
->
fetchColumn
(
'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS'
);
}
/**
* list the views in the database that reference a given table
*
* @param string $table table for which all references views should be found
* @return array data array containing all views for given table
*/
public
function
listTableViews
(
$table
)
{
$query
=
'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS'
;
$table
=
$this
->
_conn
->
quote
(
strtoupper
(
$table
),
'text'
);
$query
.=
' WHERE UPPER(RDB$RELATION_NAME) = '
.
$table
;
return
$this
->
_conn
->
fetchColumn
(
$query
);
}
/**
* list all functions in the current database
*
* @return array data array containing all availible functions
*/
public
function
listFunctions
()
{
$query
=
'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS WHERE RDB$SYSTEM_FLAG IS NULL'
;
return
$this
->
_conn
->
fetchColumn
(
$query
);
}
/**
* This function will be called to get all triggers of the
* current database ($this->_conn->getDatabase())
*
* @param string $table The name of the table from the
* previous database to query against.
* @return array data array containing all triggers for given table
*/
public
function
listTableTriggers
(
$table
)
{
$query
=
'SELECT RDB$TRIGGER_NAME FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG IS NULL OR RDB$SYSTEM_FLAG = 0'
;
if
(
!
is_null
(
$table
))
{
$table
=
$this
->
_conn
->
quote
(
strtoupper
(
$table
),
'text'
);
$query
.=
' WHERE UPPER(RDB$RELATION_NAME) = '
.
$table
;
}
return
$this
->
_conn
->
fetchColumn
(
$query
);
}
/**
* create a new database
*
* @param string $name name of the database that should be created
* @return void
*/
public
function
createDatabase
(
$name
)
{
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'PHP Interbase API does not support direct queries. You have to '
.
'create the db manually by using isql command or a similar program'
);
}
/**
* drop an existing database
*
* @param string $name name of the database that should be dropped
* @return void
*/
public
function
dropDatabase
(
$name
)
{
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'PHP Interbase API does not support direct queries. You have '
.
'to drop the db manually by using isql command or a similar program'
);
}
/**
* add an autoincrement sequence + trigger
*
* @param string $name name of the PK field
* @param string $table name of the table
* @param string $start start value for the sequence
* @return void
*/
public
function
_makeAutoincrement
(
$name
,
$table
,
$start
=
null
)
{
if
(
is_null
(
$start
))
{
$this
->
_conn
->
beginTransaction
();
$query
=
'SELECT MAX('
.
$this
->
_conn
->
quoteIdentifier
(
$name
,
true
)
.
') FROM '
.
$this
->
_conn
->
quoteIdentifier
(
$table
,
true
);
$start
=
$this
->
_conn
->
fetchOne
(
$query
,
'integer'
);
++
$start
;
$result
=
$this
->
createSequence
(
$table
,
$start
);
$this
->
_conn
->
commit
();
}
else
{
$result
=
$this
->
createSequence
(
$table
,
$start
);
}
$sequence_name
=
$this
->
_conn
->
formatter
->
getSequenceName
(
$table
);
$trigger_name
=
$this
->
_conn
->
quoteIdentifier
(
$table
.
'_AUTOINCREMENT_PK'
,
true
);
$table
=
$this
->
_conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
_conn
->
quoteIdentifier
(
$name
,
true
);
$triggerSql
=
'CREATE TRIGGER '
.
$trigger_name
.
' FOR '
.
$table
.
' ACTIVE BEFORE INSERT POSITION 0 AS'
.
' BEGIN'
.
' IF (NEW.'
.
$name
.
' IS NULL OR NEW.'
.
$name
.
' = 0) THEN'
.
' NEW.'
.
$name
.
' = GEN_ID('
.
$sequence_name
.
', 1)'
.
' END'
;
$result
=
$this
->
_conn
->
exec
(
$triggerSql
);
// TODO ? $this->_silentCommit();
return
$result
;
}
/**
* drop an existing autoincrement sequence + trigger
*
* @param string $table name of the table
* @return void
*/
public
function
_dropAutoincrement
(
$table
)
{
$result
=
$this
->
dropSequence
(
$table
);
//remove autoincrement trigger associated with the table
$table
=
$this
->
_conn
->
quote
(
strtoupper
(
$table
));
$triggerName
=
$this
->
_conn
->
quote
(
strtoupper
(
$table
)
.
'_AUTOINCREMENT_PK'
);
return
$this
->
_conn
->
exec
(
"DELETE FROM RDB
\$
TRIGGERS WHERE UPPER(RDB
\$
RELATION_NAME)="
.
$table
.
" AND UPPER(RDB
\$
TRIGGER_NAME)="
.
$triggerName
);
}
/**
* create a new table
*
* @param string $name Name of the database that should be created
* @param array $fields Associative array that contains the definition of each field of the new table
* The indexes of the array entries are the names of the fields of the table an
* the array entry values are associative arrays like those that are meant to be
* passed with the field definitions to get[Type]Declaration() functions.
*
* Example
* array(
*
* 'id' => array(
* 'type' => 'integer',
* 'unsigned' => 1,
* 'notnull' => 1,
* 'default' => 0,
* ),
* 'name' => array(
* 'type' => 'text',
* 'length' => 12,
* ),
* 'description' => array(
* 'type' => 'text',
* 'length' => 12,
* )
* );
* @param array $options An associative array of table options:
*
* @return void
*/
public
function
createTable
(
$name
,
array
$fields
,
array
$options
=
array
())
{
parent
::
createTable
(
$name
,
$fields
,
$options
);
// TODO ? $this->_silentCommit();
foreach
(
$fields
as
$field_name
=>
$field
)
{
if
(
!
empty
(
$field
[
'autoincrement'
]))
{
//create PK constraint
$pk_definition
=
array
(
'fields'
=>
array
(
$field_name
=>
array
()),
'primary'
=>
true
,
);
//$pk_name = $name.'_PK';
$pk_name
=
null
;
$result
=
$this
->
createConstraint
(
$name
,
$pk_name
,
$pk_definition
);
//create autoincrement sequence + trigger
return
$this
->
_makeAutoincrement
(
$field_name
,
$name
,
1
);
}
}
}
/**
* Check if planned changes are supported
*
* @param string $name name of the database that should be dropped
* @return void
*/
public
function
checkSupportedChanges
(
&
$changes
)
{
foreach
(
$changes
as
$change_name
=>
$change
)
{
switch
(
$change_name
)
{
case
'notnull'
:
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'it is not supported changes to field not null constraint'
);
case
'default'
:
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'it is not supported changes to field default value'
);
case
'length'
:
case
'unsigned'
:
case
'type'
:
case
'declaration'
:
case
'definition'
:
break
;
default
:
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'it is not supported change of type'
.
$change_name
);
}
}
return
true
;
}
/**
* drop an existing table
*
* @param string $name name of the table that should be dropped
* @return mixed MDB2_OK on success, a MDB2 error on failure
* @access public
*/
public
function
dropTable
(
$name
)
{
$result
=
$this
->
_dropAutoincrement
(
$name
);
$result
=
parent
::
dropTable
(
$name
);
//$this->_silentCommit();
return
$result
;
}
/**
* alter an existing table
*
* @param string $name name of the table that is intended to be changed.
* @param array $changes associative array that contains the details of each type
* of change that is intended to be performed. The types of
* changes that are currently supported are defined as follows:
*
* name
*
* New name for the table.
*
* add
*
* Associative array with the names of fields to be added as
* indexes of the array. The value of each entry of the array
* should be set to another associative array with the properties
* of the fields to be added. The properties of the fields should
* be the same as defined by the Metabase parser.
*
*
* remove
*
* Associative array with the names of fields to be removed as indexes
* of the array. Currently the values assigned to each entry are ignored.
* An empty array should be used for future compatibility.
*
* rename
*
* Associative array with the names of fields to be renamed as indexes
* of the array. The value of each entry of the array should be set to
* another associative array with the entry named name with the new
* field name and the entry named Declaration that is expected to contain
* the portion of the field declaration already in DBMS specific SQL code
* as it is used in the CREATE TABLE statement.
*
* change
*
* Associative array with the names of the fields to be changed as indexes
* of the array. Keep in mind that if it is intended to change either the
* name of a field and any other properties, the change array entries
* should have the new names of the fields as array indexes.
*
* The value of each entry of the array should be set to another associative
* array with the properties of the fields to that are meant to be changed as
* array entries. These entries should be assigned to the new values of the
* respective properties. The properties of the fields should be the same
* as defined by the Metabase parser.
*
* Example
* array(
* 'name' => 'userlist',
* 'add' => array(
* 'quota' => array(
* 'type' => 'integer',
* 'unsigned' => 1
* )
* ),
* 'remove' => array(
* 'file_limit' => array(),
* 'time_limit' => array()
* ),
* 'change' => array(
* 'name' => array(
* 'length' => '20',
* 'definition' => array(
* 'type' => 'text',
* 'length' => 20,
* ),
* )
* ),
* 'rename' => array(
* 'sex' => array(
* 'name' => 'gender',
* 'definition' => array(
* 'type' => 'text',
* 'length' => 1,
* 'default' => 'M',
* ),
* )
* )
* )
*
* @param boolean $check indicates whether the function should just check if the DBMS driver
* can perform the requested table alterations if the value is true or
* actually perform them otherwise.
* @return void
*/
public
function
alterTable
(
$name
,
array
$changes
,
$check
=
false
)
{
foreach
(
$changes
as
$changeName
=>
$change
)
{
switch
(
$changeName
)
{
case
'add'
:
case
'remove'
:
case
'rename'
:
break
;
case
'change'
:
foreach
(
$changes
[
'change'
]
as
$field
)
{
$this
->
checkSupportedChanges
(
$field
);
}
break
;
default
:
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'change type '
.
$changeName
.
' not yet supported'
);
}
}
if
(
$check
)
{
return
true
;
}
$query
=
''
;
if
(
!
empty
(
$changes
[
'add'
])
&&
is_array
(
$changes
[
'add'
]))
{
foreach
(
$changes
[
'add'
]
as
$fieldName
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
}
$query
.=
'ADD '
.
$this
->
getDeclaration
(
$fieldName
,
$field
);
}
}
if
(
!
empty
(
$changes
[
'remove'
])
&&
is_array
(
$changes
[
'remove'
]))
{
foreach
(
$changes
[
'remove'
]
as
$field_name
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
}
$field_name
=
$this
->
_conn
->
quoteIdentifier
(
$field_name
,
true
);
$query
.=
'DROP '
.
$field_name
;
}
}
if
(
!
empty
(
$changes
[
'rename'
])
&&
is_array
(
$changes
[
'rename'
]))
{
foreach
(
$changes
[
'rename'
]
as
$field_name
=>
$field
)
{
if
(
$query
)
{
$query
.=
', '
;
}
$field_name
=
$this
->
_conn
->
quoteIdentifier
(
$field_name
,
true
);
$query
.=
'ALTER '
.
$field_name
.
' TO '
.
$this
->
_conn
->
quoteIdentifier
(
$field
[
'name'
],
true
);
}
}
if
(
!
empty
(
$changes
[
'change'
])
&&
is_array
(
$changes
[
'change'
]))
{
// missing support to change DEFAULT and NULLability
foreach
(
$changes
[
'change'
]
as
$fieldName
=>
$field
)
{
$this
->
checkSupportedChanges
(
$field
);
if
(
$query
)
{
$query
.=
', '
;
}
$this
->
_conn
->
loadModule
(
'Datatype'
,
null
,
true
);
$field_name
=
$this
->
_conn
->
quoteIdentifier
(
$fieldName
,
true
);
$query
.=
'ALTER '
.
$field_name
.
' TYPE '
.
$this
->
getTypeDeclaration
(
$field
[
'definition'
]);
}
}
if
(
!
strlen
(
$query
))
{
return
false
;
}
$name
=
$this
->
_conn
->
quoteIdentifier
(
$name
,
true
);
$result
=
$this
->
_conn
->
exec
(
'ALTER TABLE '
.
$name
.
' '
.
$query
);
$this
->
_silentCommit
();
return
$result
;
}
/**
* Get the stucture of a field into an array
*
* @param string $table name of the table on which the index is to be created
* @param string $name name of the index to be created
* @param array $definition associative array that defines properties of the index to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the index fields as array
* indexes. Each entry of this array is set to another type of associative
* array that specifies properties of the index that are specific to
* each field.
*
* Currently, only the sorting property is supported. It should be used
* to define the sorting direction of the index. It may be set to either
* ascending or descending.
*
* Not all DBMS support index sorting direction configuration. The DBMS
* drivers of those that do not support it ignore this property. Use the
* function support() to determine whether the DBMS driver can manage indexes.
* Example
* array(
* 'fields' => array(
* 'user_name' => array(
* 'sorting' => 'ascending'
* ),
* 'last_login' => array()
* )
* )
* @return void
*/
public
function
createIndexSql
(
$table
,
$name
,
array
$definition
)
{
$query
=
'CREATE'
;
$query_sort
=
''
;
foreach
(
$definition
[
'fields'
]
as
$field
)
{
if
(
!
strcmp
(
$query_sort
,
''
)
&&
isset
(
$field
[
'sorting'
]))
{
switch
(
$field
[
'sorting'
])
{
case
'ascending'
:
$query_sort
=
' ASC'
;
break
;
case
'descending'
:
$query_sort
=
' DESC'
;
break
;
}
}
}
$table
=
$this
->
_conn
->
quoteIdentifier
(
$table
,
true
);
$name
=
$this
->
_conn
->
quoteIdentifier
(
$this
->
_conn
->
formatter
->
getIndexName
(
$name
),
true
);
$query
.=
$query_sort
.
' INDEX '
.
$name
.
' ON '
.
$table
;
$fields
=
array
();
foreach
(
array_keys
(
$definition
[
'fields'
])
as
$field
)
{
$fields
[]
=
$this
->
_conn
->
quoteIdentifier
(
$field
,
true
);
}
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
return
$query
;
}
/**
* create a constraint on a table
*
* @param string $table name of the table on which the constraint is to be created
* @param string $name name of the constraint to be created
* @param array $definition associative array that defines properties of the constraint to be created.
* Currently, only one property named FIELDS is supported. This property
* is also an associative with the names of the constraint fields as array
* constraints. Each entry of this array is set to another type of associative
* array that specifies properties of the constraint that are specific to
* each field.
*
* Example
* array(
* 'fields' => array(
* 'user_name' => array(),
* 'last_login' => array(),
* )
* )
* @return void
*/
public
function
createConstraint
(
$table
,
$name
,
$definition
)
{
$table
=
$this
->
_conn
->
quoteIdentifier
(
$table
,
true
);
if
(
!
empty
(
$name
))
{
$name
=
$this
->
_conn
->
quoteIdentifier
(
$this
->
_conn
->
formatter
->
getIndexName
(
$name
),
true
);
}
$query
=
"ALTER TABLE
$table
ADD"
;
if
(
!
empty
(
$definition
[
'primary'
]))
{
if
(
!
empty
(
$name
))
{
$query
.=
' CONSTRAINT '
.
$name
;
}
$query
.=
' PRIMARY KEY'
;
}
else
{
$query
.=
' CONSTRAINT '
.
$name
;
if
(
!
empty
(
$definition
[
'unique'
]))
{
$query
.=
' UNIQUE'
;
}
}
$fields
=
array
();
foreach
(
array_keys
(
$definition
[
'fields'
])
as
$field
)
{
$fields
[]
=
$this
->
_conn
->
quoteIdentifier
(
$field
,
true
);
}
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
$result
=
$this
->
_conn
->
exec
(
$query
);
// TODO ? $this->_silentCommit();
return
$result
;
}
/**
* create sequence
*
* @param string $seqName name of the sequence to be created
* @param string $start start value of the sequence; default is 1
* @param array $options An associative array of table options:
* array(
* 'comment' => 'Foo',
* 'charset' => 'utf8',
* 'collate' => 'utf8_unicode_ci',
* );
* @return boolean
*/
public
function
createSequence
(
$seqName
,
$start
=
1
,
array
$options
=
array
())
{
$sequenceName
=
$this
->
_conn
->
formatter
->
getSequenceName
(
$seqName
);
$this
->
_conn
->
exec
(
'CREATE GENERATOR '
.
$sequenceName
);
try
{
$this
->
_conn
->
exec
(
'SET GENERATOR '
.
$sequenceName
.
' TO '
.
(
$start
-
1
));
return
true
;
}
catch
(
Doctrine\DBAL\ConnectionException
$e
)
{
try
{
$this
->
dropSequence
(
$seqName
);
}
catch
(
Doctrine\DBAL\ConnectionException
$e
)
{
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'Could not drop inconsistent sequence table'
);
}
}
throw
\Doctrine\Common\DoctrineException
::
updateMe
(
'could not create sequence table'
);
}
/**
* drop existing sequence
*
* @param string $seqName name of the sequence to be dropped
* @return void
*/
public
function
dropSequenceSql
(
$seqName
)
{
$sequenceName
=
$this
->
_conn
->
formatter
->
getSequenceName
(
$seqName
);
$sequenceName
=
$this
->
_conn
->
quote
(
$sequenceName
);
$query
=
"DELETE FROM RDB
\$
GENERATORS WHERE UPPER(RDB
\$
GENERATOR_NAME)="
.
$sequenceName
;
return
$query
;
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Schema/InformixSchemaManager.php
deleted
100644 → 0
View file @
ac8492d2
<?php
/*
* $Id$
*
* 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.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
namespace
Doctrine\DBAL\Schema
;
/**
* xxx
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @author Lorenzo Alberton <l.alberton@quipo.it> (PEAR MDB2 Interbase driver)
* @version $Revision$
* @since 2.0
*/
class
InformixSchemaManager
extends
AbstractSchemaManager
{
protected
$sql
=
array
(
'listTables'
=>
"SELECT tabname,tabtype FROM systables WHERE tabtype IN ('T','V') AND owner != 'informix'"
,
'listColumns'
=>
"SELECT c.colname, c.coltype, c.collength, d.default, c.colno
FROM syscolumns c, systables t,outer sysdefaults d
WHERE c.tabid = t.tabid AND d.tabid = t.tabid AND d.colno = c.colno
AND tabname='%s' ORDER BY c.colno"
,
'listPk'
=>
"SELECT part1, part2, part3, part4, part5, part6, part7, part8 FROM
systables t, sysconstraints s, sysindexes i WHERE t.tabname='%s'
AND s.tabid=t.tabid AND s.constrtype='P'
AND i.idxname=s.idxname"
,
'listForeignKeys'
=>
"SELECT tr.tabname,updrule,delrule,
i.part1 o1,i2.part1 d1,i.part2 o2,i2.part2 d2,i.part3 o3,i2.part3 d3,i.part4 o4,i2.part4 d4,
i.part5 o5,i2.part5 d5,i.part6 o6,i2.part6 d6,i.part7 o7,i2.part7 d7,i.part8 o8,i2.part8 d8
from systables t,sysconstraints s,sysindexes i,
sysreferences r,systables tr,sysconstraints s2,sysindexes i2
where t.tabname='%s'
and s.tabid=t.tabid and s.constrtype='R' and r.constrid=s.constrid
and i.idxname=s.idxname and tr.tabid=r.ptabid
and s2.constrid=r.primary and i2.idxname=s2.idxname"
,
);
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment