Skip to content

Commit

Permalink
Fix to a Bug for Bool Type in MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
usernane committed Jul 25, 2023
1 parent 264519d commit 2e5fff3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions webfiori/database/mssql/MSSQLColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function getDefault() {
}
} else if ($dt == 'int' || $dt == 'bigint') {
$retVal = intval($defaultVal);
} else if ($dt == 'boolean') {
} else if ($dt == 'boolean' || $dt == 'bool') {
return $defaultVal === 1 || $defaultVal === true;
} else if ($dt == 'float' || $dt == 'decimal' || $dt == 'money') {
$retVal = floatval($defaultVal);
Expand Down Expand Up @@ -337,7 +337,7 @@ public function getName() : string {
public function getPHPType() : string {
$colType = $this->getDatatype();

if ($colType == 'boolean') {
if ($colType == 'boolean' || $colType == 'bool') {
$isNullStr = '';
} else {
$isNullStr = $this->isNull() ? '|null' : '';
Expand Down Expand Up @@ -408,6 +408,7 @@ public function setAutoUpdate(bool $bool) {
* column type is not supported.
*/
public function setDatatype(string $type) {

parent::setDatatype($type);

if (!($this->getDatatype() == 'int' || $this->getDatatype() == 'bigint')) {
Expand Down Expand Up @@ -500,7 +501,7 @@ private function cleanValueHelper($val) {
return null;
} else if ($colDatatype == 'int' || $colDatatype == 'bigint') {
$cleanedVal = intval($val);
} else if ($colDatatype == 'boolean') {
} else if ($colDatatype == 'boolean' || $colDatatype == 'bool') {
if ($val === true) {
$cleanedVal = 1;
} else {
Expand Down Expand Up @@ -528,7 +529,7 @@ private function cleanValueHelper($val) {
$cleanedVal = filter_var(addslashes($val));
} else if ($valType == 'double') {
$cleanedVal = "'".floatval($val)."'";
} else if ($valType == 'boolean') {
} else if ($valType == 'boolean' || $colDatatype == 'bool') {
if ($val === true) {
$cleanedVal = 1;
} else {
Expand Down Expand Up @@ -572,7 +573,7 @@ private function defaultPartString() {
$colDefault = $this->getDefault();

if ($colDefault !== null) {
if ($colDataType == 'boolean') {
if ($colDataType == 'boolean' || $colDataType == 'bool') {
if ($this->getDefault() === true) {
return 'default 1 ';
} else {
Expand Down Expand Up @@ -602,7 +603,7 @@ private function firstColPartString() {
|| $colDataType == 'char' || $colDataType == 'nchar'
|| $colDataType == 'binary' || $colDataType == 'varbinary') {
$retVal .= $colDataTypeSq.'('.$this->getSize().') ';
} else if ($colDataType == 'boolean') {
} else if ($colDataType == 'boolean' || $colDataType == 'bool') {
$retVal .= '[bit] ';
} else if ($colDataType == 'decimal') {
if ($this->getSize() != 0) {
Expand All @@ -626,7 +627,7 @@ private function firstColPartString() {
private function nullPartString() {
$colDataType = $this->getDatatype();

if (!$this->isNull() || $colDataType == 'boolean') {
if (!$this->isNull() || $colDataType == 'boolean' || $colDataType == 'bool') {
return 'not null ';
} else {
return 'null ';
Expand Down

0 comments on commit 2e5fff3

Please sign in to comment.