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

Upgrade failed SQL 7 ERROR: invalid input syntax for integer: "5,179" #5758

Closed
wolkenschieber opened this issue Nov 8, 2013 · 16 comments
Closed

Comments

@wolkenschieber
Copy link

Hi,

I just tried to upgrade to current version 5.0.13.
After applying the maintenance mode isn't turned off.

If I turn it off manually and refresh the main page I get the message:
Failed to upgrade "files_sharing". Exception="SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "5,179""

Does anyone know how to solve the issue?

Thanks
wolkenschieber

@wolkenschieber
Copy link
Author

After some poking around, the problem is caused by
owncloud/apps/files_sharing/appinfo/update.php

There the in statement doesn't work with an array that has more than one item:
$removeShares = \OC_DB::prepare('DELETE FROM *PREFIX*share WHERE file_source IN (?)');

This is propably postgres related.

@DeepDiver1975
Copy link
Member

https://github.com/owncloud/core/blob/master/apps/files_sharing/appinfo/update.php#L76

binding an array to one single query parameter will most probably work nowhere

@zmi1
Copy link

zmi1 commented Nov 9, 2013

I had a similar error on two of three sites:
owncloud Failed to upgrade "files_sharing". Invalid text representation: 7 ERROR: invalid input syntax for integer: (then lots of numbers)

One site didn't say anything, just turned maintainance mode on and stopped.

The fix was to run the SQL statement manually:
delete from oc_share where file_source in (SELECT file_source FROM oc_share LEFT JOIN oc_filecache ON file_source = oc_filecache.fileid WHERE oc_filecache.fileid IS NULL AND oc_share.item_type IN ('file', 'folder'));

Afterwards the ugprade ran smooth. We use PostgreSQL.
Sigh. There are still too many upgrade problems in OwnCloud!

@DeepDiver1975
Copy link
Member

delete from oc_share where file_source in (SELECT file_source FROM oc_share LEFT JOIN oc_filecache ON file_source = oc_filecache.fileid WHERE oc_filecache.fileid IS NULL AND oc_share.item_type IN ('file', 'folder'));

@zmi1 this is how the query should have looked like instead of that crazy code we have today.
Interested in fixing the code pieces and submit a pull request? THX

@satarsa
Copy link

satarsa commented Nov 9, 2013

Thank you @zmi1, it works!

@zmi1
Copy link

zmi1 commented Nov 12, 2013

Hi Thomas, heres the very much simplified and WORKING (yes, tested) solution. I have no idea how youd like the pull request to look like. So I attach it as a file and inline. Have fun.

PULL REQUEST:

@zmi1
Copy link

zmi1 commented Nov 12, 2013

Here's the simple diff that's working.

75,77c75,77
<       // 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\'))');
<       $result = $removeShares->execute(array(implode(',', $delArray)));
---
>       // get all shares where the original file no longer exists
>       $findShares = \OC_DB::prepare('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\')');
>       $sharesFound = $findShares->execute(array())->fetchAll();
78a79,87
>       // delete those shares from the oc_share table
>       if (is_array($sharesFound) && !empty($sharesFound)) {
>               $delArray = array();
>               foreach ($sharesFound as $share) {
>                       $delArray[] = $share['file_source'];
>               }
>               $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (?)');
>               $result = $removeShares->execute(array(implode(',', $delArray)));
>       }

I've tested it, it's working.

@DeepDiver1975
Copy link
Member

@zmi1 Thanks a lot!
Pull requests are the GitHub way of collaborative/social coding - if you are interested here is a quick tutorial on how to submit a pull request https://www.openshift.com/wiki/github-workflow-for-submitting-pull-requests

Feel free to get back to me in case of questions - THX

@zmi1
Copy link

zmi1 commented Nov 12, 2013

Looked into it, too much effort for me. You can take the code above and create your own pull request. Whatever license you need I transfer it to you.

@DeepDiver1975
Copy link
Member

Looked into it, too much effort for me.

That's sad - but understandable.

You can take the code above and create your own pull request. Whatever license you need I transfer it to you.

It will require MIT license - thanks a lot for your contribution!

@zmi1
Copy link

zmi1 commented Nov 12, 2013

Hm, looking at the code I wonder why it's working:

< $result = $removeShares->execute(array(implode(',', $delArray)));

shouldn't that be

< $result = $removeShares->execute();

?? Not sure what the parameter to execute is. It was working four our site, but I guess a cleanup would be good. I guess it worked because delArray is empty as it's not used anymore.

jmcclelland added a commit to jmcclelland/core that referenced this issue Nov 24, 2013
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
@jmcclelland
Copy link
Contributor

I had the same problem upgrading from 5.0.15 to 5.0.25 (via Debian jessie packages).

I've prepared a pull request (that is tested against 5.25/Debian Jessie package):

#6016

@jmcclelland
Copy link
Contributor

I think you are right about the parameter being cruft. I just removed it in my pull request (but sadly I've already upgraded my installation so it's not tested).

@VicDeo VicDeo modified the milestones: ownCloud 6, ownCloud 5.0.14 Feb 8, 2014
@VicDeo VicDeo removed this from the ownCloud 6 milestone Feb 8, 2014
MorrisJobke pushed a commit that referenced this issue 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.
MorrisJobke pushed a commit that referenced this issue 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.
@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2014

I believe this has been fixed now in #7293 which superseded the original PR #6016
Closing.

@rysiekpl
Copy link

rysiekpl commented Aug 8, 2014

Not fixed, the same error upgrading 4.5.x to 5.0.17 here. Probably related to these lines:

$removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share` WHERE `file_source` IN (?)');
$result = $removeShares->execute(array(implode(',', $delArray)));

As @DeepDiver1975 pointed out, "binding an array to one single query parameter will most probably work nowhere".

Running the query by hand:

DELETE FROM "oc_share" WHERE "file_source" IN (4,8,11,26,37,38,41,70,71,51,95,99)

solves the problem for me - so the issue is placing an array of integers (imploded with ',') as a text param.

@VicDeo
Copy link
Member

VicDeo commented Aug 8, 2014

@rysiekpl Fix above has ownCloud 7 milestone. Surely it is not fixed for 5.x

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

No branches or pull requests

8 participants