Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix to Running SQL Query from File #223

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading