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
33706eee
Commit
33706eee
authored
Jan 07, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated sequence drivers
parent
0a5a3bcd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
84 deletions
+88
-84
Firebird.php
lib/Doctrine/Sequence/Firebird.php
+28
-27
Mssql.php
lib/Doctrine/Sequence/Mssql.php
+18
-10
Mysql.php
lib/Doctrine/Sequence/Mysql.php
+26
-31
Oracle.php
lib/Doctrine/Sequence/Oracle.php
+8
-7
Sqlite.php
lib/Doctrine/Sequence/Sqlite.php
+8
-9
No files found.
lib/Doctrine/Sequence/Firebird.php
View file @
33706eee
...
...
@@ -40,29 +40,29 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
*
* @return integer next id in the given sequence
*/
public
function
nextID
(
$seqName
,
$on
d
emand
=
true
)
public
function
nextID
(
$seqName
,
$on
D
emand
=
true
)
{
$sequence_name
=
$this
->
getSequenceName
(
$seq_name
);
$query
=
'SELECT GEN_ID('
.
$sequence_name
.
', 1) as the_value FROM RDB$DATABASE'
;
$this
->
expectError
(
'*'
);
$result
=
$this
->
queryOne
(
$query
,
'integer'
);
$this
->
popExpect
();
if
(
PEAR
::
isError
(
$result
))
{
if
(
$ondemand
)
{
$this
->
loadModule
(
'Manager'
,
null
,
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$query
=
'SELECT GEN_ID('
.
$sequenceName
.
', 1) as the_value FROM RDB$DATABASE'
;
try
{
$result
=
$this
->
queryOne
(
$query
,
'integer'
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
$e
->
getPortableCode
()
==
Doctrine
::
ERR_NOSUCHTABLE
)
{
// 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
,
'on demand sequence could not be created'
,
__FUNCTION__
);
}
else
{
// First ID of a newly created sequence is 1
// return 1;
// BUT generators are not always reset, so return the actual value
return
$this
->
currID
(
$seq_name
);
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;
// BUT generators are not always reset, so return the actual value
return
$this
->
currID
(
$seqName
);
}
}
return
$result
;
...
...
@@ -87,16 +87,17 @@ class Doctrine_Sequence_Firebird extends Doctrine_Sequence
*/
public
function
currID
(
$seqName
)
{
$sequence_name
=
$this
->
getSequenceName
(
$seq_name
);
$query
=
'SELECT GEN_ID('
.
$sequence_name
.
', 0) as the_value FROM RDB$DATABASE'
;
$value
=
$this
->
queryOne
(
$query
);
if
(
PEAR
::
isError
(
$value
))
{
return
$this
->
raiseError
(
$result
,
null
,
null
,
'Unable to select from '
.
$seq_name
,
__FUNCTION__
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$query
=
'SELECT GEN_ID('
.
$sequence_name
.
', 0) as the_value FROM RDB$DATABASE'
;
try
{
$value
=
$this
->
queryOne
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
throw
new
Doctrine_Sequence_Exception
(
'Unable to select from '
.
$seqName
);
}
if
(
!
is_numeric
(
$value
))
{
return
$this
->
raiseError
(
MDB2_ERROR
,
null
,
null
,
'could not find value in sequence table'
,
__FUNCTION__
);
if
(
!
is_numeric
(
$value
))
{
throw
new
Doctrine_Sequence_Exception
(
'could not find value in sequence table'
);
}
return
$value
;
}
...
...
lib/Doctrine/Sequence/Mssql.php
View file @
33706eee
...
...
@@ -42,8 +42,9 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
*/
public
function
nextID
(
$seqName
,
$ondemand
=
true
)
{
$sequence_name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_name
),
true
);
$seqcol_name
=
$this
->
quoteIdentifier
(
$this
->
options
[
'seqcol_name'
],
true
);
$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 "
.
...
...
@@ -70,13 +71,18 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
}
return
$result
;
}
$value
=
$this
->
lastInsertID
(
$sequence_name
);
$value
=
$this
->
lastInsertID
(
$sequenceName
);
if
(
is_numeric
(
$value
))
{
$query
=
"DELETE FROM
$sequence_name
WHERE
$seqcol_name
<
$value
"
;
$result
=&
$this
->
_doQuery
(
$query
,
true
);
$query
=
'DELETE FROM '
.
$sequenceName
.
' WHERE '
.
$seqcolName
.
' < '
.
$value
;
$this
->
conn
->
exec
(
$query
);
/**
TODO: is the following needed ?
if (PEAR::isError($result)) {
$this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
}
*/
}
return
$value
;
}
...
...
@@ -91,14 +97,16 @@ class Doctrine_Sequence_Mssql extends Doctrine_Sequence
{
$server_info
=
$this
->
getServerVersion
();
if
(
is_array
(
$server_info
)
&&
!
is_null
(
$server_info
[
'major'
])
&&
$server_info
[
'major'
]
>=
8
)
{
$query
=
"SELECT SCOPE_IDENTITY()"
;
&&
!
is_null
(
$server_info
[
'major'
])
&&
$server_info
[
'major'
]
>=
8
)
{
$query
=
"SELECT SCOPE_IDENTITY()"
;
}
else
{
$query
=
"SELECT @@IDENTITY"
;
$query
=
"SELECT @@IDENTITY"
;
}
return
$this
->
query
One
(
$query
,
'integer'
);
return
$this
->
fetch
One
(
$query
,
'integer'
);
}
/**
* Returns the current id of a sequence
...
...
lib/Doctrine/Sequence/Mysql.php
View file @
33706eee
...
...
@@ -40,38 +40,41 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
*
* @return integer next id in the given sequence
*/
public
function
nextID
(
$seq
_n
ame
,
$ondemand
=
true
)
public
function
nextID
(
$seq
N
ame
,
$ondemand
=
true
)
{
$sequence_name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_name
),
true
);
$seqcol_name
=
$this
->
quoteIdentifier
(
$this
->
options
[
'seqcol_name'
],
true
);
$query
=
"INSERT INTO
$sequence_name
(
$seqcol_name
) VALUES (NULL)"
;
$this
->
expectError
(
MDB2_ERROR_NOSUCHTABLE
);
$result
=&
$this
->
_doQuery
(
$query
,
true
);
$this
->
popExpect
();
if
(
PEAR
::
isError
(
$result
))
{
if
(
$ondemand
&&
$result
->
getCode
()
==
MDB2_ERROR_NOSUCHTABLE
)
{
$this
->
loadModule
(
'Manager'
,
null
,
true
);
$sequenceName
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_name
),
true
);
$seqcolName
=
$this
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES (NULL)'
;
try
{
$this
->
conn
->
exec
(
$query
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
$e
->
getPortableCode
()
==
Doctrine
::
ERR_NOSUCHTABLE
)
{
// 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
,
'on demand sequence '
.
$seq_name
.
' could not be created'
,
__FUNCTION__
);
}
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
();
if
(
is_numeric
(
$value
))
{
$query
=
"DELETE FROM
$sequence_name
WHERE
$seqcol_name
<
$value
"
;
$result
=&
$this
->
_doQuery
(
$query
,
true
);
$query
=
'DELETE FROM '
.
$sequenceName
.
' WHERE '
.
$seqcolName
.
' < '
.
$value
;
$this
->
conn
->
exec
(
$query
);
/**
TODO: is the following needed ?
if (PEAR::isError($result)) {
$this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
}
*/
}
return
$value
;
}
...
...
@@ -79,21 +82,13 @@ class Doctrine_Sequence_Mysql extends Doctrine_Sequence
* Returns the autoincrement ID if supported or $id or fetches the current
* ID in a sequence called: $table.(empty($field) ? '' : '_'.$field)
*
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
* @return integer|boolean
*/
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
$connection
=
$this
->
getConnection
();
if
(
PEAR
::
isError
(
$connection
))
{
return
$connection
;
}
$value
=
@
mysqli_insert_id
(
$connection
);
if
(
!
$value
)
{
return
$this
->
raiseError
(
null
,
null
,
null
,
'Could not get last insert ID'
,
__FUNCTION__
);
}
return
$value
;
return
$this
->
conn
->
getDbh
()
->
lastInsertId
();
}
/**
* Returns the current id of a sequence
...
...
lib/Doctrine/Sequence/Oracle.php
View file @
33706eee
...
...
@@ -71,8 +71,8 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
$seq
=
$table
.
(
empty
(
$field
)
?
''
:
'_'
.
$field
);
$sequence
_name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq
),
true
);
return
$this
->
query
One
(
"SELECT
$sequence_name
.currval"
,
'integer'
);
$sequence
Name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
return
$this
->
fetch
One
(
"SELECT
$sequence_name
.currval"
,
'integer'
);
}
/**
* Returns the current id of a sequence
...
...
@@ -83,10 +83,11 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
*/
public
function
currID
(
$seqName
)
{
$sequence_name
=
$this
->
getSequenceName
(
$seq_name
);
$query
=
'SELECT (last_number-1) FROM user_sequences'
;
$query
.=
' WHERE sequence_name='
.
$this
->
quote
(
$sequence_name
,
'text'
);
$query
.=
' OR sequence_name='
.
$this
->
quote
(
strtoupper
(
$sequence_name
),
'text'
);
return
$this
->
queryOne
(
$query
,
'integer'
);
$sequenceName
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$query
=
'SELECT (last_number-1) FROM user_sequences'
;
$query
.=
' WHERE sequence_name='
.
$this
->
conn
->
quote
(
$sequence_name
,
'text'
);
$query
.=
' OR sequence_name='
.
$this
->
conn
->
quote
(
strtoupper
(
$sequence_name
),
'text'
);
return
$this
->
fetchOne
(
$query
,
'integer'
);
}
}
lib/Doctrine/Sequence/Sqlite.php
View file @
33706eee
...
...
@@ -60,7 +60,7 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
try
{
$result
=
$this
->
conn
->
export
->
createSequence
(
$seqName
,
2
);
}
catch
(
Doctrine_Exception
$e
)
{
throw
new
Doctrine_Sequence_
Sqlite_
Exception
(
'on demand sequence '
.
$seqName
.
' could not be created'
);
throw
new
Doctrine_Sequence_Exception
(
'on demand sequence '
.
$seqName
.
' could not be created'
);
}
// First ID of a newly created sequence is 1
return
1
;
...
...
@@ -70,11 +70,14 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
$value
=
$this
->
conn
->
getDbh
()
->
lastInsertID
();
if
(
is_numeric
(
$value
))
{
$query
=
"DELETE FROM
$sequence_name
WHERE
$seqcol_name
<
$value
"
;
$result
=&
$this
->
_doQuery
(
$query
,
true
);
$query
=
'DELETE FROM '
.
$sequenceName
.
' WHERE '
.
$seqcolName
.
' < '
.
$value
;
$this
->
conn
->
exec
(
$query
);
/**
TODO: is the following needed ?
if (PEAR::isError($result)) {
$this->warnings[] = 'nextID: could not delete previous sequence table values from '.$seq_name;
}
*/
}
return
$value
;
}
...
...
@@ -84,15 +87,11 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
*
* @param string name of the table into which a new row was inserted
* @param string name of the field into which a new row was inserted
* @return integer|boolean
*/
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
$value
=
$this
->
conn
->
getDbh
()
->
lastInsertID
();
if
(
!
$value
)
{
return
$this
->
raiseError
(
null
,
null
,
null
,
'Could not get last insert ID'
,
__FUNCTION__
);
}
return
$value
;
return
$this
->
conn
->
getDbh
()
->
lastInsertID
();
}
/**
* Returns the current id of a sequence
...
...
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