From aa98340c9ffa9b415cc8d820e5322bfe6373fec4 Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Wed, 8 Jan 2020 16:22:17 +0100 Subject: [PATCH] Revert "[WIP] Dev: Issue with MSSQL and 0 or 0.1 or 0.001 (#1354)" This reverts commit 2eb78e6cf5bcf8ea6409f507ca2d4a559f0e7710. Dev: Import survey fails when debug = 2 --- application/controllers/admin/dataentry.php | 6 ----- .../helpers/admin/export/SurveyObj.php | 5 +---- application/helpers/common_helper.php | 6 +---- .../helpers/expressions/em_core_helper.php | 22 +++---------------- application/helpers/qanda_helper.php | 12 ++-------- application/models/SurveyDynamic.php | 3 --- 6 files changed, 7 insertions(+), 47 deletions(-) diff --git a/application/controllers/admin/dataentry.php b/application/controllers/admin/dataentry.php index 62cc92901cc..02eadac435a 100644 --- a/application/controllers/admin/dataentry.php +++ b/application/controllers/admin/dataentry.php @@ -594,9 +594,6 @@ 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"), "."); } @@ -956,9 +953,6 @@ public function editdata($subaction, $id, $surveyid) case Question::QT_N_NUMERICAL: //NUMERICAL TEXT /* Fix DB DECIMAL type */ $value = $idrow[$fname['fieldname']]; - if($value[0] === ".") { - $value = "0".$value; - } if (strpos($value, ".")) { $value = rtrim(rtrim($value, "0"), "."); } diff --git a/application/helpers/admin/export/SurveyObj.php b/application/helpers/admin/export/SurveyObj.php index c6325b32d83..eb977ad1283 100644 --- a/application/helpers/admin/export/SurveyObj.php +++ b/application/helpers/admin/export/SurveyObj.php @@ -100,10 +100,7 @@ public function getFullAnswer($fieldName, $answerCode, Translator $translator, $ case Question::QT_K_MULTIPLE_NUMERICAL_QUESTION: case Question::QT_N_NUMERICAL: $fullAnswer = $answerCode; - if (trim($fullAnswer) !== '') { - if($fullAnswer[0] === ".") { - $fullAnswer = "0".$fullAnswer; - } + if (trim($fullAnswer) != '') { if (strpos($fullAnswer, ".") !== false) { $fullAnswer = rtrim(rtrim($fullAnswer, "0"), "."); } diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 9be2b335fec..75daac4e94b 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -929,7 +929,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]; @@ -956,10 +956,6 @@ function getExtendedAnswer($iSurveyID, $sFieldCode, $sValue, $sLanguage) case Question::QT_N_NUMERICAL: // Fix the value : Value is stored as decimal in SQL if (trim($sValue) != '') { - // issue #15685 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000 - if($sValue[0] === ".") { - $sValue = "0".$sValue; - } if (strpos($sValue, ".") !== false) { $sValue = rtrim(rtrim($sValue, "0"), "."); } diff --git a/application/helpers/expressions/em_core_helper.php b/application/helpers/expressions/em_core_helper.php index da6a95af52f..3f68780445f 100644 --- a/application/helpers/expressions/em_core_helper.php +++ b/application/helpers/expressions/em_core_helper.php @@ -352,25 +352,9 @@ private function getMismatchInformation(array $arg1, array $arg2) { /* When value come from DB : it's set to 1.000000 (DECIMAL) : must be fixed see #11163. Response::model() must fix this . or not ? */ /* Don't return true always : user can entre non numeric value in a numeric value : we must compare as string then */ - $arg1[0] = $arg1[0]; - if($arg1[2] == "NUMBER" && $arg1[0]!== "") { - if($arg1[0] === ".") { - $arg1 = "0".$arg1; - } - if (strpos($arg1, ".") !== false) { - $arg1 = rtrim(rtrim($arg1, "0"), "."); - } - } - $arg2[0] = $arg2[0]; - if($arg2[2] == "NUMBER" && $arg2[0]!== "") { - if($arg2[0] === ".") { - $arg2 = "0".$arg2; - } - if (strpos($arg2, ".") !== false) { - $arg2 = rtrim(rtrim($arg2, "0"), "."); - } - } - + $arg1[0] = ($arg1[2] == "NUMBER" && strpos($arg1[0], ".")) ? rtrim(rtrim($arg1[0], "0"), ".") : $arg1[0]; + $arg2[0] = ($arg2[2] == "NUMBER" && strpos($arg2[0], ".")) ? rtrim(rtrim($arg2[0], "0"), ".") : $arg2[0]; + $bNumericArg1 = $arg1[0]!== "" && (!$arg1[0] || strval(floatval($arg1[0])) == strval($arg1[0])); $bNumericArg2 = $arg2[0]!== "" && (!$arg2[0] || strval(floatval($arg2[0])) == strval($arg2[0])); $bStringArg1 = !$arg1[0] || !$bNumericArg1; diff --git a/application/helpers/qanda_helper.php b/application/helpers/qanda_helper.php index 6822154b16e..1bdd3d0130c 100644 --- a/application/helpers/qanda_helper.php +++ b/application/helpers/qanda_helper.php @@ -2230,12 +2230,8 @@ function do_multiplenumeric($ia) $sValue = null; } - // Fix the display value : Value is stored as decimal in SQL - if($sValue[0] == ".") { - // issue #15684 mssql SAVE 0.01 AS .0100000000, set it at 0.0100000000 - $sValue = "0" . $sValue; - } $sUnformatedValue = $sValue ? $sValue : ''; + if (strpos($sValue, ".")) { $sValue = rtrim(rtrim($sValue, "0"), "."); $sValue = str_replace('.', $sSeparator, $sValue); @@ -2428,11 +2424,7 @@ function do_numerical($ia) $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']); $sSeparator = $sSeparator['separator']; - // 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; - } + // Fix the display value : Value is stored as decimal in SQL then return dot and 0 after dot. Seems only for numerical question type if (strpos($fValue, ".")) { $fValue = rtrim(rtrim($fValue, "0"), "."); } diff --git a/application/models/SurveyDynamic.php b/application/models/SurveyDynamic.php index 60373def8eb..9eb96c20dbf 100644 --- a/application/models/SurveyDynamic.php +++ b/application/models/SurveyDynamic.php @@ -967,9 +967,6 @@ public function getQuestionArray($oQuestion, $oResponses, $bHonorConditions, $su } if ($oQuestion->type=='N' || ($oQuestion->parent_qid != 0 && $oQuestion->parents['type'] === "K")) { - if($aQuestionAttributes['answervalue'] !=="" && $aQuestionAttributes['answervalue'][0] === ".") { // issue #15685 mssql - $aQuestionAttributes['answervalue'] = "0".$aQuestionAttributes['answervalue']; - } if (strpos($aQuestionAttributes['answervalue'], ".") !== false) { // Remove last 0 and last . ALWAYS (see \SurveyObj\getShortAnswer) $aQuestionAttributes['answervalue'] = rtrim(rtrim($aQuestionAttributes['answervalue'], "0"), "."); }