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

fix update to remove shares where file doesn't exist on postgres #6016

Closed

Conversation

jmcclelland
Copy link
Contributor

Without patch, breaks with: Failed to upgrade "files_sharing".
Exception="SQLSTATE[22P02]: Invalid text representation: 7 ERROR:
invalid input syntax for integer: "5,179""

See: #5758

Without patch, breaks with: Failed to upgrade "files_sharing".
Exception="SQLSTATE[22P02]: Invalid text representation: 7 ERROR:
invalid input syntax for integer: "5,179""

See: owncloud#5758
@ghost
Copy link

ghost commented Nov 24, 2013

Can one of the admins verify this patch?

@DeepDiver1975
Copy link
Member

@jmcclelland Thanks a lot for your contribution!
Contributions to the core repo require a signed contributors agreement http://owncloud.org/about/contributor-agreement/

Alternatively you can add a comment here where you state that this contribution is MIT licensed.

@DeepDiver1975
Copy link
Member

This patch requires tests on ALL supported databases (sqlite, mysql, postgres, Oracle and mssql).

Best would be to have a unit test covering this code piece

@ghost
Copy link

ghost commented Nov 24, 2013

Test passed.
Refer to this link for build results: https://ci.owncloud.org/job/pull-request-analyser/2105/

@jmcclelland
Copy link
Contributor Author

My contribution in is MIT licensed

@karlitschek
Copy link
Contributor

Looks good. 👍 @schiesbn @bantu What do you think?

@bantu
Copy link

bantu commented Nov 28, 2013

Not sure whether we support subqueries.

$result = $removeShares->execute(array(implode(',', $delArray)));
}
// delete all shares where the original file no longer exists
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (SELECT `file_source` FROM `*PREFIX*share` LEFT JOIN `*PREFIX*filecache` ON `file_source` = `*PREFIX*filecache`.`fileid` WHERE `*PREFIX*filecache`.`fileid` IS NULL AND `*PREFIX*share`.`item_type` IN (\'file\', \'folder\'))');
Copy link

Choose a reason for hiding this comment

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

The delete query should be using the primary key, i.e. id.

Copy link

Choose a reason for hiding this comment

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

This line is way too long. Even too long to do a proper review.

@karlitschek
Copy link
Contributor

@jmcclelland Any chance this can be done without subqueries? Thanks

@MorrisJobke
Copy link
Contributor

@karlitschek Just for interest: Why aren't we support subqueries?

@karlitschek
Copy link
Contributor

@kabum It has to work with all databases. I'm fine if it works everywhere but I'm not sure at the moment. :-)

@jmcclelland
Copy link
Contributor Author

I've never spent so much time on a one line patch that I didn't even write :).

Well, I've committed a fix with shorter lines and no sub-queries, however, it hasn't been properly tested.

}
// delete those shares from the oc_share table
if (is_array($sharesFound) && !empty($sharesFound)) {
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? )');
Copy link

Choose a reason for hiding this comment

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

Closing ) in string here.

@karlitschek
Copy link
Contributor

@schiesbn Can you have a look?

@@ -71,18 +71,17 @@

// clean up oc_share table from files which are no longer exists
if (version_compare($installedVersion, '0.3.5', '<')) {
// delete all shares where the original file no longer exists
$findShares = \OC_DB::prepare('SELECT `*PREFIX*share.id` ' .
Copy link
Contributor

Choose a reason for hiding this comment

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

This need to be:

$findShares = \OC_DB::prepare('SELECT `*PREFIX*share`.`id` ' .

@DeepDiver1975
Copy link
Member

This patch requires tests on ALL supported databases (sqlite, mysql, postgres, Oracle and mssql).

Best would be to have a unit test covering this code piece

The only way to make sure this code is properly working is a unit test - as suggested many times.

if (is_array($sharesFound) && !empty($sharesFound)) {
$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `id` = ? )');
foreach ($sharesFound as $share) {
$result = $removeShares->execute($share['id']);
Copy link
Contributor

Choose a reason for hiding this comment

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

need to be:

$result = $removeShares->execute(array($share['id']));

@schiessle
Copy link
Contributor

@jmcclelland Upgrade works fine with the changes mentioned by @bantu and me. Can you update your branch, so that we can merge your changes? Thanks!

@jmcclelland
Copy link
Contributor Author

All changes have been committed except the unit test. Unfortunately I don't have time to write a unit test but would welcome someone else to do it.

@julienfastre
Copy link

Hi,

I think unit test are a good practice.

However, I encountered the problem this pull request should avoid. I applied the changes and this saved my life :-)

I have a Postgresq install (version 9.1) + apache 2.4 and php 5.5. I was migrating from 5.0.14 to 6.0.1 when I had problem : "the migration of fail_sharing failed".

MorrisJobke pushed a commit that referenced this pull request Feb 19, 2014
Without patch, breaks with: Failed to upgrade "files_sharing".
Exception="SQLSTATE[22P02]: Invalid text representation: 7 ERROR:
invalid input syntax for integer: "5,179""

See: #5758

removing unnecessary cruft - no parameter is set, none to pass.

#5758

removing subquery, making more readable

See: #6016 (comment)

parameters to sql calls should be arrays

#6016

boosting version to ensure fix gets executed

properly escaping the sql select statement

removing extraneous closing paren.
@schiessle
Copy link
Contributor

@jmcclelland Thanks for contributing this fix! We moved to commits over to #7293 so that we can add some unit tests and merge it.

@schiessle schiessle closed this Feb 28, 2014
MorrisJobke pushed a commit that referenced this pull request Mar 13, 2014
Without patch, breaks with: Failed to upgrade "files_sharing".
Exception="SQLSTATE[22P02]: Invalid text representation: 7 ERROR:
invalid input syntax for integer: "5,179""

See: #5758

removing unnecessary cruft - no parameter is set, none to pass.

#5758

removing subquery, making more readable

See: #6016 (comment)

parameters to sql calls should be arrays

#6016

boosting version to ensure fix gets executed

properly escaping the sql select statement

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

Successfully merging this pull request may close these issues.

7 participants