View Issue Details

IDProjectCategoryView StatusLast Update
14649Bug reports[All Projects] Survey designpublic2019-03-15 22:31
ReporterlemeurtAssigned To 
PrioritynoneSeveritycrash 
Status newResolutionopen 
Product Version3.15.x 
Target VersionFixed in Version 
Summary14649: CDbException when a "default answer" option is not compatible with a question type
Description

Changing the question type on a question with an incompatible "default answer" option may lead to a CDbException when taking the survey.

Proposed patch: When updating a question type, either reset the default answers or selectively reset the default answers if the new question type is not compliant with the previous one.

Steps To Reproduce
  • Create a question of type text
  • Add a long default answer as text
  • Change the question type to List Dropdown
  • add answers (the code is 5 Chars max)
  • activate the survey (the answer table prepares a varying(5) field type
  • Try to answer the survey ==> Error 500 Internal Server Error
    CDbCommand n'a pas pu exécuter la commande SQL: SQLSTATE[22001]: String data, right truncated: 7 ERROR: value too long for type character varying(5)
Additional Information

Detailed error with Debugging:

CDbCommand n'a pas pu exécuter la commande SQL: SQLSTATE[22001]: String data, right truncated: 7 ERROR: value too long for type character varying(5)

CDbException

CDbCommand n'a pas pu exécuter la commande SQL: SQLSTATE[22001]: String data, right truncated: 7 ERROR: value too long for type character varying(5). The SQL statement executed was: UPDATE lime_survey_114132 SET "lastpage"=0, "114132X202X1951"='1A CentraleSupélec 2A cursus centralien 2A cursus Supélec', "114132X202X1956"='Oui Non Ne sait pas encore' WHERE ID=601 (/var/www/html/limesurvey/framework/db/CDbCommand.php:543)

#0 /var/www/html/limesurvey/framework/db/CDbCommand.php(377): CDbCommand->queryInternal('', 0, Array)
#1 /var/www/html/limesurvey/application/helpers/expressions/em_manager_helper.php(5565): CDbCommand->query()
#2 /var/www/html/limesurvey/application/helpers/expressions/em_manager_helper.php(5290): LimeExpressionManager->_UpdateValuesInDatabase()
#3 /var/www/html/limesurvey/application/helpers/SurveyRuntimeHelper.php(838): LimeExpressionManager::NavigateForwards()
#4 /var/www/html/limesurvey/application/helpers/SurveyRuntimeHelper.php(537): SurveyRuntimeHelper->setMoveResult()
#5 /var/www/html/limesurvey/application/helpers/SurveyRuntimeHelper.php(104): SurveyRuntimeHelper->initMove()
#6 /var/www/html/limesurvey/application/controllers/survey/index.php(591): SurveyRuntimeHelper->run('114132', Array)
#7 /var/www/html/limesurvey/application/controllers/survey/index.php(24): index->action()
#8 /var/www/html/limesurvey/framework/web/actions/CAction.php(76): index->run()
#9 /var/www/html/limesurvey/framework/web/CController.php(308): CAction->runWithParams(Array)
#10 /var/www/html/limesurvey/framework/web/CController.php(286): CController->runAction(Object(index))
#11 /var/www/html/limesurvey/framework/web/CController.php(265): CController->runActionWithFilters(Object(index), Array)
#12 /var/www/html/limesurvey/framework/web/CWebApplication.php(282): CController->run('index')
#13 /var/www/html/limesurvey/framework/web/CWebApplication.php(141): CWebApplication->runController('survey/index/si...')
#14 /var/www/html/limesurvey/framework/base/CApplication.php(185): CWebApplication->processRequest()
#15 /var/www/html/limesurvey/index.php(194): CApplication->run()
#16 {main}

TagsNo tags attached.
Complete LimeSurvey version number (& build)Version 3.15.8+190130
I will donate to the project if issue is resolvedNo
Browser
Database & DB-VersionPostgres
Server OS (if known)
Webserver software & version (if known)
PHP VersionN/A

Relationships

related to 10827 closedDenisChenu Whole answers must be filtered before try to save in DB 

Activities

DenisChenu

DenisChenu

2019-03-14 12:20

developer   ~50981

2 patch must be done

  1. must fix the CDB value even with invalid value
  2. Auto fif default value in GUI

PS : a cool way to have a default value for single choice. When 1 is fixed : we can add a input:text for singlme choice too (like with Yes/No question type).

DenisChenu

DenisChenu

2019-03-14 12:24

developer   ~50982

Related to https://bugs.limesurvey.org/view.php?id=10827 because it does the same things for user entered value (filter $_POST before set).
For default value : error can be shown, but maybe only for user with edit content rights on survey ?

lemeurt

lemeurt

2019-03-15 11:34

reporter   ~51002

Hi Denis,
10827 is private, I can't access it.

DenisChenu

DenisChenu

2019-03-15 11:58

developer   ~51003

I set 10827 public since it was private due to security.
You can find the fix here : https://github.com/LimeSurvey/LimeSurvey/commit/6c7c30d13a9cb45aee498cf4d3eb0a5c8b06ed19

The big part is https://github.com/LimeSurvey/LimeSurvey/commit/6c7c30d13a9cb45aee498cf4d3eb0a5c8b06ed19#diff-796aba4d06254b9caea9d461e4ea80c9R10238
Maybe adding an optionnal settings private static function checkValidityAnswer($type,$value,$sgq,$qinfo,$setInvalidAnswerString = true)
And use it to filter default value ?

lemeurt

lemeurt

2019-03-15 22:31

reporter   ~51021

Just to let write down that this is only a major bug for Postgres users as in Mysql when trying to insert too much data in a short database column, the data is automatically truncated without throwing Exceptions.

Issue History

Date Modified Username Field Change
2019-03-14 11:42 lemeurt New Issue
2019-03-14 12:20 DenisChenu Note Added: 50981
2019-03-14 12:23 DenisChenu Relationship added related to 10827
2019-03-14 12:24 DenisChenu Note Added: 50982
2019-03-15 11:34 lemeurt Note Added: 51002
2019-03-15 11:58 DenisChenu Note Added: 51003
2019-03-15 22:31 lemeurt Note Added: 51021