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
f10d1fca
Commit
f10d1fca
authored
Aug 21, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
58f09c40
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
352 additions
and
0 deletions
+352
-0
Common.php
Doctrine/Connection/Common.php
+25
-0
Exception.php
Doctrine/Connection/Exception.php
+13
-0
Firebird.php
Doctrine/Connection/Firebird.php
+20
-0
Informix.php
Doctrine/Connection/Informix.php
+6
-0
Mssql.php
Doctrine/Connection/Mssql.php
+72
-0
Mysql.php
Doctrine/Connection/Mysql.php
+159
-0
Oracle.php
Doctrine/Connection/Oracle.php
+32
-0
Pgsql.php
Doctrine/Connection/Pgsql.php
+18
-0
Sqlite.php
Doctrine/Connection/Sqlite.php
+7
-0
No files found.
Doctrine/Connection/Common.php
0 → 100644
View file @
f10d1fca
<?php
/**
* standard connection, the parent of pgsql, mysql and sqlite
*/
class
Doctrine_Connection_Common
extends
Doctrine_Connection
{
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
*/
public
function
modifyLimitQuery
(
$query
,
$limit
=
false
,
$offset
=
false
)
{
if
(
$limit
&&
$offset
)
{
$query
.=
" LIMIT "
.
$limit
.
" OFFSET "
.
$offset
;
}
elseif
(
$limit
&&
!
$offset
)
{
$query
.=
" LIMIT "
.
$limit
;
}
elseif
(
!
$limit
&&
$offset
)
{
$query
.=
" LIMIT 999999999999 OFFSET "
.
$offset
;
}
return
$query
;
}
}
?>
Doctrine/Connection/Exception.php
0 → 100644
View file @
f10d1fca
<?php
Doctrine
::
autoload
(
'Doctrine_Exception'
);
/**
* thrown when user tries to get the current
* connection and there are no open connections
*/
class
Doctrine_Connection_Exception
extends
Doctrine_Exception
{
public
function
__construct
()
{
parent
::
__construct
(
"There are no opened connections. Use
Doctrine_Manager::getInstance()->openConnection() to open a new connection."
,
Doctrine
::
ERR_NO_SESSIONS
);
}
}
?>
Doctrine/Connection/Firebird.php
0 → 100644
View file @
f10d1fca
<?php
/**
* firebird driver
*/
class
Doctrine_Connection_Firebird
extends
Doctrine_Connection
{
public
function
modifyLimitQuery
(
$query
,
$limit
,
$offset
)
{
return
preg_replace
(
"/([\s(])*SELECT/i"
,
"
\\
1SELECT TOP(
$from
,
$count
)"
,
$query
);
}
/**
* returns the next value in the given sequence
* @param string $sequence
* @return integer
*/
public
function
getNextID
(
$sequence
)
{
$stmt
=
$this
->
query
(
"SELECT UNIQUE FROM "
.
$sequence
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
return
$data
[
0
];
}
}
?>
Doctrine/Connection/Informix.php
0 → 100644
View file @
f10d1fca
<?php
/**
* informix database driver
*/
class
Doctrine_Connection_Informix
extends
Doctrine_Connection
{
}
?>
Doctrine/Connection/Mssql.php
0 → 100644
View file @
f10d1fca
<?php
/**
* mssql driver
*/
class
Doctrine_Connection_Mssql
extends
Doctrine_Connection
{
/**
* returns the next value in the given sequence
* @param string $sequence
* @return integer
*/
public
function
getNextID
(
$sequence
)
{
$this
->
query
(
"INSERT INTO
$sequence
(vapor) VALUES (0)"
);
$stmt
=
$this
->
query
(
"SELECT @@IDENTITY FROM
$sequence
"
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
return
$data
[
0
];
}
/**
* Adds an adapter-specific LIMIT clause to the SELECT statement.
* [ borrowed from Zend Framework ]
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
* @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html
* @return string
*/
public
function
modifyLimitQuery
(
$query
,
$limit
,
$offset
)
{
if
(
$limit
)
{
// we need the starting SELECT clause for later
$select
=
'SELECT '
;
if
(
preg_match
(
'/^[[:space:]*SELECT[[:space:]]*DISTINCT/i'
,
$query
,
$matches
)
==
1
)
$select
.=
'DISTINCT '
;
$length
=
strlen
(
$select
);
// is there an offset?
if
(
!
$offset
)
{
// no offset, it's a simple TOP count
return
"
$select
TOP
$count
"
.
substr
(
$query
,
$length
);
}
// the total of the count **and** the offset, combined.
// this will be used in the "internal" portion of the
// hacked-up statement.
$total
=
$count
+
$offset
;
// build the "real" order for the external portion.
$order
=
implode
(
','
,
$parts
[
'order'
]);
// build a "reverse" order for the internal portion.
$reverse
=
$order
;
$reverse
=
str_ireplace
(
" ASC"
,
"
\xFF
"
,
$reverse
);
$reverse
=
str_ireplace
(
" DESC"
,
" ASC"
,
$reverse
);
$reverse
=
str_ireplace
(
"
\xFF
"
,
" DESC"
,
$reverse
);
// create a main statement that replaces the SELECT
// with a SELECT TOP
$main
=
"
\n
$select
TOP
$total
"
.
substr
(
$query
,
$length
)
.
"
\n
"
;
// build the hacked-up statement.
// do we really need the "as" aliases here?
$query
=
"SELECT * FROM ("
.
"SELECT TOP
$count
* FROM (
$main
) AS select_limit_rev ORDER BY
$reverse
"
.
") AS select_limit ORDER BY
$order
"
;
}
return
$query
;
}
}
?>
Doctrine/Connection/Mysql.php
0 → 100644
View file @
f10d1fca
<?php
require_once
(
"Common.php"
);
/**
* mysql driver
*/
class
Doctrine_Connection_Mysql
extends
Doctrine_Connection_Common
{
/**
* the constructor
* @param PDO $pdo -- database handle
*/
public
function
__construct
(
Doctrine_Manager
$manager
,
PDO
$pdo
)
{
$pdo
->
setAttribute
(
PDO
::
ATTR_EMULATE_PREPARES
,
true
);
parent
::
__construct
(
$manager
,
$pdo
);
}
/**
* deletes all data access object from the collection
* @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_DQL_Parser($this);
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
* @return array
*/
public
function
getMaximumValues2
(
array
$names
)
{
$values
=
array
();
foreach
(
$names
as
$name
)
{
$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;
}
*/
}
?>
Doctrine/Connection/Oracle.php
0 → 100644
View file @
f10d1fca
<?php
/**
* oracle driver
*/
class
Doctrine_Connection_Oracle
extends
Doctrine_Connection
{
/**
* Adds an driver-specific LIMIT clause to the query
*
* @param string $query
* @param mixed $limit
* @param mixed $offset
*/
public
function
modifyLimitQuery
(
$query
,
$limit
,
$offset
)
{
$e
=
explode
(
"select "
,
strtolower
(
$query
));
$e2
=
explode
(
" from "
,
$e
[
1
]);
$fields
=
$e2
[
0
];
$query
=
"SELECT
$fields
FROM (SELECT rownum as linenum,
$fields
FROM (
$query
) WHERE rownum <= (
$offset
+
$limit
)) WHERE linenum >= "
.++
$offset
;
return
$query
;
}
/**
* returns the next value in the given sequence
* @param string $sequence
* @return integer
*/
public
function
getNextID
(
$sequence
)
{
$stmt
=
$this
->
query
(
"SELECT
$sequence
.nextval FROM dual"
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
return
$data
[
0
];
}
}
?>
Doctrine/Connection/Pgsql.php
0 → 100644
View file @
f10d1fca
<?php
require_once
(
"Common.php"
);
/**
* pgsql driver
*/
class
Doctrine_Connection_Pgsql
extends
Doctrine_Connection_Common
{
/**
* returns the next value in the given sequence
* @param string $sequence
* @return integer
*/
public
function
getNextID
(
$sequence
)
{
$stmt
=
$this
->
query
(
"SELECT NEXTVAL('
$sequence
')"
);
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
return
$data
[
0
];
}
}
?>
Doctrine/Connection/Sqlite.php
0 → 100644
View file @
f10d1fca
<?php
require_once
(
"Common.php"
);
/**
* sqlite driver
*/
class
Doctrine_Connection_Sqlite
extends
Doctrine_Connection_Common
{
}
?>
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