Skip to content

Commit

Permalink
Fixed issue #15684: When reloading decimal value with 0 with MSSQL : …
Browse files Browse the repository at this point in the history
…0 disappear (#1360)

Fixed issue #15685: Issue when exporting decimal value in MSSQL
  • Loading branch information
Shnoulle authored and olleharstedt committed Jan 9, 2020
1 parent d800b43 commit a4e8900
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 6 additions & 0 deletions application/controllers/admin/dataentry.php
Expand Up @@ -598,6 +598,9 @@ public function editdata($subaction, $id, $surveyid)
$aDataentryoutput .= $fname['subquestion'].' ';
/* Fix DB DECIMAL type */
$value = $idrow[$fname['fieldname']];
if($value[0] === ".") {
$value = "0".$value;
}
if (strpos($value, ".")) {
$value = rtrim(rtrim($value, "0"), ".");
}
Expand Down Expand Up @@ -974,6 +977,9 @@ public function editdata($subaction, $id, $surveyid)
case "N": //NUMERICAL TEXT
/* Fix DB DECIMAL type */
$value = $idrow[$fname['fieldname']];
if($value[0] === ".") {
$value = "0".$value;
}
if (strpos($value, ".")) {
$value = rtrim(rtrim($value, "0"), ".");
}
Expand Down
6 changes: 5 additions & 1 deletion application/helpers/admin/export/SurveyObj.php
Expand Up @@ -100,7 +100,11 @@ public function getFullAnswer($fieldName, $answerCode, Translator $translator, $
case 'K':
case 'N':
$fullAnswer = $answerCode;
if (trim($fullAnswer) != '') {
if (trim($fullAnswer) !== '') {
// SQL DECIMAL
if($fullAnswer[0] === ".") {
$fullAnswer = "0".$fullAnswer;
}
if (strpos($fullAnswer, ".") !== false) {
$fullAnswer = rtrim(rtrim($fullAnswer, "0"), ".");
}
Expand Down
7 changes: 6 additions & 1 deletion application/helpers/common_helper.php
Expand Up @@ -1096,7 +1096,7 @@ function getExtendedAnswer($iSurveyID, $sFieldCode, $sValue, $sLanguage)
//Fieldcode used to determine question, $sValue used to match against answer code
//Returns NULL if question type does not suit
if (strpos($sFieldCode, "{$iSurveyID}X") === 0) {
//Only check if it looks like a real fieldcode
//Only check if it looks like a real fieldcode
$fieldmap = createFieldMap($survey, 'short', false, false, $sLanguage);
if (isset($fieldmap[$sFieldCode])) {
$fields = $fieldmap[$sFieldCode];
Expand All @@ -1121,6 +1121,11 @@ function getExtendedAnswer($iSurveyID, $sFieldCode, $sValue, $sLanguage)
break;
case 'K':
case 'N':
// Fix the value : Value is stored as decimal in SQL
if($sValue[0] === ".") {
// issue #15685 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000
$sValue = "0".$sValue;
}
if (trim($sValue) != '') {
if (strpos($sValue, ".") !== false) {
$sValue = rtrim(rtrim($sValue, "0"), ".");
Expand Down
17 changes: 14 additions & 3 deletions application/helpers/qanda_helper.php
Expand Up @@ -2739,10 +2739,17 @@ function do_multiplenumeric($ia)
$sValue = null;
}

$sUnformatedValue = $sValue ? $sValue : '';

// Fix the display value : Value is stored as decimal in SQL. Issue when reloading survey
if($sValue[0] == ".") {
// issue #15684 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000
$sValue = "0" . $sValue;
}
if (strpos($sValue, ".")) {
$sValue = rtrim(rtrim($sValue, "0"), ".");
}
// End of DECIMAL fix : get the nulber value
$sUnformatedValue = $sValue ? $sValue : '';
if (strpos($sValue, ".")) {
$sValue = str_replace('.', $sSeparator, $sValue);
}

Expand Down Expand Up @@ -2928,7 +2935,11 @@ function do_numerical($ia)
$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];

// Fix the display value : Value is stored as decimal in SQL then return dot and 0 after dot. Seems only for numerical question type
// Fix the display value : Value is stored as decimal in SQL
if($fValue[0] == ".") {
// issue #15684 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000
$fValue = "0" . $fValue;
}
if (strpos($fValue, ".")) {
$fValue = rtrim(rtrim($fValue, "0"), ".");
}
Expand Down

0 comments on commit a4e8900

Please sign in to comment.