diff --git a/examples/clitest/c1.php b/examples/clitest/c1.php index ef03485..802bb2a 100644 --- a/examples/clitest/c1.php +++ b/examples/clitest/c1.php @@ -1,17 +1,3 @@ - -{ - "interactive": "", - "databasetype": "mysql", - "server": "127.0.0.1", - "user": "root", - "password": "abc.123", - "database": "sakila", - "input": "", - "output": "", - "namespace": "", - "tablexclass": [], - "conversion": [], - "extracolumn": [], - "removecolumn": [], - "columnsTable": [] -} \ No newline at end of file +setInput(false) ->add(); $this->cli->evalParam('export'); + $this->inJectInitParam(); + $this->cli->createParam('databasetype', 'dt', 'longflag') ->setRelated(['common', 'export', 'generate']) ->setRequired(false) @@ -345,6 +347,7 @@ public function cliEngine(): void $this->inJectInitParam2($first->value, $interactive); break; } + $ok=false; switch ($first->value) { case 'definition': case 'export': @@ -378,18 +381,20 @@ public function cliEngine(): void $this->injectLoadFile($first->value, $interactive); break; } - if ($first->value) { + if (!$ok) {// $first->value) { + var_dump('load'); $database = $this->cli->evalParam('databasetype', $interactive, true); $server = $this->cli->evalParam('server', $interactive, true); $user = $this->cli->evalParam('user', $interactive, true); $pwd = $this->cli->evalParam('password', $interactive, true); $db = $this->cli->evalParam('database', $interactive, true); + var_dump('two'); } else { - $database = ''; - $server = ''; - $user = ''; - $pwd = ''; - $db = ''; + $database = $this->cli->getValue('databasetype'); + $server = $this->cli->getValue('server'); + $user = $this->cli->getValue('user'); + $pwd = $this->cli->getValue('password'); + $db = $this->cli->getValue('database'); } switch ($first->value) { case 'definition': @@ -515,20 +520,29 @@ protected function showHelpExport(): void , null, 'export', 25); } - protected function runCliConnection(): ?PdoOne + protected function runCliConnection($force=false): ?PdoOne { - if (!$this->cli->getValue('databasetype')) { + if (!$this->cli->getValue('databasetype') && $force===false) { return null; } + if($force) { + $this->cli->evalParam('databasetype',true); + $this->cli->evalParam('server',true); + $this->cli->evalParam('user',true); + $this->cli->evalParam('password',true); + $this->cli->evalParam('database',true); + } $result = null; while (true) { try { $pdo = $this->createPdoInstance(); + if($pdo===null) { + throw new RuntimeException('trying'); + } $this->cli->showCheck('OK', 'green', 'Connected to the database ' . $this->cli->getValue('database') . ''); $result = $pdo; break; } catch (Exception $ex) { - $this->cli->showCheck('ERROR', 'red', 'Unable to connect to the database: ' . $ex->getMessage()); } $rt = $this->cli->createParam('retry') ->setDescription('', 'Do you want to retry?') @@ -730,15 +744,21 @@ protected function databaseDetail(): void } // end while tablecommand } // end while table } - public function createPdoInstance(): PdoOne { - $pdo = new PdoOne( - $this->cli->getValue('databasetype'), - $this->cli->getValue('server'), - $this->cli->getValue('user'), - $this->cli->getValue('password'), - $this->cli->getValue('database')); - $pdo->logLevel = 3; - $pdo->connect(); + public function createPdoInstance(): ?PdoOne { + try { + $pdo = new PdoOne( + $this->cli->getValue('databasetype'), + $this->cli->getValue('server'), + $this->cli->getValue('user'), + $this->cli->getValue('password'), + $this->cli->getValue('database')); + $pdo->logLevel = 1; + $pdo->connect(); + } catch(Exception $ex) { + $this->cli->showCheck('ERROR','red',['Unable to connect to database',$pdo->lastError(),$pdo->errorText]); + return null; + } + $pdo->logLevel = 2; return $pdo; } @@ -913,6 +933,7 @@ protected function runCliGenerationParams(): void , [':