Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
e3c5fea9
Commit
e3c5fea9
authored
Mar 22, 2013
by
Bart Visscher
Browse files
Move lastInsertId to adapter classes
parent
cd98ff1e
Changes
6
Hide whitespace changes
Inline
Side-by-side
lib/db.php
View file @
e3c5fea9
...
...
@@ -345,34 +345,7 @@ class OC_DB {
*/
public
static
function
insertid
(
$table
=
null
)
{
self
::
connect
();
$type
=
OC_Config
::
getValue
(
"dbtype"
,
"sqlite"
);
if
(
$type
===
'pgsql'
)
{
$result
=
self
::
executeAudited
(
'SELECT lastval() AS id'
);
$row
=
$result
->
fetchRow
();
self
::
raiseExceptionOnError
(
$row
,
'fetching row for insertid failed'
);
return
$row
[
'id'
];
}
else
if
(
$type
===
'mssql'
)
{
if
(
$table
!==
null
)
{
$table
=
self
::
$connection
->
replaceTablePrefix
(
$table
);
}
return
self
::
$connection
->
lastInsertId
(
$table
);
}
if
(
$type
===
'oci'
)
{
if
(
$table
!==
null
)
{
$prefix
=
OC_Config
::
getValue
(
"dbtableprefix"
,
"oc_"
);
$suffix
=
'_SEQ'
;
$table
=
'"'
.
str_replace
(
'*PREFIX*'
,
$prefix
,
$table
)
.
$suffix
.
'"'
;
}
return
self
::
$connection
->
lastInsertId
(
$table
);
}
else
{
if
(
$table
!==
null
)
{
$suffix
=
OC_Config
::
getValue
(
"dbsequencesuffix"
,
"_id_seq"
);
$table
=
self
::
$connection
->
replaceTablePrefix
(
$table
)
.
$suffix
;
}
$result
=
self
::
$connection
->
lastInsertId
(
$table
);
}
self
::
raiseExceptionOnError
(
$result
,
'insertid failed'
);
return
$result
;
return
self
::
$connection
->
lastInsertId
(
$table
);
}
/**
...
...
lib/db/adapter.php
View file @
e3c5fea9
...
...
@@ -14,4 +14,8 @@ class Adapter {
public
function
__construct
(
$conn
)
{
$this
->
conn
=
$conn
;
}
public
function
lastInsertId
(
$table
)
{
return
$this
->
conn
->
realLastInsertId
(
$table
);
}
}
lib/db/adapteroci8.php
View file @
e3c5fea9
...
...
@@ -10,4 +10,12 @@
namespace
OC\DB
;
class
AdapterOCI8
extends
Adapter
{
public
function
lastInsertId
(
$table
)
{
if
(
$table
!==
null
)
{
$suffix
=
'_SEQ'
;
$table
=
'"'
.
$table
.
$suffix
.
'"'
;
$table
=
$this
->
conn
->
replaceTablePrefix
(
$table
);
}
return
$this
->
conn
->
lastInsertId
(
$table
);
}
}
lib/db/adapterpgsql.php
View file @
e3c5fea9
...
...
@@ -10,4 +10,7 @@
namespace
OC\DB
;
class
AdapterPgSql
extends
Adapter
{
public
function
lastInsertId
(
$table
)
{
return
$this
->
conn
->
fetchColumn
(
'SELECT lastval()'
);
}
}
lib/db/adaptersqlsrv.php
View file @
e3c5fea9
...
...
@@ -10,4 +10,10 @@
namespace
OC\DB
;
class
AdapterSQLSrv
extends
Adapter
{
public
function
lastInsertId
(
$table
)
{
if
(
$table
!==
null
)
{
$table
=
$this
->
conn
->
replaceTablePrefix
(
$table
);
}
return
$this
->
conn
->
lastInsertId
(
$table
);
}
}
lib/db/connection.php
View file @
e3c5fea9
...
...
@@ -67,7 +67,8 @@ class Connection extends \Doctrine\DBAL\Connection {
*/
public
function
executeQuery
(
$query
,
array
$params
=
array
(),
$types
=
array
(),
QueryCacheProfile
$qcp
=
null
)
{
// TODO: prefix
$query
=
$this
->
replaceTablePrefix
(
$query
);
// TODO: fixup
return
parent
::
executeQuery
(
$query
,
$params
,
$types
,
$qcp
);
}
...
...
@@ -85,10 +86,36 @@ class Connection extends \Doctrine\DBAL\Connection {
*/
public
function
executeUpdate
(
$query
,
array
$params
=
array
(),
array
$types
=
array
())
{
// TODO: prefix
$query
=
$this
->
replaceTablePrefix
(
$query
);
// TODO: fixup
return
parent
::
executeUpdate
(
$query
,
$params
,
$types
);
}
/**
* Returns the ID of the last inserted row, or the last value from a sequence object,
* depending on the underlying driver.
*
* Note: This method may not return a meaningful or consistent result across different drivers,
* because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY
* columns or sequences.
*
* @param string $seqName Name of the sequence object from which the ID should be returned.
* @return string A string representation of the last inserted ID.
*/
public
function
lastInsertId
(
$seqName
=
null
)
{
if
(
$seqName
)
{
$seqName
=
$this
->
replaceTablePrefix
(
$seqName
);
}
return
$this
->
adapter
->
lastInsertId
(
$seqName
);
}
// internal use
public
function
realLastInsertId
(
$seqName
=
null
)
{
return
parent
::
lastInsertId
(
$seqName
);
}
// internal use
public
function
replaceTablePrefix
(
$statement
)
{
return
str_replace
(
'*PREFIX*'
,
$this
->
table_prefix
,
$statement
);
...
...
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