mirror of
https://github.com/cosmocode/sqlite.git
synced 2025-07-25 17:11:50 +00:00
Automatic code style fixes
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @noinspection PhpUndefinedMethodInspection
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
*/
|
||||
|
||||
|
||||
namespace dokuwiki\plugin\sqlite;
|
||||
|
||||
/**
|
||||
@ -12,7 +12,6 @@ namespace dokuwiki\plugin\sqlite;
|
||||
*/
|
||||
class Functions
|
||||
{
|
||||
|
||||
/**
|
||||
* Register all standard functions
|
||||
*
|
||||
@ -74,7 +73,7 @@ class Functions
|
||||
if (empty($context['data'][0])) {
|
||||
return null;
|
||||
}
|
||||
return join($context['sep'], $context['data']);
|
||||
return implode($context['sep'], $context['data']);
|
||||
}
|
||||
|
||||
|
||||
@ -119,7 +118,6 @@ class Functions
|
||||
static $cache = [];
|
||||
if (!isset($cache[$pageid])) {
|
||||
$cache[$pageid] = page_exists($pageid);
|
||||
|
||||
}
|
||||
return (int)$cache[$pageid];
|
||||
}
|
||||
@ -157,5 +155,4 @@ class Functions
|
||||
resolve_pageid($ns, $page, $exists);
|
||||
return $page;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use dokuwiki\Extension\Event;
|
||||
|
||||
class QuerySaver
|
||||
{
|
||||
|
||||
protected $db;
|
||||
protected $upstream;
|
||||
|
||||
|
20
SQLiteDB.php
20
SQLiteDB.php
@ -16,7 +16,7 @@ use dokuwiki\Logger;
|
||||
*/
|
||||
class SQLiteDB
|
||||
{
|
||||
const FILE_EXTENSION = '.sqlite3';
|
||||
public const FILE_EXTENSION = '.sqlite3';
|
||||
|
||||
/** @var \PDO */
|
||||
protected $pdo;
|
||||
@ -239,8 +239,10 @@ class SQLiteDB
|
||||
}
|
||||
|
||||
/** @noinspection SqlResolve */
|
||||
$sql = $command . ' INTO "' . $table . '" (' . join(',', $columns) . ') VALUES (' . join(',',
|
||||
$placeholders) . ')';
|
||||
$sql = $command . ' INTO "' . $table . '" (' . implode(',', $columns) . ') VALUES (' . implode(
|
||||
',',
|
||||
$placeholders
|
||||
) . ')';
|
||||
$stm = $this->query($sql, $values);
|
||||
$success = $stm->rowCount();
|
||||
$stm->closeCursor();
|
||||
@ -371,7 +373,7 @@ class SQLiteDB
|
||||
$sql = "SELECT * FROM " . $table['name'];
|
||||
$res = $this->query($sql);
|
||||
while ($row = $res->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$values = join(',', array_map(function ($value) {
|
||||
$values = implode(',', array_map(function ($value) {
|
||||
if ($value === null) return 'NULL';
|
||||
return $this->pdo->quote($value);
|
||||
}, $row));
|
||||
@ -415,7 +417,7 @@ class SQLiteDB
|
||||
'sqlite' => $this->helper,
|
||||
'adapter' => $this,
|
||||
];
|
||||
$event = new \Doku_Event('PLUGIN_SQLITE_DATABASE_UPGRADE', $data);
|
||||
$event = new Event('PLUGIN_SQLITE_DATABASE_UPGRADE', $data);
|
||||
|
||||
$this->pdo->beginTransaction();
|
||||
try {
|
||||
@ -425,11 +427,9 @@ class SQLiteDB
|
||||
foreach ($sql as $query) {
|
||||
$this->pdo->exec($query);
|
||||
}
|
||||
} else {
|
||||
if (!$event->result) {
|
||||
// advise before returned false, but the result was false
|
||||
throw new \PDOException('Plugin event did not signal success');
|
||||
}
|
||||
} elseif (!$event->result) {
|
||||
// advise before returned false, but the result was false
|
||||
throw new \PDOException('Plugin event did not signal success');
|
||||
}
|
||||
$this->setOpt('dbversion', $newVersion);
|
||||
$this->pdo->commit();
|
||||
|
35
Tools.php
35
Tools.php
@ -2,8 +2,8 @@
|
||||
|
||||
namespace dokuwiki\plugin\sqlite;
|
||||
|
||||
class Tools {
|
||||
|
||||
class Tools
|
||||
{
|
||||
/**
|
||||
* Split sql queries on semicolons, unless when semicolons are quoted
|
||||
*
|
||||
@ -13,36 +13,37 @@ class Tools {
|
||||
* @param string $sql
|
||||
* @return string[] sql queries
|
||||
*/
|
||||
public static function SQLstring2array($sql) {
|
||||
$statements = array();
|
||||
public static function SQLstring2array($sql)
|
||||
{
|
||||
$statements = [];
|
||||
$len = strlen($sql);
|
||||
|
||||
// Simple state machine to "parse" sql into single statements
|
||||
$in_str = false;
|
||||
$in_com = false;
|
||||
$statement = '';
|
||||
for($i=0; $i<$len; $i++){
|
||||
$prev = $i ? $sql[$i-1] : "\n";
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$prev = $i ? $sql[$i - 1] : "\n";
|
||||
$char = $sql[$i];
|
||||
$next = $i < ($len - 1) ? $sql[$i+1] : '';
|
||||
$next = $i < ($len - 1) ? $sql[$i + 1] : '';
|
||||
|
||||
// in comment? ignore everything until line end
|
||||
if($in_com){
|
||||
if($char == "\n"){
|
||||
if ($in_com) {
|
||||
if ($char == "\n") {
|
||||
$in_com = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// handle strings
|
||||
if($in_str){
|
||||
if($char == "'"){
|
||||
if($next == "'"){
|
||||
if ($in_str) {
|
||||
if ($char == "'") {
|
||||
if ($next == "'") {
|
||||
// current char is an escape for the next
|
||||
$statement .= $char . $next;
|
||||
$i++;
|
||||
continue;
|
||||
}else{
|
||||
} else {
|
||||
// end of string
|
||||
$statement .= $char;
|
||||
$in_str = false;
|
||||
@ -55,20 +56,20 @@ class Tools {
|
||||
}
|
||||
|
||||
// new comment?
|
||||
if($char == '-' && $next == '-' && $prev == "\n"){
|
||||
if ($char == '-' && $next == '-' && $prev == "\n") {
|
||||
$in_com = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// new string?
|
||||
if($char == "'"){
|
||||
if ($char == "'") {
|
||||
$in_str = true;
|
||||
$statement .= $char;
|
||||
continue;
|
||||
}
|
||||
|
||||
// the real delimiter
|
||||
if($char == ';'){
|
||||
if ($char == ';') {
|
||||
$statements[] = trim($statement);
|
||||
$statement = '';
|
||||
continue;
|
||||
@ -77,7 +78,7 @@ class Tools {
|
||||
// some standard query stuff
|
||||
$statement .= $char;
|
||||
}
|
||||
if($statement) $statements[] = trim($statement);
|
||||
if ($statement) $statements[] = trim($statement);
|
||||
|
||||
return array_filter($statements); // remove empty statements
|
||||
}
|
||||
|
17
admin.php
17
admin.php
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\Extension\AdminPlugin;
|
||||
use dokuwiki\Form\Form;
|
||||
use dokuwiki\Form\InputElement;
|
||||
use dokuwiki\plugin\sqlite\QuerySaver;
|
||||
@ -12,13 +13,13 @@ use dokuwiki\plugin\sqlite\Tools;
|
||||
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
class admin_plugin_sqlite extends DokuWiki_Admin_Plugin
|
||||
class admin_plugin_sqlite extends AdminPlugin
|
||||
{
|
||||
/** @var SQLiteDB */
|
||||
protected $db = null;
|
||||
protected $db;
|
||||
|
||||
/** @var QuerySaver */
|
||||
protected $querySaver = null;
|
||||
protected $querySaver;
|
||||
|
||||
/** @inheritdoc */
|
||||
public function getMenuSort()
|
||||
@ -148,12 +149,7 @@ class admin_plugin_sqlite extends DokuWiki_Admin_Plugin
|
||||
$dbfiles = glob($conf['metadir'] . '/*.sqlite3');
|
||||
if (is_array($dbfiles)) foreach ($dbfiles as $file) {
|
||||
$db = basename($file, '.sqlite3');
|
||||
$toc[] = array(
|
||||
'link' => wl($ID, array('do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken())),
|
||||
'title' => $db,
|
||||
'level' => 2,
|
||||
'type' => 'ul',
|
||||
);
|
||||
$toc[] = ['link' => wl($ID, ['do' => 'admin', 'page' => 'sqlite', 'db' => $db, 'sectok' => getSecurityToken()]), 'title' => $db, 'level' => 2, 'type' => 'ul'];
|
||||
}
|
||||
|
||||
return $toc;
|
||||
@ -238,7 +234,8 @@ class admin_plugin_sqlite extends DokuWiki_Admin_Plugin
|
||||
'page' => 'sqlite',
|
||||
'db' => $this->db ? $this->db->getDBName() : '',
|
||||
'sectok' => getSecurityToken(),
|
||||
], $params
|
||||
],
|
||||
$params
|
||||
);
|
||||
|
||||
return wl($ID, $params, false, $form ? '&' : '&');
|
||||
|
42
helper.php
42
helper.php
@ -6,22 +6,24 @@
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
*/
|
||||
|
||||
use dokuwiki\Extension\Plugin;
|
||||
use dokuwiki\plugin\sqlite\SQLiteDB;
|
||||
use dokuwiki\plugin\sqlite\Tools;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* For compatibility with previous adapter implementation.
|
||||
*/
|
||||
if(!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo');
|
||||
if (!defined('DOKU_EXT_PDO')) define('DOKU_EXT_PDO', 'pdo');
|
||||
class helper_plugin_sqlite_adapter_dummy
|
||||
{
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return DOKU_EXT_PDO;
|
||||
}
|
||||
|
||||
public function setUseNativeAlter($set) {}
|
||||
public function setUseNativeAlter($set)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,10 +33,10 @@ class helper_plugin_sqlite_adapter_dummy
|
||||
* @author Andreas Gohr <gohr@cosmocode.de>
|
||||
* @deprecated 2023-03-15
|
||||
*/
|
||||
class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
class helper_plugin_sqlite extends Plugin
|
||||
{
|
||||
/** @var SQLiteDB|null */
|
||||
protected $adapter = null;
|
||||
protected $adapter;
|
||||
|
||||
/** @var array result cache */
|
||||
protected $data;
|
||||
@ -89,7 +91,7 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
*/
|
||||
public function init($dbname, $updatedir)
|
||||
{
|
||||
if(!defined('DOKU_UNITTEST')) { // for now we don't want to trigger the deprecation warning in the tests
|
||||
if (!defined('DOKU_UNITTEST')) { // for now we don't want to trigger the deprecation warning in the tests
|
||||
dbg_deprecated(SQLiteDB::class);
|
||||
}
|
||||
|
||||
@ -108,7 +110,7 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
* @param SQLiteDB $adapter
|
||||
* @return void
|
||||
*/
|
||||
function setAdapter($adapter)
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
@ -182,17 +184,18 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
* @return bool|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareSql($args) {
|
||||
public function prepareSql($args)
|
||||
{
|
||||
|
||||
$sql = trim(array_shift($args));
|
||||
$sql = rtrim($sql, ';');
|
||||
|
||||
if(!$sql) {
|
||||
if (!$sql) {
|
||||
throw new \Exception('No SQL statement given', -1);
|
||||
}
|
||||
|
||||
$argc = count($args);
|
||||
if($argc > 0 && is_array($args[0])) {
|
||||
if ($argc > 0 && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
$argc = count($args);
|
||||
}
|
||||
@ -201,10 +204,10 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
$qmc = substr_count($sql, '?');
|
||||
if ($argc < $qmc) {
|
||||
throw new \Exception('Not enough arguments passed for statement. ' .
|
||||
'Expected '.$qmc.' got '. $argc.' - '.hsc($sql));
|
||||
} elseif($argc > $qmc) {
|
||||
'Expected ' . $qmc . ' got ' . $argc . ' - ' . hsc($sql));
|
||||
} elseif ($argc > $qmc) {
|
||||
throw new \Exception('Too much arguments passed for statement. ' .
|
||||
'Expected '.$qmc.' got '. $argc.' - '.hsc($sql));
|
||||
'Expected ' . $qmc . ' got ' . $argc . ' - ' . hsc($sql));
|
||||
}
|
||||
|
||||
// explode at wildcard, then join again
|
||||
@ -212,7 +215,7 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
$args = array_map([$this->adapter->getPdo(), 'quote'], $args);
|
||||
$sql = '';
|
||||
|
||||
while(($part = array_shift($parts)) !== null) {
|
||||
while (($part = array_shift($parts)) !== null) {
|
||||
$sql .= $part;
|
||||
$sql .= array_shift($args);
|
||||
}
|
||||
@ -356,7 +359,7 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
public function quote_and_join($vals, $sep = ',')
|
||||
{
|
||||
$vals = array_map([$this->adapter->getPdo(), 'quote'], $vals);
|
||||
return join($sep, $vals);
|
||||
return implode($sep, $vals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -391,7 +394,7 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
*/
|
||||
public function SQLstring2array($sql)
|
||||
{
|
||||
if(!DOKU_UNITTEST) { // for now we don't want to trigger the deprecation warning in the tests
|
||||
if (!DOKU_UNITTEST) { // for now we don't want to trigger the deprecation warning in the tests
|
||||
dbg_deprecated(Tools::class . '::SQLstring2array');
|
||||
}
|
||||
return Tools::SQLstring2array($sql);
|
||||
@ -400,7 +403,8 @@ class helper_plugin_sqlite extends DokuWiki_Plugin
|
||||
/**
|
||||
* @deprecated needs to be fixed in stuct and structpublish
|
||||
*/
|
||||
public function doTransaction($sql, $sqlpreparing = true) {
|
||||
public function doTransaction($sql, $sqlpreparing = true)
|
||||
{
|
||||
throw new \Exception(
|
||||
'This method seems to never have done what it suggests. Please use the query() function instead.'
|
||||
);
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\Extension\Plugin;
|
||||
|
||||
/**
|
||||
* DokuWiki Plugin sqlite (Helper Component)
|
||||
*
|
||||
@ -8,7 +10,7 @@
|
||||
*/
|
||||
|
||||
|
||||
class helper_plugin_sqlite_db extends DokuWiki_Plugin
|
||||
class helper_plugin_sqlite_db extends Plugin
|
||||
{
|
||||
/** @var helper_plugin_sqlite */
|
||||
protected $sqlite;
|
||||
@ -27,7 +29,6 @@ class helper_plugin_sqlite_db extends DokuWiki_Plugin
|
||||
*/
|
||||
protected function init()
|
||||
{
|
||||
/** @var helper_plugin_sqlite $sqlite */
|
||||
$this->sqlite = plugin_load('helper', 'sqlite');
|
||||
|
||||
// initialize the database connection
|
||||
|
@ -5,3 +5,4 @@ date 2023-08-17
|
||||
name sqlite plugin
|
||||
desc A helper plugin to easily access a SQLite database
|
||||
url http://www.dokuwiki.org/plugin:sqlite
|
||||
minphp 7.3
|
||||
|
Reference in New Issue
Block a user