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

#48 Resolve getDatatableSize function return type issue #49

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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
18 changes: 9 additions & 9 deletions src/Traits/DBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ public function getFieldDataType(string $tableName, string $fieldName): array|bo
{
try {
$query = "SELECT `DATA_TYPE`, `CHARACTER_MAXIMUM_LENGTH`, `NUMERIC_PRECISION`, `NUMERIC_SCALE` FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`= '" . $this->getDatabaseName() . "' AND `TABLE_NAME`= '" . $tableName . "' AND `COLUMN_NAME` = '" . $fieldName . "' ";
WHERE `TABLE_SCHEMA`= '" . $this->getDatabaseName() . "' AND `TABLE_NAME`= '" . $tableName . "' AND `COLUMN_NAME` = '" . $fieldName . "' ";

$dataType = DB::select($query)[0];

if(in_array($dataType->DATA_TYPE, Constant::NUMERIC_DATATYPE)) {

if($dataType->DATA_TYPE === Constant::DATATYPE_DECIMAL) {
$size = "(". $dataType->NUMERIC_PRECISION .",". $dataType->NUMERIC_SCALE .")";
} else {
Expand Down Expand Up @@ -178,10 +178,10 @@ public function getDatabaseName()
public function getDatabaseSize()
{
try {
$query = 'SELECT table_schema as db_name, ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "size"
$query = 'SELECT table_schema as db_name, ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "size"
FROM information_schema.tables
where table_schema = "'. $this->getDatabaseName() .'" GROUP BY table_schema';
where table_schema = "'. $this->getDatabaseName() .'" GROUP BY table_schema';

$result = DB::select($query);

if ($result) {
Expand All @@ -190,7 +190,7 @@ public function getDatabaseSize()
} catch (Exception $exception) {
Log::error($exception->getMessage());
}
return Constant::NULL;
return Constant::DASH;

}

Expand All @@ -200,7 +200,7 @@ public function getDatabaseEngin()
$query = 'SELECT engine FROM information_schema.Tables where TABLE_SCHEMA = "'. $this->getDatabaseName() .'" Limit 1';

$result = DB::select($query);

if ($result) {
return $result[0]->ENGINE;
}
Expand All @@ -216,7 +216,7 @@ public function getCharacterSetName()
try {
$query = 'SELECT DEFAULT_CHARACTER_SET_NAME
FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = "'. $this->getDatabaseName() .'"';

$result = DB::select($query);

if ($result) {
Expand Down