summaryrefslogtreecommitdiffstatshomepage
path: root/src/SemanticScuttle/Service
diff options
context:
space:
mode:
authorGravatar Tom Willemse2024-06-10 23:38:09 -0700
committerGravatar Tom Willemse2024-06-10 23:38:09 -0700
commiteb81d7b851f51ab5919be78493737ef2abf49aab (patch)
tree8559f83f83e1cab0b6cb9a0d0fa94f8b0bcb1959 /src/SemanticScuttle/Service
parentc6101ba37422dcfcf16131d9dc41692e0725aa81 (diff)
downloadscuttle-eb81d7b851f51ab5919be78493737ef2abf49aab.tar.gz
scuttle-eb81d7b851f51ab5919be78493737ef2abf49aab.zip
Fix using SQLite as a database engine
- The ‘sqlite_*’ functions don't exist anymore in PHP 8. They have been replaced with several ‘SQLite3*’ classes. - There are some differences between MySQL and SQLite queries that showed up while doing this work. These differences have been pushed into a QueryBuilder class so that the other database engines don't have to be modified. This is done in an ad-hoc basis for now, just to get things working. - SQLite doesn't support the ‘!’ negation operator used as ‘!ISNULL(...)’, instead I use ‘IIF(...)’. - SQLite doesn't support a ‘LEFT(...)’ function, instead I use ‘SUBSTRING(..., 0, ...)’. - The SQLite3 module doesn't provide a connection identifier, instead you use an object that represents the connection. - SQLite doesn't support the ‘ALL’ keyword (or at least doesn't support it in the same way MySQL does). Instead of ‘<> ALL <subquery>’ I use ‘NOT IN <subquery>’. - The ‘SQLite3*’ classes don't provide any way to determine how many rows have been returned without iterating through all of them, so any place that tries to figure out the rows beforehand just doesn't anymore. - All the database engine classes require a ‘QueryBuilder’ instance. The sqlite one uses a specialized one. I can't test most of these database engines, so I'm focusing on SQLite and MySQL/MariaDB for now.
Diffstat (limited to 'src/SemanticScuttle/Service')
-rw-r--r--src/SemanticScuttle/Service/Bookmark.php4
-rw-r--r--src/SemanticScuttle/Service/Bookmark2Tag.php12
-rw-r--r--src/SemanticScuttle/Service/Factory.php2
-rw-r--r--src/SemanticScuttle/Service/Tag2Tag.php2
-rw-r--r--src/SemanticScuttle/Service/User.php8
5 files changed, 10 insertions, 18 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 17f91b1..e157fc4 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -138,7 +138,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
if ($GLOBALS['enableVoting'] && $userservice->isLoggedOn()) {
$cuid = $userservice->getCurrentUserId();
$vs = SemanticScuttle_Service_Factory::get('Vote');
- $query_1 .= ', !ISNULL(V.bId) as hasVoted, V.vote as vote';
+ $query_1 .= ', ' . $this->db->QueryBuilder->isNotNull('V.bId') . ' as hasVoted, V.vote as vote';
$query_2 .= ' LEFT JOIN ' . $vs->getTableName() . ' AS V'
. ' ON B.bId = V.bId'
. ' AND V.uId = ' . (int)$cuid;
@@ -789,7 +789,7 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService
if ($GLOBALS['enableVoting'] && $userservice->isLoggedOn()) {
$cuid = $userservice->getCurrentUserId();
$vs = SemanticScuttle_Service_Factory::get('Vote');
- $query_1 .= ', !ISNULL(V.bId) as hasVoted, V.vote as vote';
+ $query_1 .= ', ' . $this->db->QueryBuilder->isNotNull('V.bId') . ' as hasVoted, V.vote as vote';
$query_2 .= ' LEFT JOIN ' . $vs->getTableName() . ' AS V'
. ' ON B.bId = V.bId'
. ' AND V.uId = ' . (int)$cuid;
diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php
index 910da48..2b95bd8 100644
--- a/src/SemanticScuttle/Service/Bookmark2Tag.php
+++ b/src/SemanticScuttle/Service/Bookmark2Tag.php
@@ -287,7 +287,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$query = 'SELECT tag FROM ' . $this->getTableName()
. ' WHERE bId = ' . intval($bookmarkid);
if (!$systemTags) {
- $query .= ' AND LEFT(tag, 7) <> "system:"';
+ $query .= ' AND ' . $this->db->QueryBuilder->left('tag', 7) . ' <> "system:"';
}
$query .= ' ORDER BY id ASC';
@@ -329,7 +329,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$query = 'SELECT tag, bId FROM ' . $this->getTableName()
. ' WHERE bId IN (' . implode(',', $bookmarkids) . ')'
- . ' AND LEFT(tag, 7) <> "system:"'
+ . ' AND ' . $this->db->QueryBuilder->left('tag', 7) . ' <> "system:"'
. ' ORDER BY id, bId ASC';
if (!($dbresult = $this->db->sql_query($query))) {
@@ -367,7 +367,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$conditions['B.bStatus'] = 0;
}
- $query .= ' WHERE '. $this->db->sql_build_array('SELECT', $conditions) .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag';
+ $query .= ' WHERE '. $this->db->sql_build_array('SELECT', $conditions) .' AND ' . $this->db->QueryBuilder->left('T.tag', 7) . ' <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag';
if (!($dbresult = $this->db->sql_query($query))) {
message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db);
@@ -414,7 +414,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$query_2 .= ', '. $this->getTableName() .' AS T'. $i;
$query_4 .= ' AND T'. $i .'.bId = B.bId AND T'. $i .'.tag = "'. $this->db->sql_escape($tags[$i - 1]) .'" AND T0.tag <> "'. $this->db->sql_escape($tags[$i - 1]) .'"';
}
- $query_5 = ' AND LEFT(T0.tag, 7) <> "system:" GROUP BY T0.tag ORDER BY bCount DESC, T0.tag';
+ $query_5 = ' AND ' . $this->db->QueryBuilder->left('T0.tag', 7) . ' <> "system:" GROUP BY T0.tag ORDER BY bCount DESC, T0.tag';
$query = $query_1 . $query_2 . $query_3 . $query_4 . $query_5;
if (! ($dbresult = $this->db->sql_query_limit($query, $limit)) ){
@@ -445,7 +445,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
$privacy = ' AND B.bStatus = 0 ';
}
- $query = 'SELECT T.tag, COUNT(T.tag) AS bCount FROM '.$GLOBALS['tableprefix'].'bookmarks AS B LEFT JOIN '.$GLOBALS['tableprefix'].'bookmarks2tags AS T ON B.bId = T.bId WHERE B.bHash = \''. $this->db->sql_escape($hash) .'\' '. $privacy .'AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC';
+ $query = 'SELECT T.tag, COUNT(T.tag) AS bCount FROM '.$GLOBALS['tableprefix'].'bookmarks AS B LEFT JOIN '.$GLOBALS['tableprefix'].'bookmarks2tags AS T ON B.bId = T.bId WHERE B.bHash = \''. $this->db->sql_escape($hash) .'\' '. $privacy .'AND ' . $this->db->QueryBuilder->left('T.tag', 7) . ' <> "system:" GROUP BY T.tag ORDER BY bCount DESC';
if (!($dbresult = $this->db->sql_query_limit($query, $limit))) {
message_die(GENERAL_ERROR, 'Could not get related tags for this hash', '', __LINE__, __FILE__, $query, $this->db);
@@ -599,7 +599,7 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
. '%\'';
}
- $query .= ' AND LEFT(T.tag, 7) <> "system:"'
+ $query .= ' AND ' . $this->db->QueryBuilder->left('T.tag', 7) . ' <> "system:"'
. ' GROUP BY T.tag'
. ' ORDER BY bCount DESC, tag';
diff --git a/src/SemanticScuttle/Service/Factory.php b/src/SemanticScuttle/Service/Factory.php
index b661cdb..4cc2efa 100644
--- a/src/SemanticScuttle/Service/Factory.php
+++ b/src/SemanticScuttle/Service/Factory.php
@@ -124,7 +124,7 @@ class SemanticScuttle_Service_Factory
$db->sql_connect(
$dbhost, $dbuser, $dbpass, $dbname, $dbport, $dbpersist
);
- if (!$db->db_connect_id) {
+ if (!$db->db_connection) {
message_die(
CRITICAL_ERROR,
'Could not connect to the database',
diff --git a/src/SemanticScuttle/Service/Tag2Tag.php b/src/SemanticScuttle/Service/Tag2Tag.php
index 9dddc44..9a5d0f2 100644
--- a/src/SemanticScuttle/Service/Tag2Tag.php
+++ b/src/SemanticScuttle/Service/Tag2Tag.php
@@ -270,7 +270,7 @@ class SemanticScuttle_Service_Tag2Tag extends SemanticScuttle_DbService
$tsts =SemanticScuttle_Service_Factory::get('TagStat');
$query.= ", ".$tsts->getTableName() ." tsts";
}
- $query.= " WHERE tts.tag1 <> ALL";
+ $query.= " WHERE tts.tag1 not in";
$query.= " (SELECT DISTINCT tag2 FROM `". $this->getTableName() ."`";
$query.= " WHERE relationType = '" . $this->db->sql_escape($relationType) . "'";
if($uId > 0) {
diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php
index 675c4fb..d527031 100644
--- a/src/SemanticScuttle/Service/User.php
+++ b/src/SemanticScuttle/Service/User.php
@@ -609,10 +609,6 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
$arrWatch = array();
- if ($this->db->sql_numrows($dbresult) == 0) {
- $this->db->sql_freeresult($dbresult);
- return $arrWatch;
- }
while ($row = $this->db->sql_fetchrow($dbresult)) {
$arrWatch[] = $row['watched'];
}
@@ -659,10 +655,6 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
}
$arrWatch = array();
- if ($this->db->sql_numrows($dbresult) == 0) {
- $this->db->sql_freeresult($dbresult);
- return $arrWatch;
- }
while ($row = $this->db->sql_fetchrow($dbresult)) {
$arrWatch[] = $row[$this->getFieldName('username')];
}