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
4928dfef
Commit
4928dfef
authored
Jan 08, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
c8d0a378
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
52 deletions
+61
-52
Connection.php
lib/Doctrine/Connection.php
+6
-0
Export.php
lib/Doctrine/Export.php
+1
-1
Sequence.php
lib/Doctrine/Sequence.php
+1
-1
Firebird.php
lib/Doctrine/Sequence/Firebird.php
+1
-0
Mssql.php
lib/Doctrine/Sequence/Mssql.php
+23
-24
Mysql.php
lib/Doctrine/Sequence/Mysql.php
+11
-9
Oracle.php
lib/Doctrine/Sequence/Oracle.php
+12
-11
Sqlite.php
lib/Doctrine/Sequence/Sqlite.php
+6
-6
No files found.
lib/Doctrine/Connection.php
View file @
4928dfef
...
...
@@ -61,17 +61,23 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
*
* export Doctrine_Export driver, handles db structure modification abstraction (contains
* methods such as alterTable, createConstraint etc.)
* import Doctrine_Import driver, handles db schema reading
*
* sequence Doctrine_Sequence driver, handles sequential id generation and retrieval
*
* @see Doctrine_Connection::__get()
* @see Doctrine_DataDict
* @see Doctrine_Expression
* @see Doctrine_Export
* @see Doctrine_Transaction
* @see Doctrine_Sequence
*/
private
$modules
=
array
(
'transaction'
=>
false
,
'expression'
=>
false
,
'dataDict'
=>
false
,
'export'
=>
false
,
'import'
=>
false
,
'sequence'
=>
false
,
'unitOfWork'
=>
false
,
);
/**
...
...
lib/Doctrine/Export.php
View file @
4928dfef
...
...
@@ -282,7 +282,7 @@ class Doctrine_Export extends Doctrine_Connection_Module
foreach
(
array_keys
(
$definition
[
'fields'
])
as
$field
)
{
$fields
[]
=
$this
->
conn
->
quoteIdentifier
(
$field
);
}
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
$query
.=
' ('
.
implode
(
', '
,
$fields
)
.
')'
;
return
$query
;
}
...
...
lib/Doctrine/Sequence.php
View file @
4928dfef
...
...
@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Connection_Module'
);
/**
* Doctrine_Sequence
* The base class for sequence handling drivers.
...
...
lib/Doctrine/Sequence/Firebird.php
View file @
4928dfef
...
...
@@ -64,6 +64,7 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
// BUT generators are not always reset, so return the actual value
return
$this
->
currID
(
$seqName
);
}
throw
$e
;
}
return
$result
;
}
...
...
lib/Doctrine/Sequence/Mssql.php
View file @
4928dfef
...
...
@@ -45,31 +45,30 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$this
->
expectError
(
MDB2_ERROR_NOSUCHTABLE
);
if
(
$this
->
_checkSequence
(
$sequence_name
))
{
$query
=
"SET IDENTITY_INSERT
$sequence_name
ON "
.
"INSERT INTO
$sequence_name
(
$seqcol_name
) VALUES (0)"
;
$query
=
'SET IDENTITY_INSERT '
.
$sequenceName
.
' ON '
.
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES (0)'
;
}
else
{
$query
=
"INSERT INTO
$sequence_name
(
$seqcol_name
) VALUES (0)"
;
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES (0)'
;
}
$result
=&
$this
->
_doQuery
(
$query
,
true
);
$this
->
popExpect
();
if
(
PEAR
::
isError
(
$result
))
{
if
(
$ondemand
&&
!
$this
->
_checkSequence
(
$sequence_name
))
{
$this
->
loadModule
(
'Manager'
,
null
,
true
);
try
{
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
!
$this
->
_checkSequence
(
$sequenceName
))
{
// Since we are creating the sequence on demand
// we know the first id = 1 so initialize the
// sequence at 2
$result
=
$this
->
manager
->
createSequence
(
$seq_name
,
2
);
if
(
PEAR
::
isError
(
$result
))
{
return
$this
->
raiseError
(
$result
,
null
,
null
,
'nextID: on demand sequence '
.
$seq_name
.
' could not be created'
);
}
else
{
// First ID of a newly created sequence is 1
return
1
;
try
{
$result
=
$this
->
conn
->
export
->
createSequence
(
$seqName
,
2
);
}
catch
(
Doctrine_Exception
$e
)
{
throw
new
Doctrine_Sequence_Exception
(
'on demand sequence '
.
$seqName
.
' could not be created'
);
}
// First ID of a newly created sequence is 1
return
1
;
}
return
$result
;
}
$value
=
$this
->
lastInsertID
(
$sequenceName
);
...
...
@@ -95,18 +94,18 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
*/
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
$server
_i
nfo
=
$this
->
getServerVersion
();
if
(
is_array
(
$server
_i
nfo
)
&&
!
is_null
(
$server
_i
nfo
[
'major'
])
&&
$server
_i
nfo
[
'major'
]
>=
8
)
{
$server
I
nfo
=
$this
->
getServerVersion
();
if
(
is_array
(
$server
I
nfo
)
&&
!
is_null
(
$server
I
nfo
[
'major'
])
&&
$server
I
nfo
[
'major'
]
>=
8
)
{
$query
=
"SELECT SCOPE_IDENTITY()"
;
$query
=
'SELECT SCOPE_IDENTITY()'
;
}
else
{
$query
=
"SELECT @@IDENTITY"
;
$query
=
'SELECT @@IDENTITY'
;
}
return
$this
->
fetchOne
(
$query
,
'integer'
);
return
$this
->
fetchOne
(
$query
);
}
/**
* Returns the current id of a sequence
...
...
lib/Doctrine/Sequence/Mysql.php
View file @
4928dfef
...
...
@@ -40,10 +40,10 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
*
* @return integer next id in the given sequence
*/
public
function
nextI
D
(
$seqName
,
$ondemand
=
true
)
public
function
nextI
d
(
$seqName
,
$ondemand
=
true
)
{
$sequenceName
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_n
ame
),
true
);
$seqcolName
=
$this
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqN
ame
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES (NULL)'
;
try
{
...
...
@@ -63,9 +63,11 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
// First ID of a newly created sequence is 1
return
1
;
}
return
$result
;
throw
$e
;
}
$value
=
$this
->
lastInsertID
();
$value
=
$this
->
lastInsertId
();
if
(
is_numeric
(
$value
))
{
$query
=
'DELETE FROM '
.
$sequenceName
.
' WHERE '
.
$seqcolName
.
' < '
.
$value
;
$this
->
conn
->
exec
(
$query
);
...
...
@@ -86,7 +88,7 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
* @param string name of the field into which a new row was inserted
* @return integer|boolean
*/
public
function
lastInsertI
D
(
$table
=
null
,
$field
=
null
)
public
function
lastInsertI
d
(
$table
=
null
,
$field
=
null
)
{
return
$this
->
conn
->
getDbh
()
->
lastInsertId
();
}
...
...
@@ -97,12 +99,12 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
*
* @return integer current id in the given sequence
*/
public
function
currI
D
(
$seqName
)
public
function
currI
d
(
$seqName
)
{
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'SELECT MAX('
.
$seqcolName
.
') FROM '
.
$sequenceName
;
return
$this
->
queryOne
(
$query
,
'integer'
);
return
(
int
)
$this
->
conn
->
fetchOne
(
$query
);
}
}
lib/Doctrine/Sequence/Oracle.php
View file @
4928dfef
...
...
@@ -42,12 +42,11 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
*/
public
function
nextID
(
$seqName
,
$onDemand
=
true
)
{
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$query
=
"SELECT
$sequence_name
.nextval FROM DUAL"
;
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqName
),
true
);
$query
=
'SELECT '
.
$sequenceName
.
'.nextval FROM DUAL'
;
try
{
$result
=
$this
->
queryOne
(
$query
,
'integer'
);
$result
=
$this
->
conn
->
fetchOne
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
$e
->
getPortableCode
()
==
Doctrine
::
ERR_NOSUCHTABLE
)
{
...
...
@@ -58,6 +57,7 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
}
return
$this
->
nextId
(
$seqName
,
false
);
}
throw
$e
;
}
return
$result
;
}
...
...
@@ -70,9 +70,10 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
*/
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
$seq
=
$table
.
(
empty
(
$field
)
?
''
:
'_'
.
$field
);
$sequenceName
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
return
$this
->
fetchOne
(
"SELECT
$sequence_name
.currval"
,
'integer'
);
$seqName
=
$table
.
(
empty
(
$field
)
?
''
:
'_'
.
$field
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqName
),
true
);
return
$this
->
conn
->
fetchOne
(
'SELECT '
.
$sequenceName
.
'.currval'
);
}
/**
* Returns the current id of a sequence
...
...
@@ -83,11 +84,11 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
*/
public
function
currID
(
$seqName
)
{
$sequenceName
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqName
),
true
);
$query
=
'SELECT (last_number-1) FROM user_sequences'
;
$query
.=
' WHERE sequence_name='
.
$this
->
conn
->
quote
(
$sequence
_n
ame
,
'text'
);
$query
.=
' OR sequence_name='
.
$this
->
conn
->
quote
(
strtoupper
(
$sequence
_n
ame
),
'text'
);
$query
.=
' WHERE sequence_name='
.
$this
->
conn
->
quote
(
$sequence
N
ame
,
'text'
);
$query
.=
' OR sequence_name='
.
$this
->
conn
->
quote
(
strtoupper
(
$sequence
N
ame
),
'text'
);
return
$this
->
fetchOne
(
$query
,
'integer'
);
return
$this
->
conn
->
fetchOne
(
$query
);
}
}
lib/Doctrine/Sequence/Sqlite.php
View file @
4928dfef
...
...
@@ -42,14 +42,14 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
*/
public
function
nextID
(
$seqName
,
$onDemand
=
true
)
{
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES (NULL)'
;
try
{
$this
->
conn
->
exec
(
$query
,
true
);
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
$result
->
getPortableCode
()
==
Doctrine
::
ERR_NOSUCHTABLE
)
{
...
...
@@ -102,11 +102,11 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
*/
public
function
currID
(
$seqName
)
{
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
conn
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'SELECT MAX('
.
$seqcolName
.
') FROM '
.
$sequenceName
;
return
$this
->
fetchOne
(
$query
,
'integer'
);
return
(
int
)
$this
->
conn
->
fetchOne
(
$query
);
}
}
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