View Issue Details

This bug affects 1 person(s).
 0
IDProjectCategoryView StatusLast Update
20175Bug reportsPrint Viewpublic2025-07-15 23:15
ReporterMauro Assigned To 
PrioritynoneSeveritycrash 
Status newResolutionopen 
Product Version6.6.x 
Summary20175: Print survey fails on SQL Server due to duplicated ORDER BY (sortorder,code)
Description

Description
When generating a Printable Survey in LimeSurvey version 6.15.4+250710 using Microsoft SQL Server, the application crashes with a 500 Internal Server Error.

The problem is due to a duplicated ORDER BY clause in the SQL query executed by the controller PrintableSurvey.php (around line 1270). The query explicitly sets order => 'sortorder,code', even though this same clause is already included in the model's defaultScope().

Temporary fix
Manually editing the line to include a space after the comma (i.e., 'sortorder, code') avoids duplication. Alternatively, removing the 'order' key from the findAll() call resolves the issue completely.

Steps To Reproduce

Steps to reproduce
Use LimeSurvey version 6.15.4+250710 with Microsoft SQL Server (ODBC Driver 17).

Create a survey with at least one multiple-choice or array question (with answer options).

Go to the survey administration menu and click "Print survey".

The application tries to render the survey content and fails.

Expected result
The survey should render the printable view successfully, showing all questions and their answer options.

Actual result
The server returns a 500 Internal Server Error. The following database error appears:

CDbCommand failed to execute the SQL statement: SQLSTATE[42000]:
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]A column has been specified more than once in the ORDER BY list.
Columns in the ORDER BY list must be unique.
Root cause:
The PrintableSurvey.php controller explicitly sets the order => 'sortorder,code' in a query to Answer::model()->findAll(), but this same order is already included in the model's defaultScope(). This results in a duplicated ORDER BY clause like:

ORDER BY sortorder, code, sortorder, code
SQL Server does not allow repeated fields in the ORDER BY clause, unlike MySQL or PostgreSQL.

Workaround tested:
Editing PrintableSurvey.php line 1270 and adding a space after the comma ('sortorder, code') prevents duplication. Alternatively, removing the 'order' key entirely also resolves the error.

TagsNo tags attached.
Attached Files
ERROR_DETAIL.png (187,955 bytes)
ERROR_SQL_LIME.png (75,688 bytes)   
ERROR_SQL_LIME.png (75,688 bytes)   
Bug heat0
Complete LimeSurvey version number (& build)6.15.4+250710
I will donate to the project if issue is resolvedNo
Browser
Database type & versionMicrosoft SQL Server 2019, ODBC Driver 17
Server OS (if known)Ubuntu 22.04
Webserver software & version (if known)
PHP Version8.3.19

Users monitoring this issue

There are no users monitoring this issue.

Activities

Issue History

Date Modified Username Field Change
2025-07-15 23:15 Mauro New Issue
2025-07-15 23:15 Mauro File Added: ERROR_DETAIL.png
2025-07-15 23:15 Mauro File Added: ERROR_SQL_LIME.png