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
24f6b062
Commit
24f6b062
authored
Jan 06, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sequence porting continues
parent
1d141435
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
65 deletions
+69
-65
Oracle.php
lib/Doctrine/Sequence/Oracle.php
+17
-15
Pgsql.php
lib/Doctrine/Sequence/Pgsql.php
+22
-21
Sqlite.php
lib/Doctrine/Sequence/Sqlite.php
+30
-29
No files found.
lib/Doctrine/Sequence/Oracle.php
View file @
24f6b062
...
...
@@ -36,25 +36,27 @@ class Doctrine_Sequence_Oracle 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
* @param bool
onDemand
when true missing sequences are automatic created
*
* @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
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_name
),
true
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$query
=
"SELECT
$sequence_name
.nextval FROM DUAL"
;
$this
->
expectError
(
MDB2_ERROR_NOSUCHTABLE
);
$result
=
$this
->
queryOne
(
$query
,
'integer'
);
$this
->
popExpect
();
if
(
PEAR
::
isError
(
$result
))
{
if
(
$ondemand
&&
$result
->
getCode
()
==
MDB2_ERROR_NOSUCHTABLE
)
{
$this
->
loadModule
(
'Manager'
,
null
,
true
);
$result
=
$this
->
manager
->
createSequence
(
$seq_name
);
if
(
PEAR
::
isError
(
$result
))
{
return
$result
;
try
{
$result
=
$this
->
queryOne
(
$query
,
'integer'
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
$e
->
getPortableCode
()
==
Doctrine
::
ERR_NOSUCHTABLE
)
{
try
{
$result
=
$this
->
conn
->
export
->
createSequence
(
$seqName
);
}
catch
(
Doctrine_Exception
$e
)
{
throw
new
Doctrine_Sequence_Oracle_Exception
(
'on demand sequence '
.
$seqName
.
' could not be created'
);
}
return
$this
->
nextId
(
$seq
_n
ame
,
false
);
return
$this
->
nextId
(
$seq
N
ame
,
false
);
}
}
return
$result
;
...
...
@@ -83,8 +85,8 @@ class Doctrine_Sequence_Oracle extends Doctrine_Sequence
{
$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'
);
$query
.=
' WHERE sequence_name='
.
$this
->
quote
(
$sequence_name
,
'text'
);
$query
.=
' OR sequence_name='
.
$this
->
quote
(
strtoupper
(
$sequence_name
),
'text'
);
return
$this
->
queryOne
(
$query
,
'integer'
);
}
}
lib/Doctrine/Sequence/Pgsql.php
View file @
24f6b062
...
...
@@ -36,26 +36,26 @@ class Doctrine_Sequence_Pgsql 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
* @param bool
onDemand
when true missing sequences are automatic created
*
* @return integer next id in the given sequence
*/
public
function
nextI
D
(
$seqName
,
$ond
emand
=
true
)
public
function
nextI
d
(
$seqName
,
$onD
emand
=
true
)
{
$sequence
_name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_n
ame
),
true
);
$query
=
"SELECT NEXTVAL('
$sequence_name
')"
;
$
this
->
expectError
(
MDB2_ERROR_NOSUCHTABLE
)
;
$result
=
$this
->
queryOne
(
$query
,
'integer'
);
$this
->
popExpect
(
);
if
(
PEAR
::
isError
(
$result
)
)
{
if
(
$on
demand
&&
$result
->
getCode
()
==
MDB2_ERRO
R_NOSUCHTABLE
)
{
$this
->
loadModule
(
'Manager'
,
null
,
true
);
$result
=
$this
->
manager
->
createSequence
(
$seq_name
);
if
(
PEAR
::
isError
(
$result
))
{
return
$this
->
raiseError
(
$result
,
null
,
null
,
'on demand sequence could not be created'
,
__FUNCTION__
);
$sequence
Name
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqN
ame
),
true
);
$
query
=
"SELECT NEXTVAL('"
.
$sequenceName
.
"')"
;
try
{
$result
=
$this
->
fetchOne
(
$query
,
'integer'
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$on
Demand
&&
$e
->
getPortableCode
()
==
Doctrine
::
ER
R_NOSUCHTABLE
)
{
try
{
$result
=
$this
->
conn
->
export
->
createSequence
(
$seqName
);
}
catch
(
Doctrine_Exception
$e
)
{
throw
new
Doctrine_Sequence_Sqlite_Exception
(
'on demand sequence '
.
$seqName
.
' could not be created'
);
}
return
$this
->
nextId
(
$seq
_n
ame
,
false
);
return
$this
->
nextId
(
$seq
N
ame
,
false
);
}
}
return
$result
;
...
...
@@ -67,11 +67,12 @@ class Doctrine_Sequence_Pgsql 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
*/
public
function
lastInsertI
D
(
$table
=
null
,
$field
=
null
)
public
function
lastInsertI
d
(
$table
=
null
,
$field
=
null
)
{
$seq
=
$table
.
(
empty
(
$field
)
?
''
:
'_'
.
$field
);
$sequence_name
=
$this
->
getSequenceName
(
$seq
);
return
$this
->
queryOne
(
"SELECT currval('
$sequence_name
')"
,
'integer'
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
return
$this
->
fetchOne
(
"SELECT currval('"
.
$sequenceName
.
"')"
,
'integer'
);
}
/**
* Returns the current id of a sequence
...
...
@@ -80,9 +81,9 @@ class Doctrine_Sequence_Pgsql extends Doctrine_Sequence
*
* @return integer current id in the given sequence
*/
public
function
currI
D
(
$seqName
)
public
function
currI
d
(
$seqName
)
{
$sequence
_name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_n
ame
),
true
);
return
$this
->
queryOne
(
"SELECT last_value FROM
$sequence_name
"
,
'integer'
);
$sequence
Name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqN
ame
),
true
);
return
$this
->
fetchOne
(
'SELECT last_value FROM '
.
$sequenceName
,
'integer'
);
}
}
lib/Doctrine/Sequence/Sqlite.php
View file @
24f6b062
...
...
@@ -36,36 +36,39 @@ class Doctrine_Sequence_Sqlite 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
* @param bool
$onDemand
when true missing sequences are automatic created
*
* @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
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_name
),
true
);
$seqcol_name
=
$this
->
options
[
'seqcol_name'
];
$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
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'INSERT INTO '
.
$sequenceName
.
' ('
.
$seqcolName
.
') VALUES (NULL)'
;
try
{
$this
->
conn
->
exec
(
$query
,
true
);
}
catch
(
Doctrine_Connection_Exception
$e
)
{
if
(
$onDemand
&&
$result
->
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_Sqlite_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
();
$value
=
$this
->
conn
->
getDbh
()
->
lastInsertID
();
if
(
is_numeric
(
$value
))
{
$query
=
"DELETE FROM
$sequence_name
WHERE
$seqcol_name
<
$value
"
;
$result
=&
$this
->
_doQuery
(
$query
,
true
);
...
...
@@ -84,11 +87,7 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
*/
public
function
lastInsertID
(
$table
=
null
,
$field
=
null
)
{
$connection
=
$this
->
getConnection
();
if
(
PEAR
::
isError
(
$connection
))
{
return
$connection
;
}
$value
=
@
sqlite_last_insert_rowid
(
$connection
);
$value
=
$this
->
conn
->
getDbh
()
->
lastInsertID
();
if
(
!
$value
)
{
return
$this
->
raiseError
(
null
,
null
,
null
,
'Could not get last insert ID'
,
__FUNCTION__
);
...
...
@@ -104,9 +103,11 @@ class Doctrine_Sequence_Sqlite extends Doctrine_Sequence
*/
public
function
currID
(
$seqName
)
{
$sequence_name
=
$this
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seq_name
),
true
);
$seqcol_name
=
$this
->
quoteIdentifier
(
$this
->
options
[
'seqcol_name'
],
true
);
$query
=
"SELECT MAX(
$seqcol_name
) FROM
$sequence_name
"
;
return
$this
->
queryOne
(
$query
,
'integer'
);
$sequenceName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getSequenceName
(
$seqName
),
true
);
$seqcolName
=
$this
->
conn
->
quoteIdentifier
(
$this
->
getAttribute
(
Doctrine
::
ATTR_SEQCOL_NAME
),
true
);
$query
=
'SELECT MAX('
.
$seqcolName
.
') FROM '
.
$sequenceName
;
return
$this
->
fetchOne
(
$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