modifs.mineures sans commentaires
This commit is contained in:
parent
fdf19326b0
commit
1c57fcf041
|
@ -32,7 +32,7 @@ class CapacitorChannel {
|
|||
if ($primaryKeys === null && $columnDefinitions !== null) {
|
||||
$index = 0;
|
||||
foreach ($columnDefinitions as $col => $def) {
|
||||
if ($col == $index) {
|
||||
if ($col === $index) {
|
||||
$index++;
|
||||
if (preg_match('/\bprimary\s+key\s+\((.+)\)/i', $def, $ms)) {
|
||||
$primaryKeys = preg_split('/\s*,\s*/', trim($ms[1]));
|
||||
|
|
|
@ -4,4 +4,11 @@ namespace nur\sery\db\mysql;
|
|||
use nur\sery\db\pdo\Pdo;
|
||||
|
||||
class Mysql extends Pdo {
|
||||
function getDbname(): ?string {
|
||||
$url = $this->dbconn["name"] ?? null;
|
||||
if ($url !== null && preg_match('/^mysql(?::|.*;)dbname=([^;]+)/i', $url, $ms)) {
|
||||
return $ms[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,10 +36,11 @@ class MysqlStorage extends CapacitorStorage {
|
|||
}
|
||||
|
||||
function _exists(CapacitorChannel $channel): bool {
|
||||
$tableName = $this->mysql->get([
|
||||
$mysql = $this->mysql;
|
||||
$tableName = $mysql->get([
|
||||
"select table_name from information_schema.tables",
|
||||
"where" => [
|
||||
#"table_schema" => database_name #XXX
|
||||
"table_schema" => $mysql->getDbname(),
|
||||
"table_name" => $channel->getTableName(),
|
||||
],
|
||||
]);
|
||||
|
|
|
@ -71,13 +71,15 @@ class _query_base extends _base {
|
|||
} elseif (is_string($value)) {
|
||||
if (self::is_sqldate($value)) {
|
||||
# déjà dans le bon format
|
||||
} elseif (Date::isa_date($value)) {
|
||||
} elseif (Date::isa_date($value, true)) {
|
||||
$value = new Date($value);
|
||||
$value = $value->format('Y-m-d');
|
||||
} elseif (DateTime::isa_datetime($value)) {
|
||||
} elseif (DateTime::isa_datetime($value, true)) {
|
||||
$value = new DateTime($value);
|
||||
$value = $value->format('Y-m-d H:i:s');
|
||||
}
|
||||
} elseif (is_bool($value)) {
|
||||
$value = $value? 1: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,8 +159,8 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||
} else {
|
||||
# il faut déterminer le type de fichier CSV en lisant la première ligne
|
||||
$pos = IOException::ensure_valid(ftell($fd));
|
||||
$line = IOException::ensure_valid(fgets($fd));
|
||||
$line = strpbrk($line, ",;\t");
|
||||
$line = fgets($fd);
|
||||
if ($line !== false) $line = strpbrk($line, ",;\t");
|
||||
if ($line === false) {
|
||||
# aucun séparateur trouvé, prender la valeur par défaut
|
||||
$flavour = static::DEFAULT_CSV_FLAVOUR;
|
||||
|
@ -308,11 +308,22 @@ class Stream extends AbstractIterator implements IReader, IWriter {
|
|||
}
|
||||
}
|
||||
|
||||
protected function _teardown(): void {
|
||||
private function _rewindFd(): void {
|
||||
$md = stream_get_meta_data($this->fd);
|
||||
if ($md["seekable"]) $this->fseek(0);
|
||||
}
|
||||
|
||||
protected function _teardown(): void {
|
||||
$this->_rewindFd();
|
||||
}
|
||||
|
||||
function rewind(): void {
|
||||
# il faut toujours faire un rewind sur la resource, que l'itérateur aie été
|
||||
# initialisé ou non
|
||||
if ($this->_hasIteratorBeenSetup()) parent::rewind();
|
||||
else $this->_rewindFd();
|
||||
}
|
||||
|
||||
#############################################################################
|
||||
# Writer
|
||||
|
||||
|
|
|
@ -75,6 +75,11 @@ abstract class AbstractIterator implements Iterator, ICloseable {
|
|||
# Implémentation par défaut
|
||||
|
||||
private $setup = false;
|
||||
|
||||
protected function _hasIteratorBeenSetup(): bool {
|
||||
return $this->setup;
|
||||
}
|
||||
|
||||
private $valid = false;
|
||||
private $toredown = true;
|
||||
|
||||
|
|
|
@ -43,18 +43,18 @@ class DateTime extends \DateTime {
|
|||
preg_match(self::YMDHISZ_PATTERN, $datetime);
|
||||
}
|
||||
|
||||
static function isa_datetime($datetime): bool {
|
||||
static function isa_datetime($datetime, bool $frOnly=false): bool {
|
||||
if ($datetime instanceof DateTimeInterface) return true;
|
||||
if (!is_int($datetime) && !is_string($datetime)) return false;
|
||||
return preg_match(self::DMYHIS_PATTERN, $datetime) ||
|
||||
preg_match(self::YMDHISZ_PATTERN, $datetime);
|
||||
(!$frOnly && preg_match(self::YMDHISZ_PATTERN, $datetime));
|
||||
}
|
||||
|
||||
static function isa_date($datetime): bool {
|
||||
static function isa_date($datetime, bool $frOnly=false): bool {
|
||||
if ($datetime instanceof DateTimeInterface) return true;
|
||||
if (!is_int($datetime) && !is_string($datetime)) return false;
|
||||
return preg_match(self::DMY_PATTERN, $datetime) ||
|
||||
preg_match(self::YMD_PATTERN, $datetime);
|
||||
(!$frOnly && preg_match(self::YMD_PATTERN, $datetime));
|
||||
}
|
||||
|
||||
static function _YmdHMSZ_format(\DateTime $datetime): string {
|
||||
|
|
Loading…
Reference in New Issue