Skip to content

Commit

Permalink
Merge pull request #223 from WebFiori/dev
Browse files Browse the repository at this point in the history
fix: Fix to Running SQL Query from File
  • Loading branch information
usernane authored May 13, 2024
2 parents 7841fd2 + 905c3c7 commit 1e4e6c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions webfiori/framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private function initFrameworkVersionInfo() {
*
* @since 2.1
*/
define('WF_VERSION', '3.0.0-Beta.6');
define('WF_VERSION', '3.0.0-Beta.7');
/**
* A constant that tells the type of framework version.
*
Expand All @@ -558,7 +558,7 @@ private function initFrameworkVersionInfo() {
*
* @since 2.1
*/
define('WF_RELEASE_DATE', '2024-05-12');
define('WF_RELEASE_DATE', '2024-05-13');
}

/**
Expand Down
29 changes: 22 additions & 7 deletions webfiori/framework/cli/commands/RunSQLQueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ private function connectionBased($dbConnections) : int {

if ($file !== null) {
$fileObj = new File(ROOT_PATH.DS.$file);


if (!$fileObj->isExist()) {
$fileObj = new File($file);
}

if ($fileObj->isExist()) {
$fileObj->read();
$mime = $fileObj->getMIME();
Expand All @@ -135,7 +139,12 @@ private function connectionBased($dbConnections) : int {
return -1;
}
} else {
$this->error('No such file: '.$file);
$path = $fileObj->getAbsolutePath();

if (strlen($path) == 0) {
$path = $file;
}
$this->error('No such file: '.$path);

return -1;
}
Expand Down Expand Up @@ -201,24 +210,30 @@ private function queryFromFile($schema) {

while (!File::isFileExist($filePath)) {
$filePath = $this->getInput('File path:');

$modified = ROOT_PATH.DS.$filePath;

if (File::isFileExist($modified)) {
$filePath = $modified;
}

if (File::isFileExist($filePath)) {
$file = new File($filePath);
$file->read();

if ($file->getMIME() == 'application/sql') {
$mime = $file->getMIME();

if ($mime == 'application/sql' || $mime == 'application/x-sql') {
break;
} else {
$this->error('Provided file is not SQL file!');
}
} else {
$this->error('No such file!');
$this->error('No such file: '.$filePath);
}
}

return $this->runFileQuery($schema, $file);
}

private function queryOnSchema(DB $schema) {
if ($this->isArgProvided('--create')) {
$schema->createTables();
Expand Down

0 comments on commit 1e4e6c2

Please sign in to comment.