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
53e9b06f
Commit
53e9b06f
authored
Oct 30, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved connection driver functionality to expression drivers
parent
7ef869ee
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
209 additions
and
174 deletions
+209
-174
Connection.php
lib/Doctrine/Connection.php
+33
-46
Firebird.php
lib/Doctrine/Connection/Firebird.php
+5
-0
Informix.php
lib/Doctrine/Connection/Informix.php
+6
-1
Mssql.php
lib/Doctrine/Connection/Mssql.php
+5
-1
Mysql.php
lib/Doctrine/Connection/Mysql.php
+5
-10
Oracle.php
lib/Doctrine/Connection/Oracle.php
+6
-38
Pgsql.php
lib/Doctrine/Connection/Pgsql.php
+5
-17
Sqlite.php
lib/Doctrine/Connection/Sqlite.php
+2
-36
Profiler.php
lib/Doctrine/DB/Profiler.php
+5
-1
Expression.php
lib/Doctrine/Expression.php
+22
-9
Mysql.php
lib/Doctrine/Expression/Mysql.php
+10
-1
Oracle.php
lib/Doctrine/Expression/Oracle.php
+42
-0
Pgsql.php
lib/Doctrine/Expression/Pgsql.php
+18
-1
Sqlite.php
lib/Doctrine/Expression/Sqlite.php
+45
-13
No files found.
lib/Doctrine/Connection.php
View file @
53e9b06f
...
...
@@ -44,6 +44,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
*/
protected
$tables
=
array
();
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
;
/**
* @var array $supported an array containing all features this driver supports,
* keys representing feature names and values as
* one of the following (true, false, 'emulated')
*/
protected
$supported
=
array
();
/**
* @var Doctrine_DataDict $dataDict
*/
...
...
@@ -51,19 +61,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
private
static
$availibleDrivers
=
array
(
"Mysql"
,
"Pgsql"
,
"Oracle"
,
"Informix"
,
"Mssql"
,
"Sqlite"
,
"Firebird"
'Mysql'
,
'Pgsql'
,
'Oracle'
,
'Informix'
,
'Mssql'
,
'Sqlite'
,
'Firebird'
);
private
static
$driverMap
=
array
(
'oracle'
=>
'oci8'
,
'postgres'
=>
'pgsql'
,
'oci'
=>
'oci8'
,
'sqlite2'
=>
'sqlite'
,
'sqlite3'
=>
'sqlite'
);
/**
* the constructor
...
...
@@ -84,6 +89,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$this
->
getAttribute
(
Doctrine
::
ATTR_LISTENER
)
->
onOpen
(
$this
);
}
/**
* getName
*
* @return string returns the name of this driver
*/
public
function
getName
()
{
return
$this
->
driverName
;
}
/**
* quoteIdentifier
*
...
...
@@ -145,28 +159,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
if
(
isset
(
$this
->
dataDict
))
return
$this
->
dataDict
;
$driver
=
$this
->
dbh
->
getAttribute
(
PDO
::
ATTR_DRIVER_NAME
);
switch
(
$driver
)
{
case
"mysql"
:
$this
->
dataDict
=
new
Doctrine_DataDict_Mysql
(
$this
->
dbh
);
break
;
case
"sqlite"
:
case
"sqlite2"
:
$this
->
dataDict
=
new
Doctrine_DataDict_Sqlite
(
$this
->
dbh
);
break
;
case
"pgsql"
:
$this
->
dataDict
=
new
Doctrine_DataDict_Pgsql
(
$this
->
dbh
);
break
;
case
"oci"
:
case
"oci8"
:
$this
->
dataDict
=
new
Doctrine_DataDict_Oracle
(
$this
->
dbh
);
break
;
case
"mssql"
:
$this
->
dataDict
=
new
Doctrine_DataDict_Mssql
(
$this
->
dbh
);
break
;
default
:
throw
new
Doctrine_Connection_Exception
(
"No datadict driver availible for "
.
$driver
);
}
$class
=
'Doctrine_DataDict_'
.
$this
->
getName
();
$this
->
dataDict
=
new
$class
(
$this
->
dbh
);
return
$this
->
dataDict
;
}
/**
...
...
@@ -185,16 +180,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public
function
setTransactionIsolation
(
$isolation
)
{
throw
new
Doctrine_Connection_Exception
(
'Transaction isolation levels not supported by this database driver.'
);
}
/**
* getRegexpOperator
* returns the regular expression operator
* (implemented by the connection drivers)
*
* @return string
*/
public
function
getRegexpOperator
()
{
throw
new
Doctrine_Connection_Exception
(
'Regular expression operator is not supported by this database driver.'
);
}
/**
* getTransactionIsolation
*
...
...
@@ -246,9 +232,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
}
/**
* hasTable
* whether or not this connection has table $name initialized
*
* @param
$
mixed $name
* @param mixed $name
* @return boolean
*/
public
function
hasTable
(
$name
)
{
...
...
lib/Doctrine/Connection/Firebird.php
View file @
53e9b06f
...
...
@@ -27,6 +27,11 @@ Doctrine::autoload('Doctrine_Connection');
* @license LGPL
*/
class
Doctrine_Connection_Firebird
extends
Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
=
'Firebird'
;
/**
* Adds an driver-specific LIMIT clause to the query
*
...
...
lib/Doctrine/Connection/Informix.php
View file @
53e9b06f
...
...
@@ -26,4 +26,9 @@ Doctrine::autoload('Doctrine_Connection');
* @url www.phpdoctrine.com
* @license LGPL
*/
class
Doctrine_Connection_Informix
extends
Doctrine_Connection
{
}
class
Doctrine_Connection_Informix
extends
Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
=
'Informix'
;
}
lib/Doctrine/Connection/Mssql.php
View file @
53e9b06f
...
...
@@ -27,6 +27,10 @@ Doctrine::autoload('Doctrine_Connection');
* @license LGPL
*/
class
Doctrine_Connection_Mssql
extends
Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
=
'Mssql'
;
/**
* returns the next value in the given sequence
* @param string $sequence
...
...
lib/Doctrine/Connection/Mysql.php
View file @
53e9b06f
...
...
@@ -27,7 +27,10 @@ Doctrine::autoload('Doctrine_Connection_Common');
* @license LGPL
*/
class
Doctrine_Connection_Mysql
extends
Doctrine_Connection_Common
{
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
=
'Mysql'
;
/**
* the constructor
* @param PDO $pdo -- database handle
...
...
@@ -59,15 +62,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
parent
::
__construct
(
$manager
,
$pdo
);
}
/**
* returns the regular expression operator
* (implemented by the connection drivers)
*
* @return string
*/
public
function
getRegexpOperator
()
{
return
'RLIKE'
;
}
/**
* getTransactionIsolation
*
...
...
lib/Doctrine/Connection/Oracle.php
View file @
53e9b06f
...
...
@@ -27,6 +27,10 @@ Doctrine::autoload('Doctrine_Connection');
* @license LGPL
*/
class
Doctrine_Connection_Oracle
extends
Doctrine_Connection
{
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
=
'Oracle'
;
/**
* Adds an driver-specific LIMIT clause to the query
*
...
...
@@ -78,44 +82,8 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
$data
=
$stmt
->
fetch
(
PDO
::
FETCH_NUM
);
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 @
53e9b06f
...
...
@@ -27,6 +27,10 @@ Doctrine::autoload("Doctrine_Connection_Common");
* @license LGPL
*/
class
Doctrine_Connection_Pgsql
extends
Doctrine_Connection_Common
{
/**
* @var string $driverName the name of this connection driver
*/
protected
$driverName
=
'Pgsql'
;
/**
* returns the next value in the given sequence
* @param string $sequence
...
...
@@ -60,22 +64,6 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$query
=
'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL '
.
$isolation
;
return
$this
->
dbh
->
query
(
$query
);
}
/**
* getRegexpOperator
*
* @return string the regular expression operator
*/
public
function
getRegexpOperator
()
{
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/Connection/Sqlite.php
View file @
53e9b06f
...
...
@@ -29,22 +29,9 @@ Doctrine::autoload("Doctrine_Connection_Common");
class
Doctrine_Connection_Sqlite
extends
Doctrine_Connection_Common
{
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time.
*
* @return string sqlite function as string
* @var string $driverName the name of this connection driver
*/
public
function
now
(
$type
=
'timestamp'
)
{
switch
(
$type
)
{
case
'time'
:
return
'time(\'now\')'
;
case
'date'
:
return
'date(\'now\')'
;
case
'timestamp'
:
default
:
return
'datetime(\'now\')'
;
}
}
protected
$driverName
=
'Sqlite'
;
/**
* Set the transacton isolation level.
*
...
...
@@ -72,27 +59,6 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
$query
=
"PRAGMA read_uncommitted=
$isolation
"
;
return
$this
->
_doQuery
(
$query
,
true
);
}
/**
* return string to call a function to get a substring inside an SQL statement
*
* @return string to call a function to get a substring
* @access public
*/
public
function
substring
(
$value
,
$position
=
1
,
$length
=
null
)
{
if
(
$length
!==
null
)
return
"substr(
$value
,
$position
,
$length
)"
;
return
"substr(
$value
,
$position
,length(
$value
))"
;
}
/**
* return string to call a function to get random value inside an SQL statement
*
* @return string to generate float between 0 and 1
*/
public
function
random
()
{
return
'((RANDOM() + 2147483648) / 4294967296)'
;
}
}
lib/Doctrine/DB/Profiler.php
View file @
53e9b06f
...
...
@@ -26,7 +26,11 @@
* @package Doctrine
*/
class
Doctrine_DB_Profiler
extends
Doctrine_DB_EventListener
{
public
function
onPreQuery
(
Doctrine_DB
$dbh
,
array
$args
)
{
}
private
$queries
;
public
function
onPreQuery
(
Doctrine_DB
$dbh
,
array
$args
)
{
$this
->
queries
[]
=
$args
[
0
];
}
public
function
onQuery
(
Doctrine_DB
$dbh
,
array
$args
)
{
}
public
function
onPrePrepare
(
Doctrine_DB
$dbh
,
array
$args
)
{
}
...
...
lib/Doctrine/Expression.php
View file @
53e9b06f
...
...
@@ -38,6 +38,15 @@ class Doctrine_Expression {
public
function
__construct
(
Doctrine_Connection
$conn
)
{
$this
->
conn
=
$conn
;
}
/**
* regexp
* returns the regular expression operator
*
* @return string
*/
public
function
regexp
()
{
throw
new
Doctrine_Connection_Exception
(
'Regular expression operator is not supported by this database driver.'
);
}
/**
* Returns the average value of a column
*
...
...
@@ -160,7 +169,8 @@ class Doctrine_Expression {
}
/**
* upper
* Returns the string $str with all characters changed to uppercase according to the current character set mapping.
* Returns the string $str with all characters changed to
* uppercase according to the current character set mapping.
*
* @param string $str literal string or column name
* @return string
...
...
@@ -170,7 +180,8 @@ class Doctrine_Expression {
}
/**
* lower
* Returns the string $str with all characters changed to lowercase according to the current character set mapping.
* Returns the string $str with all characters changed to
* lowercase according to the current character set mapping.
*
* @param string $str literal string or column name
* @return string
...
...
@@ -198,16 +209,18 @@ class Doctrine_Expression {
return
'NOW()'
;
}
/**
*
Returns part of a string.
*
return string to call a function to get a substring inside an SQL statement
*
* Note: Not SQL92, but common functionality.
*
* @param string $value the target $value the string or the string column.
* @param int $from extract from this characeter.
* @param int $len extract this amount of characters.
* @return string sql that extracts part of a string.
* SQLite only supports the 2 parameter variant of this function
*
* @param string $value an sql string literal or column name/alias
* @param integer $position where to start the substring portion
* @param integer $length the substring portion length
* @return string SQL substring function with given parameters
*/
public
function
sub
S
tring
(
$value
,
$from
,
$len
=
null
)
{
public
function
sub
s
tring
(
$value
,
$from
,
$len
=
null
)
{
$value
=
$this
->
getIdentifier
(
$value
);
if
(
$len
===
null
)
return
'SUBSTRING('
.
$value
.
' FROM '
.
$from
.
')'
;
...
...
lib/Doctrine/Expression/Mysql.php
View file @
53e9b06f
...
...
@@ -26,4 +26,13 @@ Doctrine::autoload('Doctrine_Expression');
* @url www.phpdoctrine.com
* @license LGPL
*/
class
Doctrine_Expression_Mysql
extends
Doctrine_Expression
{
}
class
Doctrine_Expression_Mysql
extends
Doctrine_Expression
{
/**
* returns the regular expression operator
*
* @return string
*/
public
function
regexp
()
{
return
'RLIKE'
;
}
}
lib/Doctrine/Expression/Oracle.php
View file @
53e9b06f
...
...
@@ -42,4 +42,46 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
$cols
=
$this
->
getIdentifiers
(
$args
);
return
join
(
' || '
,
$cols
);
}
/**
* return string to call a function to get a substring inside an SQL statement
*
* Note: Not SQL92, but common functionality.
*
* @param string $value an sql string literal or column name/alias
* @param integer $position where to start the substring portion
* @param integer $length the substring portion length
* @return string SQL substring function with given parameters
*/
public
function
substring
(
$value
,
$position
=
1
,
$length
=
null
)
{
if
(
$length
!==
null
)
return
"SUBSTR(
$value
,
$position
,
$length
)"
;
return
"SUBSTR(
$value
,
$position
)"
;
}
/**
* 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
*/
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\')'
;
}
}
/**
* random
*
* @return string an oracle SQL string that generates a float between 0 and 1
*/
function
random
()
{
return
'dbms_random.value'
;
}
}
lib/Doctrine/Expression/Pgsql.php
View file @
53e9b06f
...
...
@@ -88,4 +88,21 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
return
join
(
' || '
,
$cols
);
}
/**
* regexp
*
* @return string the regular expression operator
*/
public
function
regexp
()
{
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/Expression/Sqlite.php
View file @
53e9b06f
...
...
@@ -28,22 +28,54 @@ Doctrine::autoload('Doctrine_Expression');
*/
class
Doctrine_Expression_Sqlite
extends
Doctrine_Expression
{
/**
*
Returns part of a string.
*
returns the regular expression operator
*
* Note: Not SQL92, but common functionality. SQLite only supports the 3
* parameter variant of this function, so we are using 2^30-1 as
* artificial length in that case.
* @return string
*/
public
function
regexp
()
{
return
'RLIKE'
;
}
/**
* Return string to call a variable with the current timestamp inside an SQL statement
* There are three special variables for current date and time.
*
* @return string sqlite function as string
*/
public
function
now
(
$type
=
'timestamp'
)
{
switch
(
$type
)
{
case
'time'
:
return
'time(\'now\')'
;
case
'date'
:
return
'date(\'now\')'
;
case
'timestamp'
:
default
:
return
'datetime(\'now\')'
;
}
}
/**
* return string to call a function to get random value inside an SQL statement
*
* @return string to generate float between 0 and 1
*/
public
function
random
()
{
return
'((RANDOM() + 2147483648) / 4294967296)'
;
}
/**
* return string to call a function to get a substring inside an SQL statement
*
* Note: Not SQL92, but common functionality.
*
* SQLite only supports the 2 parameter variant of this function
*
* @param string $value
the target $value the string or the string column.
* @param int
$from extract from this characeter.
* @param int
$len extract this amount of characters.
* @return string
sql that extracts part of a string.
* @param string $value
an sql string literal or column name/alias
* @param int
eger $position where to start the substring portion
* @param int
eger $length the substring portion length
* @return string
SQL substring function with given parameters
*/
public
function
subString
(
$value
,
$from
,
$len
=
null
)
{
$value
=
$this
->
getIdentifier
(
$value
);
if
(
$len
===
null
)
$len
=
1073741823
;
public
function
substring
(
$value
,
$position
=
1
,
$length
=
null
)
{
if
(
$length
!==
null
)
return
'SUBSTR('
.
$value
.
', '
.
$position
.
', '
.
$length
.
')'
;
return
'SUBSTR('
.
$value
.
', '
.
$
from
.
', '
.
$len
.
'
)'
;
return
'SUBSTR('
.
$value
.
', '
.
$
position
.
', LENGTH('
.
$value
.
')
)'
;
}
}
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