View Issue Details

This bug affects 1 person(s).
 4
IDProjectCategoryView StatusLast Update
09177Bug reportsSurvey takingpublic2014-09-08 21:21
ReporterIbistide Assigned ToDenisChenu  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version2.05+ 
Target Version2.05+Fixed in Version2.05+ 
Summary09177: Surveys with quota causing error in MSSQL
Description

We have an issue where quizzes that contain a Yes/No question are throwing an MSSQL error.

The first page of our quiz is a Yes/No question. When it is submitted, it posts
to /index.php?r=survey/index the following Form Data:

YII_CSRF_TOKEN:5ddf3b8543847c1e09a2c4f7e134bace4f36c136
fieldnames:624695X14X235
624695X14X235:Y
java624695X14X235:Y
lastgroup:624695X14
relevance235:1
relevanceG0:1
movenext:movenext
thisstep:1
sid:624695
start_time:1408475858
LEMpostKey:1041361029

when the POST occurs, the following query is run on MSSQL server:

declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 nvarchar(1)',N'SELECT COUNT(*) FROM [dbo].[survey_624695] [t] WHERE (submitdate IS NOT NULL) AND (624695X14X235 = @P1)',N'N'
select @p1

Which causes this error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'X14X235'.

Note: this error does not occur in Version 2.05+ Build 140502. It only started happening after we upgraded to 140811. It occurs in both existing surveys created before version 140811, and new surveys created in 140811.

Steps To Reproduce

(The attached test survey was created on a fresh install of Limesurvey Version 2.05+ Build 140811.)

  1. Import survey file (attached).
  2. From the Administrator menu, select the survey.
  3. Choose "Test this survey" to run the survey.
  4. Submit your answer to the first Y/N question.
  5. MSSQL error occurs.
Additional Information

The column names in the T-SQL statements that Limesurvey is generating are not wrapped in []. My guess is that this is causing MSSQL server some confusion; the "AND 624695X14X235 = @P1" portion of the statement may be ambiguous. (It may be trying to perform a comparison of "624695X14X235" itself as a value instead of performing the evaluation on the values in the 624695X14X235 column?)

It appears that wrapping [] around the column names solves this issue.

Test:

Isolating the Select statement and running it by itself in SSMS (SQL Server Management Studio) and replaceing @p1 with the 'Y' value supplied from the form, this statement causes an error:

SELECT COUNT(*) FROM [dbo].[survey_624695] [t] WHERE (submitdate IS NOT NULL) AND (624695X14X235 = 'Y')

Result: Error: Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'X14X235'.

After wrapping 624695X14X235 in brackets, the statement runs successfully:

SELECT COUNT(*) FROM [dbo].[survey_624695] [t] WHERE (submitdate IS NOT NULL) AND ([624695X14X235] = 'Y')

Result: Returns a correct count value.

(Note: the column 624695X14X235 in the table [dbo].[survey_624695] in the Limesurvey database is a varchar(1) field.)

TagsNo tags attached.
Attached Files
Bug heat4
Complete LimeSurvey version number (& build)140811
I will donate to the project if issue is resolvedNo
BrowserGoogle Chrome 36.0.1985.143
Database type & versionMSSQL Server 2012 SP1 Enterprise Edition, Database: Compatability Level 2012, Collation SQL_Latin1_General_CP1_CI_AS
Server OS (if known)Windows 2008 R2 Enterprise
Webserver software & version (if known)IIS 7.5
PHP VersionPHP 5.4.26.0

Users monitoring this issue

There are no users monitoring this issue.

Activities

DenisChenu

DenisChenu

2014-08-20 17:38

developer   ~30433

Fix committed to master branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=14382

DenisChenu

DenisChenu

2014-08-20 17:40

developer   ~30434

Last edited: 2014-08-20 17:40

@Ibistide can you apply the same patch than https://github.com/LimeSurvey/LimeSurvey/commit/c85494d76557845166a7dbffaa760ceaffb38081 and test again ?
Cause i don't have mssql to validate the bugfix :)

Ibistide

Ibistide

2014-08-20 21:16

reporter   ~30435

@DenisChenu - Thanks for the quick turnaround!

I edited those changes directly into application/helpers/common_helper.php on our 140811 version.

Our Limesurvey admin tested, and says that this change has solved the issue. I confirmed that the T-SQL statement (the one that was previously throwing an error) now has the column names wrapped in [] and is working correctly.

Thanks again!

DenisChenu

DenisChenu

2014-08-21 11:29

developer   ~30439

Thanks for return.

You can update to the next version when it come (you have some information that common_helper was updated and have to confirm).

Related Changesets

LimeSurvey: master c85494d7

2014-08-20 15:38:46

DenisChenu

Details Diff
Fixed issue 09177: Surveys with quote causing error in MSSQL
Dev : Need to quote column name
Dev : child of https://github.com/LimeSurvey/LimeSurvey/commit/535035816af172fc5b82f3fa896cdb73d53c9800
Affected Issues
09177
mod - application/helpers/common_helper.php Diff File

Issue History

Date Modified Username Field Change
2014-08-19 23:36 Ibistide New Issue
2014-08-19 23:36 Ibistide File Added: limesurvey_survey_624695.lss
2014-08-20 17:15 DenisChenu Assigned To => DenisChenu
2014-08-20 17:15 DenisChenu Status new => assigned
2014-08-20 17:34 DenisChenu Summary Quizzes with Yes/No question causing error in MSSQL => Surveys with quote causing error in MSSQL
2014-08-20 17:38 DenisChenu Changeset attached => LimeSurvey master c85494d7
2014-08-20 17:38 DenisChenu Note Added: 30433
2014-08-20 17:38 DenisChenu Resolution open => fixed
2014-08-20 17:40 DenisChenu Note Added: 30434
2014-08-20 17:40 DenisChenu Status assigned => feedback
2014-08-20 17:40 DenisChenu Note Edited: 30434
2014-08-20 17:40 DenisChenu Target Version => 2.05+
2014-08-20 17:41 DenisChenu Summary Surveys with quote causing error in MSSQL => Surveys with quota causing error in MSSQL
2014-08-20 21:16 Ibistide Note Added: 30435
2014-08-20 21:16 Ibistide Status feedback => assigned
2014-08-21 11:29 DenisChenu Note Added: 30439
2014-08-21 11:29 DenisChenu Status assigned => resolved
2014-08-21 11:29 DenisChenu Fixed in Version => 2.05+
2014-09-08 21:21 c_schmitz Status resolved => closed