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
ebfc0788
Commit
ebfc0788
authored
Jan 05, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
5ce795be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
2 deletions
+77
-2
Sequence.php
lib/Doctrine/Sequence.php
+0
-2
Mysql.php
lib/Doctrine/Sequence/Mysql.php
+77
-0
No files found.
lib/Doctrine/Sequence.php
View file @
ebfc0788
...
...
@@ -51,8 +51,6 @@ class Doctrine_Sequence extends Doctrine_Connection_Module
*
* @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 mixed MDB2 Error Object or id
*/
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
...
...
lib/Doctrine/Sequence/Mysql.php
View file @
ebfc0788
...
...
@@ -32,5 +32,82 @@ Doctrine::autoload('Doctrine_Sequence');
*/
class
Doctrine_Sequence_Mysql
extends
Doctrine_Sequence
{
/**
* Returns the next free id of a sequence
*
* @param string $seqName name of the sequence
* @param bool when true missing sequences are automatic created
*
* @return integer next id in the given sequence
*/
public
function
nextID
(
$seq_name
,
$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
);
// 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
;
}
}
return
$result
;
}
$value
=
$this
->
lastInsertID
();
if
(
is_numeric
(
$value
))
{
$query
=
"DELETE FROM
$sequence_name
WHERE
$seqcol_name
<
$value
"
;
$result
=&
$this
->
_doQuery
(
$query
,
true
);
if
(
PEAR
::
isError
(
$result
))
{
$this
->
warnings
[]
=
'nextID: could not delete previous sequence table values from '
.
$seq_name
;
}
}
return
$value
;
}
/**
* 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
*/
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
;
}
/**
* Returns the current id of a sequence
*
* @param string $seqName name of the sequence
*
* @return integer current id in the given sequence
*/
public
function
currID
(
$seqName
)
{
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
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'
);
}
}
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