modifs.mineures sans commentaires
This commit is contained in:
parent
6530747067
commit
2e58cbd49f
|
@ -63,15 +63,21 @@ Application::run(new class extends Application {
|
||||||
if ($dbfile === null) self::die("Vous devez spécifier la base de données");
|
if ($dbfile === null) self::die("Vous devez spécifier la base de données");
|
||||||
if (!file_exists($dbfile)) self::die("$dbfile: fichier introuvable");
|
if (!file_exists($dbfile)) self::die("$dbfile: fichier introuvable");
|
||||||
$storage = new SqliteStorage($dbfile);
|
$storage = new SqliteStorage($dbfile);
|
||||||
|
$db = $storage->db();
|
||||||
|
|
||||||
|
$haveChannels = $storage->tableExists("_channels");
|
||||||
|
|
||||||
$name = $this->name;
|
$name = $this->name;
|
||||||
$channelClass = $this->channelClass;
|
$channelClass = $this->channelClass;
|
||||||
$tableName = $this->tableName;
|
$tableName = $this->tableName;
|
||||||
if ($name !== null) {
|
if ($name !== null) {
|
||||||
$row = $storage->db()->one([
|
$row = null;
|
||||||
"select from _channels",
|
if ($haveChannels) {
|
||||||
"where" => ["name" => $name],
|
$row = $db->one([
|
||||||
]);
|
"select from _channels",
|
||||||
|
"where" => ["name" => $name],
|
||||||
|
]);
|
||||||
|
}
|
||||||
if ($row === null) self::die("$name: nom de canal de données introuvable");
|
if ($row === null) self::die("$name: nom de canal de données introuvable");
|
||||||
if ($row["class"] !== "class@anonymous") $channelClass = $row["class"];
|
if ($row["class"] !== "class@anonymous") $channelClass = $row["class"];
|
||||||
else $tableName = $row["table_name"];
|
else $tableName = $row["table_name"];
|
||||||
|
@ -87,18 +93,30 @@ Application::run(new class extends Application {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
self::die("Vous devez spécifier le canal de données");
|
$found = false;
|
||||||
|
if ($haveChannels) {
|
||||||
|
$rows = $db->all([
|
||||||
|
"select from _channels",
|
||||||
|
]);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
msg::print($row["name"]);
|
||||||
|
$found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$found) self::die("Vous devez spécifier le canal de données");
|
||||||
}
|
}
|
||||||
$capacitor = new Capacitor($storage, $channel);
|
$capacitor = new Capacitor($storage, $channel);
|
||||||
|
|
||||||
switch ($this->action) {
|
switch ($this->action) {
|
||||||
case self::ACTION_QUERY:
|
case self::ACTION_QUERY:
|
||||||
$args = $this->args;
|
$args = $this->args;
|
||||||
|
var_export($args); #XXX
|
||||||
if (!$args) {
|
if (!$args) {
|
||||||
# lister les id
|
# lister les id
|
||||||
$out = new Stream(STDOUT);
|
$out = new Stream(STDOUT);
|
||||||
$primaryKeys = $storage->getPrimaryKeys($channel);
|
$primaryKeys = $storage->getPrimaryKeys($channel);
|
||||||
$rows = $storage->db()->all([
|
var_export($primaryKeys); #XXX
|
||||||
|
$rows = $db->all([
|
||||||
"select",
|
"select",
|
||||||
"cols" => $primaryKeys,
|
"cols" => $primaryKeys,
|
||||||
"from" => $channel->getTableName(),
|
"from" => $channel->getTableName(),
|
||||||
|
|
|
@ -11,9 +11,9 @@ if ($argc <= 1) die("invalid arguments");
|
||||||
app::init(NULIB_APP_app_params);
|
app::init(NULIB_APP_app_params);
|
||||||
|
|
||||||
$app = $argv[1];
|
$app = $argv[1];
|
||||||
|
array_splice($argv, 0, 1); $argc--;
|
||||||
if (class_exists($app)) {
|
if (class_exists($app)) {
|
||||||
# la configuration est celle actuellement chargée
|
# la configuration est celle actuellement chargée
|
||||||
array_splice($argv, 1, 1); $argc--;
|
|
||||||
$app::run();
|
$app::run();
|
||||||
} elseif (is_executable($app)) {
|
} elseif (is_executable($app)) {
|
||||||
# la configuration est passée par une variable d'environnement
|
# la configuration est passée par une variable d'environnement
|
||||||
|
@ -21,7 +21,6 @@ if (class_exists($app)) {
|
||||||
pcntl_exec($app, array_slice($argv, 1));
|
pcntl_exec($app, array_slice($argv, 1));
|
||||||
} else {
|
} else {
|
||||||
# la configuration est celle actuellement chargée
|
# la configuration est celle actuellement chargée
|
||||||
array_splice($argv, 0, 1); $argc--;
|
|
||||||
$name = preg_replace('/\.php$/', "", path::basename($app));
|
$name = preg_replace('/\.php$/', "", path::basename($app));
|
||||||
app::init([
|
app::init([
|
||||||
"name" => $name,
|
"name" => $name,
|
||||||
|
|
|
@ -28,13 +28,25 @@ class SqliteStorage extends CapacitorStorage {
|
||||||
return self::format_sql($channel, $query->getSql());
|
return self::format_sql($channel, $query->getSql());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _afterCreate(CapacitorChannel $channel): void {
|
function tableExists(string $tableName): bool {
|
||||||
$db = $this->db;
|
|
||||||
$name = $this->db->get([
|
$name = $this->db->get([
|
||||||
"select name from sqlite_schema",
|
"select name from sqlite_schema",
|
||||||
"where" => ["name" => "_channels"],
|
"where" => ["name" => $tableName],
|
||||||
]);
|
]);
|
||||||
if ($name === null) {
|
return $name !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function channelExists(string $name): bool {
|
||||||
|
$name = $this->db->get([
|
||||||
|
"select name from _channels",
|
||||||
|
"where" => ["name" => $name],
|
||||||
|
]);
|
||||||
|
return $name !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function _afterCreate(CapacitorChannel $channel): void {
|
||||||
|
$db = $this->db;
|
||||||
|
if (!$this->tableExists("_channels")) {
|
||||||
# ne pas créer si la table existe déjà, pour éviter d'avoir besoin d'un
|
# ne pas créer si la table existe déjà, pour éviter d'avoir besoin d'un
|
||||||
# verrou en écriture
|
# verrou en écriture
|
||||||
$db->exec([
|
$db->exec([
|
||||||
|
@ -47,11 +59,7 @@ class SqliteStorage extends CapacitorStorage {
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$name = $this->db->get([
|
if (!$this->channelExists($channel->getName())) {
|
||||||
"select name from _channels",
|
|
||||||
"where" => ["name" => $channel->getName()],
|
|
||||||
]);
|
|
||||||
if ($name === null) {
|
|
||||||
# ne pas insérer si la ligne existe déjà, pour éviter d'avoir besoin d'un
|
# ne pas insérer si la ligne existe déjà, pour éviter d'avoir besoin d'un
|
||||||
# verrou en écriture
|
# verrou en écriture
|
||||||
$db->exec([
|
$db->exec([
|
||||||
|
@ -78,13 +86,7 @@ class SqliteStorage extends CapacitorStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _exists(CapacitorChannel $channel): bool {
|
function _exists(CapacitorChannel $channel): bool {
|
||||||
$tableName = $this->db->get([
|
return $this->tableExists($channel->getTableName());
|
||||||
"select name from sqlite_schema",
|
|
||||||
"where" => [
|
|
||||||
"name" => $channel->getTableName(),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
return $tableName !== null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function close(): void {
|
function close(): void {
|
||||||
|
|
Loading…
Reference in New Issue