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
dd4aff4a
Commit
dd4aff4a
authored
Oct 20, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SQL function abstraction started on some drivers, developed mssql and oracle datadict drivers
parent
cfac6410
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
186 additions
and
142 deletions
+186
-142
Mysql.php
lib/Doctrine/Connection/Mysql.php
+8
-138
Oracle.php
lib/Doctrine/Connection/Oracle.php
+39
-0
Pgsql.php
lib/Doctrine/Connection/Pgsql.php
+11
-3
Mssql.php
lib/Doctrine/DataDict/Mssql.php
+127
-0
Oracle.php
lib/Doctrine/DataDict/Oracle.php
+1
-1
No files found.
lib/Doctrine/Connection/Mysql.php
View file @
dd4aff4a
...
@@ -24,146 +24,16 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
...
@@ -24,146 +24,16 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
return
'RLIKE'
;
return
'RLIKE'
;
}
}
/**
/**
* deletes all data access object from the collection
* Returns string to concatenate two or more string parameters
* @param Doctrine_Collection $coll
*/
/**
public function deleteCollection(Doctrine_Collection $coll) {
$a = $coll->getTable()->getCompositePaths();
$a = array_merge(array($coll->getTable()->getComponentName()),$a);
$graph = new Doctrine_Query();
foreach($coll as $k=>$record) {
switch($record->getState()):
case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_CLEAN:
$ids[] = $record->getID();
break;
endswitch;
}
if(empty($ids))
return array();
$graph->parseQuery("FROM ".implode(", ",$a)." WHERE ".$coll->getTable()->getTableName().".id IN(".implode(", ",$ids).")");
$query = $graph->buildDelete();
$this->getDBH()->query($query);
return $ids;
}
*/
/**
* returns maximum identifier values
*
*
* @param array $names an array of component names
* @param string $value1
* @return array
* @param string $value2
* @param string $values...
* @return string a concatenation of two or more strings
*/
*/
public
function
getMaximumValues2
(
array
$names
)
{
public
function
concat
(
$value1
,
$value2
)
{
$values
=
array
();
$args
=
func_get_args
();
foreach
(
$names
as
$name
)
{
return
"CONCAT("
.
implode
(
', '
,
$args
)
.
")"
;
$table
=
$this
->
tables
[
$name
];
$keys
=
$table
->
getPrimaryKeys
();
$tablename
=
$table
->
getTableName
();
if
(
count
(
$keys
)
==
1
&&
$keys
[
0
]
==
$table
->
getIdentifier
())
{
// record uses auto_increment column
$sql
[]
=
"SELECT MAX("
.
$tablename
.
"."
.
$table
->
getIdentifier
()
.
") as
$tablename
FROM "
.
$tablename
;
$values
[
$tablename
]
=
0
;
$array
[]
=
$tablename
;
}
}
$sql
=
implode
(
" UNION "
,
$sql
);
$stmt
=
$this
->
getDBH
()
->
query
(
$sql
);
$data
=
$stmt
->
fetchAll
(
PDO
::
FETCH_NUM
);
foreach
(
$data
as
$k
=>
$v
)
{
$values
[
$array
[
$k
]]
=
$v
[
0
];
}
return
$values
;
}
/**
* bulkInsert
* inserts all the objects in the pending insert list into database
* TODO: THIS IS NOT WORKING YET AS THERE ARE BUGS IN COMPONENTS USING SELF-REFERENCENCING
*
* @return boolean
*/
/**
public function bulkInsert() {
if(empty($this->insert))
return false;
foreach($this->insert as $name => $inserts) {
if( ! isset($inserts[0]))
continue;
$record = $inserts[0];
$table = $record->getTable();
$seq = $table->getSequenceName();
$keys = $table->getPrimaryKeys();
$marks = array();
$params = array();
foreach($inserts as $k => $record) {
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
// listen the onPreInsert event
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record);
$array = $record->getPrepared();
if(isset($this->validator)) {
if( ! $this->validator->validateRecord($record)) {
continue;
}
}
$key = implode(", ",array_keys($array));
if( ! isset($params[$key]))
$params[$key] = array();
$marks[$key][] = "(".substr(str_repeat("?, ",count($array)),0,-2).")";
$params[$key] = array_merge($params[$key], array_values($array));
// listen the onInsert event
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record);
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
}
if( ! empty($marks)) {
foreach($marks as $key => $list) {
$query = "INSERT INTO ".$table->getTableName()." (".$key.") VALUES ".implode(", ", $list);
$stmt = $this->getDBH()->prepare($query);
$stmt->execute($params[$key]);
}
}
}
if(count($keys) == 1 && $keys[0] == $table->getIdentifier()) {
// record uses auto_increment column
$sql = "SELECT MAX(".$table->getIdentifier().") FROM ".$record->getTable()->getTableName();
$stmt = $this->getDBH()->query($sql);
$data = $stmt->fetch(PDO::FETCH_NUM);
$id = $data[0];
$stmt->closeCursor();
foreach(array_reverse($inserts) as $record) {
$record->setID((int) $id);
$id--;
}
}
}
$this->insert = array();
return true;
}
*/
}
}
lib/Doctrine/Connection/Oracle.php
View file @
dd4aff4a
...
@@ -28,5 +28,44 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
...
@@ -28,5 +28,44 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
return
$data
[
0
];
return
$data
[
0
];
}
}
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time:
* - CURRENT_TIMESTAMP (date and time, TIMESTAMP type)
* - CURRENT_DATE (date, DATE type)
* - CURRENT_TIME (time, TIME type)
*
* @return string to call a variable with the current timestamp
* @access public
*/
function
now
(
$type
=
'timestamp'
)
{
switch
(
$type
)
{
case
'date'
:
case
'time'
:
case
'timestamp'
:
default
:
return
'TO_CHAR(CURRENT_TIMESTAMP, \'YYYY-MM-DD HH24:MI:SS\')'
;
}
}
/**
* substring
*
* @return string SQL substring function with given parameters
*/
function
substring
(
$value
,
$position
=
1
,
$length
=
null
)
{
if
(
$length
!==
null
)
return
"SUBSTR(
$value
,
$position
,
$length
)"
;
return
"SUBSTR(
$value
,
$position
)"
;
}
/**
* random
*
* @return string an oracle SQL string that generates a float between 0 and 1
*/
function
random
()
{
return
'dbms_random.value'
;
}
}
}
lib/Doctrine/Connection/Pgsql.php
View file @
dd4aff4a
...
@@ -15,13 +15,21 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
...
@@ -15,13 +15,21 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
return
$data
[
0
];
return
$data
[
0
];
}
}
/**
/**
* returns the regular expression operator
* getRegexpOperator
* (implemented by the connection drivers)
*
*
* @return string
* @return string
the regular expression operator
*/
*/
public
function
getRegexpOperator
()
{
public
function
getRegexpOperator
()
{
return
'SIMILAR TO'
;
return
'SIMILAR TO'
;
}
}
/**
* return string to call a function to get random value inside an SQL statement
*
* @return return string to generate float between 0 and 1
* @access public
*/
public
function
random
()
{
return
'RANDOM()'
;
}
}
}
lib/Doctrine/DataDict/Mssql.php
View file @
dd4aff4a
...
@@ -24,10 +24,137 @@
...
@@ -24,10 +24,137 @@
* @url http://www.phpdoctrine.com
* @url http://www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @author Konsta Vesterinen
* @author Konsta Vesterinen
* @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
* @version $Id$
* @version $Id$
*/
*/
class
Doctrine_DataDict_Mssql
extends
Doctrine_DataDict
{
class
Doctrine_DataDict_Mssql
extends
Doctrine_DataDict
{
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
*
* @param array $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
*
* length
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
*
* default
* Text value to be used as default for this field.
*
* notnull
* Boolean flag that indicates whether this field is constrained
* to not be set to null.
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
*/
public
function
getTypeDeclaration
(
$field
)
{
switch
(
$field
[
'type'
])
{
case
'text'
:
$length
=
!
empty
(
$field
[
'length'
])
?
$field
[
'length'
]
:
false
;
$fixed
=
!
empty
(
$field
[
'fixed'
])
?
$field
[
'fixed'
]
:
false
;
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR('
.
$db
->
options
[
'default_text_field_length'
]
.
')'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
);
case
'clob'
:
if
(
!
empty
(
$field
[
'length'
]))
{
$length
=
$field
[
'length'
];
if
(
$length
<=
8000
)
{
return
'VARCHAR('
.
$length
.
')'
;
}
}
return
'TEXT'
;
case
'blob'
:
if
(
!
empty
(
$field
[
'length'
]))
{
$length
=
$field
[
'length'
];
if
(
$length
<=
8000
)
{
return
"VARBINARY(
$length
)"
;
}
}
return
'IMAGE'
;
case
'integer'
:
return
'INT'
;
case
'boolean'
:
return
'BIT'
;
case
'date'
:
return
'CHAR ('
.
strlen
(
'YYYY-MM-DD'
)
.
')'
;
case
'time'
:
return
'CHAR ('
.
strlen
(
'HH:MM:SS'
)
.
')'
;
case
'timestamp'
:
return
'CHAR ('
.
strlen
(
'YYYY-MM-DD HH:MM:SS'
)
.
')'
;
case
'float'
:
return
'FLOAT'
;
case
'decimal'
:
$length
=
!
empty
(
$field
[
'length'
])
?
$field
[
'length'
]
:
18
;
return
'DECIMAL('
.
$length
.
','
.
$db
->
options
[
'decimal_places'
]
.
')'
;
}
return
''
;
}
/**
* Maps a native array description of a field to a MDB2 datatype and length
*
* @param array $field native field description
* @return array containing the various possible types, length, sign, fixed
*/
public
function
mapNativeDatatype
(
$field
)
{
$db_type
=
preg_replace
(
'/\d/'
,
''
,
strtolower
(
$field
[
'type'
])
);
$length
=
$field
[
'length'
];
if
((
int
)
$length
<=
0
)
{
$length
=
null
;
}
$type
=
array
();
// todo: unsigned handling seems to be missing
$unsigned
=
$fixed
=
null
;
switch
(
$db_type
)
{
case
'bit'
:
$type
[
0
]
=
'boolean'
;
break
;
case
'int'
:
$type
[
0
]
=
'integer'
;
break
;
case
'datetime'
:
$type
[
0
]
=
'timestamp'
;
break
;
case
'float'
:
case
'real'
:
case
'numeric'
:
$type
[
0
]
=
'float'
;
break
;
case
'decimal'
:
case
'money'
:
$type
[
0
]
=
'decimal'
;
break
;
case
'text'
:
case
'varchar'
:
$fixed
=
false
;
case
'char'
:
$type
[
0
]
=
'text'
;
if
(
$length
==
'1'
)
{
$type
[]
=
'boolean'
;
if
(
preg_match
(
'/^[is|has]/'
,
$field
[
'name'
]))
{
$type
=
array_reverse
(
$type
);
}
}
elseif
(
strstr
(
$db_type
,
'text'
))
{
$type
[]
=
'clob'
;
}
if
(
$fixed
!==
false
)
{
$fixed
=
true
;
}
break
;
case
'image'
:
case
'varbinary'
:
$type
[]
=
'blob'
;
$length
=
null
;
break
;
default
:
throw
new
Doctrine_DataDict_Mssql_Exception
(
'mapNativeDatatype: unknown database attribute type: '
.
$db_type
);
}
return
array
(
$type
,
$length
,
$unsigned
,
$fixed
);
}
/**
/**
* lists all databases
* lists all databases
*
*
...
...
lib/Doctrine/DataDict/Oracle.php
View file @
dd4aff4a
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
* @version $Id$
* @version $Id$
*/
*/
class
Doctrine_DataDict_
Mssql
extends
Doctrine_DataDict
{
class
Doctrine_DataDict_
Oracle
extends
Doctrine_DataDict
{
/**
/**
* Obtain DBMS specific SQL code portion needed to declare an text type
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
* field to be used in statements like CREATE TABLE.
...
...
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