From fde4cf0616e68d7b94f0991c1fcb434de4567c17 Mon Sep 17 00:00:00 2001 From: Eric Priou aka erixtekila Date: Thu, 5 Feb 2015 14:19:03 +0100 Subject: Fix fetched entries when localized --- inc/poche/Database.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/poche/Database.class.php') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index f6ba4708..6bac0f5d 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -293,7 +293,7 @@ class Database { $sql_limit = "LIMIT ".$limit." OFFSET 0"; } - $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=? ORDER BY id " . $sql_limit; + $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit; $query = $this->executeQuery($sql, array($user_id)); $entries = $query->fetchAll(); @@ -302,7 +302,7 @@ class Database { public function retrieveUnfetchedEntriesCount($user_id) { - $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; + $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?"; $query = $this->executeQuery($sql, array($user_id)); list($count) = $query->fetch(); -- cgit v1.2.3 From 054c9d8838e6d339f46d22f90655576fa1d1231d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 14 Feb 2015 15:12:02 +0100 Subject: (definitely) fixed utf8mb4 and check if user already exists in database before installing first user --- inc/poche/Database.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'inc/poche/Database.class.php') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 6bac0f5d..a987b7cc 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -31,10 +31,15 @@ class Database { $this->handle = new PDO($db_path); break; case 'mysql': - $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; - $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', - )); + if (MYSQL_USE_UTF8MB4) { + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', + )); + } else { + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); + } break; case 'postgres': $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; -- cgit v1.2.3 From 6b60741600321e4a2c414e91595b09d35516a3ea Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Feb 2015 00:43:18 +0100 Subject: alternative random function to fix #1082 --- inc/poche/Database.class.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'inc/poche/Database.class.php') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index a987b7cc..210ebb74 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -411,6 +411,14 @@ class Database { return $count; } + public function getRandomId($row, $user_id) { + $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? "; + $params = array($user_id, $row); + $query = $this->executeQuery($sql, $params); + + return $query->fetchAll(); + } + public function updateContent($id, $content, $user_id) { -- cgit v1.2.3 From cdee5e65701330e0b740640f471228d8b9b02a91 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 16 Feb 2015 15:18:24 +0100 Subject: much better fix for #1082 --- inc/poche/Database.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'inc/poche/Database.class.php') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 210ebb74..65675afe 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -411,12 +411,14 @@ class Database { return $count; } - public function getRandomId($row, $user_id) { - $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? "; - $params = array($user_id, $row); - $query = $this->executeQuery($sql, $params); + public function getRandomId($user_id) { + $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; + $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; + $params = array($user_id); + $query = $this->executeQuery($sql, $params); + $id = $query->fetchAll(); - return $query->fetchAll(); + return $id; } -- cgit v1.2.3