|
From: <var...@us...> - 2024-01-12 18:43:35
|
Revision: 11071
http://sourceforge.net/p/phpwiki/code/11071
Author: vargenau
Date: 2024-01-12 18:43:33 +0000 (Fri, 12 Jan 2024)
Log Message:
-----------
PDO sqlite backend patches by Christof Meerwald
Modified Paths:
--------------
trunk/lib/DbSession/PDO.php
trunk/lib/DbSession/SQL.php
trunk/lib/DbSession/dba.php
trunk/lib/DbSession.php
trunk/lib/WikiDB/backend/PDO.php
trunk/schemas/sqlite-initialize.sql
Added Paths:
-----------
trunk/lib/WikiDB/backend/PDO_sqlite.php
Modified: trunk/lib/DbSession/PDO.php
===================================================================
--- trunk/lib/DbSession/PDO.php 2023-11-20 16:31:08 UTC (rev 11070)
+++ trunk/lib/DbSession/PDO.php 2024-01-12 18:43:33 UTC (rev 11071)
@@ -32,9 +32,9 @@
{
public $_backend_type = "PDO";
- public function __construct($dbh, $table)
+ public function __construct($backend, $table)
{
- $this->_dbh = $dbh;
+ $this->_backend = $backend;
$this->_table = $table;
session_set_save_handler(
@@ -49,11 +49,7 @@
public function & _connect()
{
- $dbh = &$this->_dbh;
- global $DBParams;
- $db = new WikiDB_backend_PDO($DBParams);
- $this->_dbh =& $db->_dbh;
- $this->_backend =& $db;
+ $dbh = &$this->_backend->_dbh;
return $dbh;
}
@@ -70,9 +66,6 @@
public function _disconnect()
{
- if (0 and $this->_dbh) {
- unset($this->_dbh);
- }
}
/**
@@ -118,6 +111,9 @@
$sth->bindParam(1, $id, PDO::PARAM_STR, 32);
if ($sth->execute()) {
$res = $sth->fetchColumn();
+ if (empty($res)) {
+ $res = '';
+ }
} else {
$res = '';
}
@@ -165,10 +161,19 @@
$remote_addr = $request->get('REMOTE_ADDR');
$this->_backend->beginTransaction();
- $delete = $dbh->prepare("DELETE FROM $table WHERE sess_id=?");
- $delete->bindParam(1, $id, PDO::PARAM_STR, 32);
- $delete->execute();
- $sth = $dbh->prepare("INSERT INTO $table"
+ $backend_type = $this->_backend->backendType();
+ if (substr($backend_type, 0, 5) == 'mysql' or
+ $backend_type == 'sqlite') {
+ // mysql/sqlite can do it as a single replace command
+ $insert = "REPLACE INTO";
+ } else {
+ // otherwise need to do it as a delete/insert
+ $delete = $dbh->prepare("DELETE FROM $table WHERE sess_id=?");
+ $delete->bindParam(1, $id, PDO::PARAM_STR, 32);
+ $delete->execute();
+ $insert = "INSERT INTO";
+ }
+ $sth = $dbh->prepare("$insert $table"
. " (sess_id, sess_data, sess_date, sess_ip)"
. " VALUES (?, ?, ?, ?)");
$sth->bindParam(1, $id, PDO::PARAM_STR, 32);
@@ -239,7 +244,7 @@
if (preg_match('|^[a-zA-Z0-9/+=]+$|', $data)) {
$data = base64_decode($data);
}
- if ($date < 908437560 or $date > 1588437560) {
+ if ($date < 908437560) {
$date = 0;
}
// session_data contains the <variable name> + "|" + <packed string>
Modified: trunk/lib/DbSession/SQL.php
===================================================================
--- trunk/lib/DbSession/SQL.php 2023-11-20 16:31:08 UTC (rev 11070)
+++ trunk/lib/DbSession/SQL.php 2024-01-12 18:43:33 UTC (rev 11071)
@@ -36,9 +36,9 @@
{
public $_backend_type = "SQL";
- public function __construct($dbh, $table)
+ public function __construct($backend, $table)
{
- $this->_dbh = $dbh;
+ $this->_dbh = $backend->_dbh;
$this->_table = $table;
session_set_save_handler(
@@ -248,7 +248,7 @@
if (preg_match('|^[a-zA-Z0-9/+=]+$|', $data)) {
$data = base64_decode($data);
}
- if ($date < 908437560 or $date > 1588437560) {
+ if ($date < 908437560) {
$date = 0;
}
// session_data contains the <variable name> + "|" + <packed string>
Modified: trunk/lib/DbSession/dba.php
===================================================================
--- trunk/lib/DbSession/dba.php 2023-11-20 16:31:08 UTC (rev 11070)
+++ trunk/lib/DbSession/dba.php 2024-01-12 18:43:33 UTC (rev 11071)
@@ -37,9 +37,9 @@
{
public $_backend_type = "dba";
- public function __construct($dbh, $table)
+ public function __construct($backend, $table)
{
- $this->_dbh = $dbh;
+ $this->_dbh = $backend->_dbh;
session_set_save_handler(
array(&$this, 'open'),
array(&$this, 'close'),
@@ -221,7 +221,7 @@
}
// session_data contains the <variable name> + "|" + <packed string>
// we need just the wiki_user object (might be array as well)
- if ($date < 908437560 or $date > 1588437560) {
+ if ($date < 908437560) {
$date = 0;
}
$user = strstr($packed, "wiki_user|");
Modified: trunk/lib/DbSession.php
===================================================================
--- trunk/lib/DbSession.php 2023-11-20 16:31:08 UTC (rev 11070)
+++ trunk/lib/DbSession.php 2024-01-12 18:43:33 UTC (rev 11071)
@@ -52,8 +52,7 @@
$class = "DbSession_" . $db_type;
if (class_exists($class)) {
- // dba has no ->_dbh, so this is used for the session link
- $this->_backend = new $class($dbh->_backend->_dbh, $table);
+ $this->_backend = new $class($dbh->_backend, $table);
return;
}
}
Modified: trunk/lib/WikiDB/backend/PDO.php
===================================================================
--- trunk/lib/WikiDB/backend/PDO.php 2023-11-20 16:31:08 UTC (rev 11070)
+++ trunk/lib/WikiDB/backend/PDO.php 2024-01-12 18:43:33 UTC (rev 11071)
@@ -82,16 +82,11 @@
}
} else {
list($driver, $dsn) = explode(":", $dbparams['dsn'], 2);
- foreach (explode(";", trim($dsn)) as $pair) {
- if ($pair) {
- list($option, $value) = explode("=", $pair, 2);
- $this->_parsedDSN[$option] = $value;
- }
- }
- $this->_dbh->database = isset($this->_parsedDSN['database'])
- ? $this->_parsedDSN['database']
- : $this->_parsedDSN['dbname'];
+ $this->_parsedDSN = array();
}
+ if (empty($this->_parsedDSN['username'])) {
+ $this->_parsedDSN['username'] = '';
+ }
if (empty($this->_parsedDSN['password'])) {
$this->_parsedDSN['password'] = '';
}
@@ -129,7 +124,7 @@
$this->_hasTransactions = true;
try {
$this->_dbh->beginTransaction();
- $this->commit();
+ $this->_dbh->commit();
} catch (PDOException $e) {
$this->_hasTransactions = false;
}
@@ -404,7 +399,8 @@
}
if (empty($id)) {
//mysql, mysqli or mysqlt
- if (substr($dbh->databaseType, 0, 5) == 'mysql') {
+ if (substr($dbh->databaseType, 0, 5) == 'mysql' or
+ $dbh->databaseType == 'sqlite') {
// have auto-incrementing, atomic version
$sth = $dbh->prepare("INSERT INTO $page_tbl"
. " (id,pagename)"
@@ -576,7 +572,8 @@
$id = $this->_get_pageid($pagename, true);
$backend_type = $this->backendType();
// optimize: mysql can do this with one REPLACE INTO.
- if (substr($backend_type, 0, 5) == 'mysql') {
+ if (substr($backend_type, 0, 5) == 'mysql' or
+ $backend_type == 'sqlite') {
$sth = $dbh->prepare("REPLACE INTO $version_tbl"
. " (id,version,mtime,minor_edit,content,versiondata)"
. " VALUES(?,?,?,?,?,?)");
@@ -715,7 +712,7 @@
if ($sth->fetchColumn()) {
// We're still in the link table (dangling link) so we can't delete this
// altogether.
- $dbh->query("UPDATE $page_tbl SET hits=0, pagedata='' WHERE id=$id");
+ $dbh->query("UPDATE $page_tbl SET hits=0, pagedata='', cached_html=NULL WHERE id=$id");
$result = 0;
} else {
$dbh->query("DELETE FROM $page_tbl WHERE id=$id");
@@ -1186,7 +1183,8 @@
// optimize: mysql can do this with one REPLACE INTO.
$backend_type = $this->backendType();
- if (substr($backend_type, 0, 5) == 'mysql') {
+ if (substr($backend_type, 0, 5) == 'mysql' or
+ $backend_type == 'sqlite') {
$sth = $dbh->prepare("REPLACE INTO $recent_tbl"
. " (id, latestversion, latestmajor, latestminor)"
. " SELECT id, $maxversion, $maxmajor, $maxminor"
Added: trunk/lib/WikiDB/backend/PDO_sqlite.php
===================================================================
--- trunk/lib/WikiDB/backend/PDO_sqlite.php (rev 0)
+++ trunk/lib/WikiDB/backend/PDO_sqlite.php 2024-01-12 18:43:33 UTC (rev 11071)
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Copyright © 2023 $ThePhpWikiProgrammingTeam
+ *
+ * This file is part of PhpWiki.
+ *
+ * PhpWiki is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpWiki is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ */
+
+/**
+ * @author: Christof Meerwald
+ */
+require_once 'lib/WikiDB/backend/PDO.php';
+
+class WikiDB_backend_PDO_sqlite extends WikiDB_backend_PDO
+{
+ public function __construct($dbparams)
+ {
+ parent::__construct($dbparams);
+ }
+
+ public function backendType()
+ {
+ return 'sqlite';
+ }
+
+ /*
+ * offset specific syntax within sqlite
+ * convert from,count to SQL "LIMIT $count OFFSET $from"
+ */
+ public function _limit_sql($limit = false)
+ {
+ if ($limit) {
+ list($from, $count) = $this->limit($limit);
+ if ($from) {
+ $limit = " LIMIT $count OFFSET $from";
+ } else {
+ $limit = " LIMIT $count";
+ }
+ } else {
+ $limit = '';
+ }
+ return $limit;
+ }
+}
Modified: trunk/schemas/sqlite-initialize.sql
===================================================================
--- trunk/schemas/sqlite-initialize.sql 2023-11-20 16:31:08 UTC (rev 11070)
+++ trunk/schemas/sqlite-initialize.sql 2024-01-12 18:43:33 UTC (rev 11071)
@@ -34,7 +34,8 @@
CREATE TABLE link (
linkfrom INTEGER NOT NULL,
- linkto INTEGER NOT NULL
+ linkto INTEGER NOT NULL,
+ relation INTEGER
);
CREATE INDEX linkfrom_index ON link (linkfrom);
CREATE INDEX linkto_index ON link (linkto);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|