Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying the compare-array for insertIfNotExists() #14766

Merged
merged 11 commits into from
Mar 16, 2015

Conversation

nickvergessen
Copy link
Contributor

No description provided.

'configvalue' => $value,
'userid' => $userId,
'appid' => $appName,
]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about only having to specify the array keys instead of duplicating the values as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that makes sense, yes

@nickvergessen nickvergessen force-pushed the fix-insertifnotexists-poc branch from 07c87ea to 0a21608 Compare March 9, 2015 17:22
@nickvergessen nickvergessen added this to the 8.1-current milestone Mar 9, 2015
@DeepDiver1975
Copy link
Member

@nickvergessen I see what you are trying to accomplish - bääh - we should have continue to talk about this days back ... well - shit happens.

@DeepDiver1975
Copy link
Member

What I was thinking about while having a look at the implementation of insertIfNoExists():
What about handling the unique constraint violation not is a specific way - like simply throwing a UniqueContraintViolationException and let the caller decide on what to do.

@DeepDiver1975
Copy link
Member

61e4fd7 - contains a unit test to show this approach basically works
1e7d3ee - DBALException is throws from insertIfNotExists instead of HintException

@DeepDiver1975 DeepDiver1975 force-pushed the fix-insertifnotexists-poc branch from 1e7d3ee to 89be55a Compare March 9, 2015 21:38
if ($row = $result->fetchRow()) {
$this->numericId = $row['numeric_id'];
} else {
throw new \Exception('Storage exists when inserting and does not exist on select... go away');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temp code and must not happen

@nickvergessen
Copy link
Contributor Author

What I was thinking about while having a look at the implementation of insertIfNoExists():
What about handling the unique constraint violation not is a specific way - like simply throwing a UniqueContraintViolationException and let the caller decide on what to do.

I think we can/should do this, to make it possible to differ between a normal DB exception and this case. Shall I go ahead and implement that @DeepDiver1975

@DeepDiver1975
Copy link
Member

Shall I go ahead and implement that

89be55a <- already done

@nickvergessen nickvergessen changed the title [POC][WIP][DO NOT MERGE] Allow specifying the compare-array for insertIfNotExists() [WIP] Allow specifying the compare-array for insertIfNotExists() Mar 10, 2015
if (!$exists && $preCondition === null) {
$sql = 'INSERT INTO `*PREFIX*preferences` (`configvalue`, `userid`, `appid`, `configkey`)'.
'VALUES (?, ?, ?, ?)';
$this->connection->insertIfNotExist('*PREFIX*preferences', [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole code block cries for a second method: InsertOrUpdate - but this is OT

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really work? The backticks are missing and I remind problems on OCI with this. @DeepDiver1975 Can you run the oracle test suite?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method adds the backticks. The code around here, does not know anything about sql syntax ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backticks are in lib/private/db/adapter.php

@DeepDiver1975
Copy link
Member

From my POV this is ready to go - :high_five: @nickvergessen

@DeepDiver1975 DeepDiver1975 changed the title [WIP] Allow specifying the compare-array for insertIfNotExists() Allow specifying the compare-array for insertIfNotExists() Mar 10, 2015
@nickvergessen nickvergessen force-pushed the fix-insertifnotexists-poc branch from 83b0a40 to 2af8fea Compare March 11, 2015 08:34
@ghost
Copy link

ghost commented Mar 11, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/10339/
Test PASSed.

@DeepDiver1975
Copy link
Member

👍 ready to go

@DeepDiver1975
Copy link
Member

@PVince81 @icewind1991 please review - THX

*/
public function insertIfNotExist($table, $input) {
public function insertIfNotExist($table, $input, array $compare = null) {
if ($compare === null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be empty() so we use all keys when an empty array is passed aswell :(, will fix asap

@scrutinizer-notifier
Copy link

The inspection completed: 7 new issues, 6 updated code elements

@ghost
Copy link

ghost commented Mar 12, 2015

Refer to this link for build results (access rights to CI server needed):
https://ci.owncloud.org//job/pull-request-analyser-ng-simple/10381/
Test PASSed.

@DeepDiver1975
Copy link
Member

@nickvergessen shall we squash to allow easier backport?

@nickvergessen
Copy link
Contributor Author

No, I prefer a cherry-pick session over a huge commit that no one understands anymore.

@nickvergessen
Copy link
Contributor Author

Second review @MorrisJobke @LukasReschke ?

@DeepDiver1975
Copy link
Member

@MorrisJobke @LukasReschke @PVince81 @icewind1991 please review - THX

@MorrisJobke
Copy link
Contributor

Works 👍

MorrisJobke added a commit that referenced this pull request Mar 16, 2015
Allow specifying the compare-array for insertIfNotExists()
@MorrisJobke MorrisJobke merged commit 997a7a2 into master Mar 16, 2015
@MorrisJobke MorrisJobke deleted the fix-insertifnotexists-poc branch March 16, 2015 09:31
@nickvergessen
Copy link
Contributor Author

Backport is at #14914

@lock lock bot locked as resolved and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants