Skip to content

Commit

Permalink
Revert "[WIP] Dev: Issue with MSSQL and 0 or 0.1 or 0.001 (#1354)"
Browse files Browse the repository at this point in the history
This reverts commit 2eb78e6.

Dev: Import survey fails when debug = 2
  • Loading branch information
olleharstedt committed Jan 8, 2020
1 parent a375fc7 commit aa98340
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 47 deletions.
6 changes: 0 additions & 6 deletions application/controllers/admin/dataentry.php
Expand Up @@ -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"), ".");
}
Expand Down Expand Up @@ -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"), ".");
}
Expand Down
5 changes: 1 addition & 4 deletions application/helpers/admin/export/SurveyObj.php
Expand Up @@ -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"), ".");
}
Expand Down
6 changes: 1 addition & 5 deletions application/helpers/common_helper.php
Expand Up @@ -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];
Expand All @@ -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"), ".");
}
Expand Down
22 changes: 3 additions & 19 deletions application/helpers/expressions/em_core_helper.php
Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions application/helpers/qanda_helper.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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"), ".");
}
Expand Down
3 changes: 0 additions & 3 deletions application/models/SurveyDynamic.php
Expand Up @@ -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"), ".");
}
Expand Down

0 comments on commit aa98340

Please sign in to comment.