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

Compatibility with Nextcloud 18 and MySQL 8.0 #362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<dependencies>
<lib>curl</lib>
<owncloud min-version="7.0.3" max-version="10.0.10" />
<nextcloud min-version="9.1" max-version="17" />
<nextcloud min-version="9.1" max-version="18" />
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks right.

</dependencies>
</info>
24 changes: 12 additions & 12 deletions lib/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getListing($FOLDER, $showdel) {
// Get the listing from the database
$requery = false;
$uid = \OCP\User::getUser();
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$query = "SELECT id, name, `grouping`, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about this change. I don't see this needed based on column type and MySQL 8 release/change notes so am curious about documentation as to why these backticks are required now.

Copy link
Author

@mh0rst mh0rst Apr 26, 2020

Choose a reason for hiding this comment

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

Please take a look at the link I provided in the PR description (https://dev.mysql.com/doc/refman/8.0/en/keywords.html):

GROUPING (R); added in 8.0.1 (reserved)

Grouping is a reserved keyword starting with MySQL 8.0.1, hence its unquoted usage in queries will cause an error.
Example output from a MySQL database with ownnote installed:

mysql> SELECT id, name, grouping, mtime, deleted FROM oc_ownnote ORDER BY name LIMIT 1;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', mtime, deleted FROM oc_ownnote ORDER BY name LIMIT 1' at line 1
mysql> SELECT id, name, `grouping`, mtime, deleted FROM oc_ownnote ORDER BY name LIMIT 1;
+----+------------+----------+------------+---------+
| id | name       | grouping | mtime      | deleted |
+----+------------+----------+------------+---------+
| 34 | Abrechnung |          | 1587824928 |       0 |
+----+------------+----------+------------+---------+
1 row in set (0.00 sec)

Copy link
Contributor

Choose a reason for hiding this comment

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

@mh0rst I apologize. I did not see that GROUPING had become reserved. Thank you for educating me.

$results = $this->db->executeQuery($query, Array($uid))->fetchAll();
$results2 = $results;
if ($results)
Expand Down Expand Up @@ -164,7 +164,7 @@ public function getListing($FOLDER, $showdel) {
}
}
if ($requery) {
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$query = "SELECT id, name, `grouping`, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$results = $this->db->executeQuery($query, Array($uid))->fetchAll();
$requery = false;
}
Expand Down Expand Up @@ -248,7 +248,7 @@ public function getListing($FOLDER, $showdel) {
}
}
if ($requery) {
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$query = "SELECT id, name, `grouping`, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? ORDER BY name";
$results = $this->db->executeQuery($query, Array($uid))->fetchAll();
}
// Now also make sure the files exist, they may not if the user switched folders in admin.
Expand Down Expand Up @@ -304,7 +304,7 @@ public function createNote($FOLDER, $in_name, $in_group) {
$fileindb = false;
$filedeldb = false;
$ret = -1;
$query = "SELECT id, name, grouping, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$query = "SELECT id, name, `grouping`, mtime, deleted FROM *PREFIX*ownnote WHERE uid=? and name=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group))->fetchAll();
foreach($results as $result)
if ($result['deleted'] == 0) {
Expand All @@ -314,7 +314,7 @@ public function createNote($FOLDER, $in_name, $in_group) {
$filedeldb = true;
}
if ($filedeldb) {
$query = "DELETE FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$query = "DELETE FROM *PREFIX*ownnote WHERE uid=? and name=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group));
}
if (! $fileindb) {
Expand All @@ -329,7 +329,7 @@ public function createNote($FOLDER, $in_name, $in_group) {
$mtime = $info['mtime'];
}
}
$query = "INSERT INTO *PREFIX*ownnote (uid, name, grouping, mtime, note, shared) VALUES (?,?,?,?,?,?)";
$query = "INSERT INTO *PREFIX*ownnote (uid, name, `grouping`, mtime, note, shared) VALUES (?,?,?,?,?,?)";
$this->db->executeQuery($query, Array($uid,$name,$group,$mtime,'',''));
$ret = $this->db->lastInsertId('*PREFIX*ownnote');
}
Expand All @@ -341,9 +341,9 @@ public function deleteNote($FOLDER, $name, $group) {
$now = new DateTime();
$mtime = $now->getTimestamp();
$uid = \OCP\User::getUser();
$query = "UPDATE *PREFIX*ownnote set note='', deleted=1, mtime=? WHERE uid=? and name=? and grouping=?";
$query = "UPDATE *PREFIX*ownnote set note='', deleted=1, mtime=? WHERE uid=? and name=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($mtime, $uid, $name, $group));
$query = "SELECT id FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$query = "SELECT id FROM *PREFIX*ownnote WHERE uid=? and name=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group))->fetchAll();
foreach($results as $result) {
$query2 = "DELETE FROM *PREFIX*ownnote_parts WHERE id=?";
Expand All @@ -363,7 +363,7 @@ public function deleteNote($FOLDER, $name, $group) {
public function editNote($name, $group) {
$ret = "";
$uid = \OCP\User::getUser();
$query = "SELECT id,note FROM *PREFIX*ownnote WHERE uid=? and name=? and grouping=?";
$query = "SELECT id,note FROM *PREFIX*ownnote WHERE uid=? and name=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($uid, $name, $group))->fetchAll();
foreach($results as $result) {
$ret = $result['note'];
Expand Down Expand Up @@ -397,7 +397,7 @@ public function saveNote($FOLDER, $name, $group, $content, $in_mtime) {
$mtime = $info['mtime'];
}
}
$query = "UPDATE *PREFIX*ownnote set note='', mtime=? WHERE uid=? and name=? and grouping=?";
$query = "UPDATE *PREFIX*ownnote set note='', mtime=? WHERE uid=? and name=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($mtime, $uid, $name, $group));
$query = "DELETE FROM *PREFIX*ownnote_parts WHERE id=?";
$results = $this->db->executeQuery($query, Array($id));
Expand Down Expand Up @@ -426,7 +426,7 @@ public function renameNote($FOLDER, $name, $group, $in_newname, $in_newgroup) {
public function deleteGroup($FOLDER, $group) {
// We actually need to just rename all the notes
$uid = \OCP\User::getUser();
$query = "SELECT id, name, grouping, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and grouping=?";
$query = "SELECT id, name, `grouping`, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($uid, $group))->fetchAll();
foreach($results as $result) {
$this->renameNote($FOLDER, $result['name'], $group, $result['name'], '');
Expand All @@ -436,7 +436,7 @@ public function deleteGroup($FOLDER, $group) {

public function renameGroup($FOLDER, $group, $newgroup) {
$uid = \OCP\User::getUser();
$query = "SELECT id, name, grouping, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and grouping=?";
$query = "SELECT id, name, `grouping`, mtime FROM *PREFIX*ownnote WHERE deleted=0 and uid=? and `grouping`=?";
$results = $this->db->executeQuery($query, Array($uid, $group))->fetchAll();
foreach($results as $result) {
$this->renameNote($FOLDER, $result['name'], $group, $result['name'], $newgroup);
Expand Down