Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
e2661224
Commit
e2661224
authored
11 years ago
by
Andreas Fischer
Browse files
Options
Downloads
Patches
Plain Diff
Make MySQL return "number of found rows" instead of number of "affected rows".
parent
10b59f10
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/private/db/connectionfactory.php
+7
-1
7 additions, 1 deletion
lib/private/db/connectionfactory.php
tests/lib/db.php
+41
-0
41 additions, 0 deletions
tests/lib/db.php
with
48 additions
and
1 deletion
lib/private/db/connectionfactory.php
+
7
−
1
View file @
e2661224
...
@@ -60,7 +60,13 @@ class ConnectionFactory {
...
@@ -60,7 +60,13 @@ class ConnectionFactory {
if
(
!
isset
(
$this
->
defaultConnectionParams
[
$normalizedType
]))
{
if
(
!
isset
(
$this
->
defaultConnectionParams
[
$normalizedType
]))
{
throw
new
\InvalidArgumentException
(
"Unsupported type:
$type
"
);
throw
new
\InvalidArgumentException
(
"Unsupported type:
$type
"
);
}
}
return
$this
->
defaultConnectionParams
[
$normalizedType
];
$result
=
$this
->
defaultConnectionParams
[
$normalizedType
];
if
(
$normalizedType
===
'mysql'
&&
defined
(
'\PDO::MYSQL_ATTR_FOUND_ROWS'
))
{
$result
[
'driverOptions'
]
=
array
(
\PDO
::
MYSQL_ATTR_FOUND_ROWS
=>
true
,
);
}
return
$result
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
tests/lib/db.php
+
41
−
0
View file @
e2661224
...
@@ -200,4 +200,45 @@ class Test_DB extends PHPUnit_Framework_TestCase {
...
@@ -200,4 +200,45 @@ class Test_DB extends PHPUnit_Framework_TestCase {
}
}
}
}
public
function
testUpdateAffectedRowsNoMatch
()
{
$this
->
insertCardData
(
'fullname1'
,
'uri1'
);
// The WHERE clause does not match any rows
$this
->
assertSame
(
0
,
$this
->
updateCardData
(
'fullname3'
,
'uri2'
));
}
public
function
testUpdateAffectedRowsDifferent
()
{
$this
->
insertCardData
(
'fullname1'
,
'uri1'
);
// The WHERE clause matches a single row and the value we are updating
// is different from the one already present.
$this
->
assertSame
(
1
,
$this
->
updateCardData
(
'fullname1'
,
'uri2'
));
}
public
function
testUpdateAffectedRowsSame
()
{
$this
->
insertCardData
(
'fullname1'
,
'uri1'
);
// The WHERE clause matches a single row and the value we are updating
// to is the same as the one already present. MySQL reports 0 here when
// the PDO::MYSQL_ATTR_FOUND_ROWS flag is not specified.
$this
->
assertSame
(
1
,
$this
->
updateCardData
(
'fullname1'
,
'uri1'
));
}
public
function
testUpdateAffectedRowsMultiple
()
{
$this
->
insertCardData
(
'fullname1'
,
'uri1'
);
$this
->
insertCardData
(
'fullname2'
,
'uri2'
);
// The WHERE clause matches two rows. One row contains a value that
// needs to be updated, the other one already contains the value we are
// updating to. MySQL reports 1 here when the PDO::MYSQL_ATTR_FOUND_ROWS
// flag is not specified.
$query
=
OC_DB
::
prepare
(
"UPDATE `*PREFIX*
{
$this
->
table2
}
` SET `uri` = ?"
);
$this
->
assertSame
(
2
,
$query
->
execute
(
array
(
'uri1'
)));
}
protected
function
insertCardData
(
$fullname
,
$uri
)
{
$query
=
OC_DB
::
prepare
(
"INSERT INTO `*PREFIX*
{
$this
->
table2
}
` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"
);
$this
->
assertSame
(
1
,
$query
->
execute
(
array
(
$fullname
,
$uri
,
uniqid
())));
}
protected
function
updateCardData
(
$fullname
,
$uri
)
{
$query
=
OC_DB
::
prepare
(
"UPDATE `*PREFIX*
{
$this
->
table2
}
` SET `uri` = ? WHERE `fullname` = ?"
);
return
$query
->
execute
(
array
(
$uri
,
$fullname
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment