Compare commits
7 Commits
feature/TT
...
feature/TT
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
378d6c7527 | ||
|
|
5c6a5c2d20 | ||
|
|
b033a718ad | ||
|
|
51e3cc7c7f | ||
|
|
b7935dcb71 | ||
|
|
89e8f79cae | ||
|
|
1a027e5c7d |
46
4dev/tests/DB/CoreLibsDBSqLiteTest.php
Normal file
46
4dev/tests/DB/CoreLibsDBSqLiteTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for DB\SqLite
|
||||
* This will only test the SqLite parts
|
||||
* @coversDefaultClass \CoreLibs\DB\SqLite
|
||||
* @testdox \CoreLibs\SqLite method tests for extended DB interface
|
||||
*/
|
||||
final class CoreLibsDBESqLiteTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!extension_loaded('sqlite')) {
|
||||
$this->markTestSkipped(
|
||||
'The SqLite extension is not available.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @testdox DB\SqLite Class tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSqLite()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'DB\SqLite Tests have not yet been implemented'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
157
www/admin/class_test.db.sqlite.php
Normal file
157
www/admin/class_test.db.sqlite.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// turn on all error reporting
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', true);
|
||||
define('DATABASE', 'sqlite' . DIRECTORY_SEPARATOR);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-db';
|
||||
ob_end_flush();
|
||||
|
||||
$sql_file = BASE . MEDIA . DATABASE . "class_test.db.sqlite.sq3";
|
||||
|
||||
use CoreLibs\DB\SqLite;
|
||||
use CoreLibs\Debug\Support;
|
||||
use CoreLibs\Convert\SetVarType;
|
||||
|
||||
$log = new CoreLibs\Logging\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'log_file_id' => $LOG_FILE_ID,
|
||||
'log_per_date' => true,
|
||||
]);
|
||||
// db connection and attach logger
|
||||
$db = new CoreLibs\DB\SqLite($log, "sqlite:" . $sql_file);
|
||||
$db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB: SqLite';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
print "<hr>";
|
||||
|
||||
echo "Create Tables on demand<br>";
|
||||
|
||||
$query = <<<SQL
|
||||
CREATE TABLE IF NOT EXISTS test (
|
||||
test_id INTEGER PRIMARY KEY,
|
||||
c_text TEXT,
|
||||
c_integer INTEGER,
|
||||
c_integer_default INTEGER DEFAULT -1,
|
||||
c_bool BOOLEAN,
|
||||
c_datetime TEXT,
|
||||
c_datetime_microseconds TEXT,
|
||||
c_datetime_default TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
c_date TEXT,
|
||||
c_julian REAL,
|
||||
c_unixtime DATETIME,
|
||||
c_unixtime_alt DATETIME,
|
||||
c_numeric NUMERIC,
|
||||
c_real REAL,
|
||||
c_blob
|
||||
)
|
||||
SQL;
|
||||
$db->dbExec($query);
|
||||
// **********************
|
||||
$query = <<<SQL
|
||||
CREATE TABLE IF NOT EXISTS test_no_pk (
|
||||
c_text TEXT,
|
||||
c_integer INTEGER
|
||||
)
|
||||
SQL;
|
||||
$db->dbExec($query);
|
||||
|
||||
print "<hr>";
|
||||
|
||||
$table = 'test';
|
||||
echo "Table info for: " . $table . "<br>";
|
||||
|
||||
if (($table_info = $db->dbShowTableMetaData($table)) === false) {
|
||||
print "Read problem for: $table<br>";
|
||||
} else {
|
||||
print "TABLE INFO: <pre>" . print_r($table_info, true) . "</pre><br>";
|
||||
}
|
||||
|
||||
print "<hr>";
|
||||
|
||||
echo "Insert into 'test'<br>";
|
||||
|
||||
$query = <<<SQL
|
||||
INSERT INTO test (
|
||||
c_text, c_integer, c_bool,
|
||||
c_datetime, c_datetime_microseconds, c_date,
|
||||
c_julian, c_unixtime, c_unixtime_alt,
|
||||
c_numeric, c_real, c_blob
|
||||
) VALUES (
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
julianday(?), ?, unixepoch(?),
|
||||
?, ?, ?
|
||||
)
|
||||
SQL;
|
||||
$db->dbExecParams($query, [
|
||||
'test', rand(1, 100), true,
|
||||
date('Y-m-d H:i:s'), date_format(date_create("now"), 'Y-m-d H:i:s.u'), date('Y-m-d'),
|
||||
// julianday pass through
|
||||
date('Y-m-d H:i:s'),
|
||||
// use "U" if no unixepoch in query
|
||||
date('U'), date('Y-m-d H:i:s'),
|
||||
1.5, 10.5, 'Anything'
|
||||
]);
|
||||
|
||||
print "<hr>";
|
||||
|
||||
echo "Insert into 'test_no_pk'<br>";
|
||||
|
||||
$query = <<<SQL
|
||||
INSERT INTO test_no_pk (
|
||||
c_text, c_integer
|
||||
) VALUES (
|
||||
?, ?
|
||||
)
|
||||
SQL;
|
||||
$db->dbExecParams($query, ['test no pk', rand(100, 200)]);
|
||||
|
||||
print "<hr>";
|
||||
|
||||
$query = <<<SQL
|
||||
SELECT test_id, c_text, c_integer, c_integer_default, c_datetime_default
|
||||
FROM test
|
||||
SQL;
|
||||
while (is_array($row = $db->dbReturnArray($query))) {
|
||||
print "ROW: PK(test_id): " . $row["test_id"]
|
||||
. ", Text: " . $row["c_text"] . ", Int: " . $row["c_integer"]
|
||||
. ", Int Default: " . $row["c_integer_default"]
|
||||
. ", Date Default: " . $row["c_datetime_default"]
|
||||
. "<br>";
|
||||
}
|
||||
|
||||
echo "<hr>";
|
||||
|
||||
$query = <<<SQL
|
||||
SELECT rowid, c_text, c_integer
|
||||
FROM test_no_pk
|
||||
SQL;
|
||||
|
||||
while (is_array($row = $db->dbReturnArray($query))) {
|
||||
print "ROW[CURSOR]: PK(rowid): " . $row["rowid"]
|
||||
. ", Text: " . $row["c_text"] . ", Int: " . $row["c_integer"]
|
||||
. "<br>";
|
||||
}
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
@@ -10,16 +10,12 @@ class Email
|
||||
/** @var array<int,string> */
|
||||
private static array $email_regex_check = [
|
||||
0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
// . "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
|
||||
// fixed pattern matching for domain
|
||||
. "(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$", // MASTER
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
|
||||
1 => "@(.*)@(.*)", // double @
|
||||
2 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@", // wrong part before @
|
||||
// 3 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$", // wrong part after @
|
||||
3 => "@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.[a-zA-Z]{2,6}$", // wrong part after @
|
||||
// 4 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.", // wrong domain name part
|
||||
4 => "@@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(?:\.[A-Za-z0-9-]{1,63}(?<!-))*\.", // wrong domain name part
|
||||
5 => "\.[a-zA-Z]{2,6}$", // wrong top level part
|
||||
3 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$", // wrong part after @
|
||||
4 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.", // wrong domain name part
|
||||
5 => "\.([a-zA-Z]{2,6}){1}$", // wrong top level part
|
||||
6 => "@(.*)\.{2,}", // double .. in domain name part
|
||||
7 => "@.*\.$" // ends with a dot, top level, domain missing
|
||||
];
|
||||
|
||||
@@ -748,11 +748,8 @@ class ArrayHandler
|
||||
* sort ascending or descending with or without lower case convert
|
||||
* value only, will loose key connections unless preserve_keys is set to true
|
||||
*
|
||||
* @param array<mixed> $array Array to sort by values
|
||||
* @param bool $case_insensitive [false] Sort case insensitive
|
||||
* @param bool $reverse [false] Reverse sort
|
||||
* @param bool $maintain_keys [false] Maintain keys
|
||||
* @param int $flag [SORT_REGULAR] Sort flags
|
||||
* @param array<mixed> $array array to sort by values
|
||||
* @param int $params sort flags
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public static function sortArray(
|
||||
@@ -760,7 +757,7 @@ class ArrayHandler
|
||||
bool $case_insensitive = false,
|
||||
bool $reverse = false,
|
||||
bool $maintain_keys = false,
|
||||
int $flag = SORT_REGULAR
|
||||
int $params = SORT_REGULAR
|
||||
): array {
|
||||
$fk_sort_lower_case = function (string $a, string $b): int {
|
||||
return strtolower($a) <=> strtolower($b);
|
||||
@@ -775,8 +772,8 @@ class ArrayHandler
|
||||
) :
|
||||
(
|
||||
$maintain_keys ?
|
||||
($reverse ? arsort($array, $flag) : asort($array, $flag)) :
|
||||
($reverse ? rsort($array, $flag) : sort($array, $flag))
|
||||
($reverse ? arsort($array, $params) : asort($array, $params)) :
|
||||
($reverse ? rsort($array, $params) : sort($array, $params))
|
||||
);
|
||||
return $array;
|
||||
}
|
||||
@@ -784,9 +781,9 @@ class ArrayHandler
|
||||
/**
|
||||
* sort by key ascending or descending and return
|
||||
*
|
||||
* @param array<mixed> $array Array to srt
|
||||
* @param bool $case_insensitive [false] Sort keys case insenstive
|
||||
* @param bool $reverse [false] Reverse key sort
|
||||
* @param array<mixed> $array
|
||||
* @param bool $case_insensitive [false]
|
||||
* @param bool $reverse [false]
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public static function ksortArray(array $array, bool $case_insensitive = false, bool $reverse = false): array
|
||||
|
||||
@@ -55,10 +55,10 @@ class Json
|
||||
* Deos not throw errors
|
||||
*
|
||||
* @param array<mixed> $data
|
||||
* @param int $flags [JSON_UNESCAPED_UNICODE] json_encode flags as is
|
||||
* @param int $flags json_encode flags as is
|
||||
* @return string JSON string or '{}' if false
|
||||
*/
|
||||
public static function jsonConvertArrayTo(array $data, int $flags = JSON_UNESCAPED_UNICODE): string
|
||||
public static function jsonConvertArrayTo(array $data, int $flags = 0): string
|
||||
{
|
||||
$json_string = json_encode($data, $flags) ?: '{}';
|
||||
self::$json_last_error = json_last_error();
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
/**
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2025/7/17
|
||||
* CREATED: Ymd
|
||||
* DESCRIPTION:
|
||||
* SQLite IO basic interface
|
||||
* DescriptionHere
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\DB\SQL\Interface;
|
||||
namespace CoreLibs\DB\Interface;
|
||||
|
||||
interface DatabaseInterface
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace CoreLibs\DB;
|
||||
|
||||
use CoreLibs\Create\Hash;
|
||||
|
||||
class SqLite implements SQL\Interface\DatabaseInterface
|
||||
class SqLite implements Interface\DatabaseInterface
|
||||
{
|
||||
/** @var \CoreLibs\Logging\Logging logging */
|
||||
public \CoreLibs\Logging\Logging $log;
|
||||
@@ -116,7 +116,7 @@ class SqLite implements SQL\Interface\DatabaseInterface
|
||||
}
|
||||
// TODO: if not ":memory:" check if path to file is writeable by system
|
||||
// avoid double open
|
||||
if (!empty($this->dsn) && $dsn == $this->dsn) {
|
||||
if (!empty($this->dsn) && $dsn == $this->dsn && $this->dbh instanceof \PDO) {
|
||||
$this->log->info(
|
||||
"Connection already establisehd with this dsn",
|
||||
[
|
||||
@@ -151,8 +151,7 @@ class SqLite implements SQL\Interface\DatabaseInterface
|
||||
|
||||
/**
|
||||
* Table meta data
|
||||
* Note that if columns have multi entries multiple lines are returned
|
||||
* ?1 is equal to $1 in this query
|
||||
* Note that if columns have multi
|
||||
*
|
||||
* @param string $table
|
||||
* @return array<array<string,mixed>>|false
|
||||
@@ -336,7 +335,7 @@ class SqLite implements SQL\Interface\DatabaseInterface
|
||||
*/
|
||||
public function dbGetQueryHash(string $query, array $params = []): string
|
||||
{
|
||||
return Hash::hashLong(
|
||||
return Hash::__hashLong(
|
||||
$query . (
|
||||
$params !== [] ?
|
||||
'#' . json_encode($params) : ''
|
||||
@@ -416,7 +415,7 @@ class SqLite implements SQL\Interface\DatabaseInterface
|
||||
return $row;
|
||||
}
|
||||
|
||||
// MARK: other interface
|
||||
// MARK other interface
|
||||
|
||||
/**
|
||||
* get current db handler
|
||||
@@ -112,7 +112,7 @@ enum Level: int
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the passed $level is included in set level
|
||||
* Returns true if the passed $level is higher or equal to $this
|
||||
*
|
||||
* @param Level $level
|
||||
* @return bool
|
||||
|
||||
@@ -1475,15 +1475,14 @@ class Logging
|
||||
Level::Error, Level::Critical, Level::Alert, Level::Emergency
|
||||
] as $l
|
||||
) {
|
||||
print "Check: " . $this->log_level->getName() . " | " . $l->getName() . "<br>";
|
||||
if ($this->log_level->isHigherThan($l)) {
|
||||
print "L(gt): " . $this->log_level->getName() . " > " . $l->getName() . "<br>";
|
||||
print "L: " . $this->log_level->getName() . " > " . $l->getName() . "<br>";
|
||||
}
|
||||
if ($this->log_level->includes($l)) {
|
||||
print "L(le): " . $this->log_level->getName() . " <= " . $l->getName() . "<br>";
|
||||
print "L: " . $this->log_level->getName() . " <= " . $l->getName() . "<br>";
|
||||
}
|
||||
if ($this->log_level->isLowerThan($l)) {
|
||||
print "L(lt): " . $this->log_level->getName() . " < " . $l->getName() . "<br>";
|
||||
print "L: " . $this->log_level->getName() . " < " . $l->getName() . "<br>";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user