View Issue Details

This bug affects 1 person(s).
 10
IDProjectCategoryView StatusLast Update
20021Bug reportsCentral participant databasepublic2025-04-15 11:37
Reportermo2025 Assigned Totibor.pacalat  
PrioritynoneSeveritycrash 
Status closedResolutionfixed 
Product Version6.6.x 
Summary20021: Deleting a participants leads to 500: Internal server error
Description

We are using a standard limesurvey installation on Ubuntu linux, but Microsoft Azure SQL Server.
Whenever we want to delete a participants, we get an internal server error:

500: Interner Serverfehler - CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The multi-part identifier "dbo.lime_tokens_719895.tid" could not be bound.

We were able to identify the issue: There is an alias for the table, but the alias is not used in the WHERE clausel. In the end the following statement is used:

SELECT * FROM lime_tokens_719895 <ALIAS> WHERE [dbo].[lime_tokens_841351].[tid]=1

Steps To Reproduce

Steps to reproduce

  1. Select a participants to delete.

(Replace this text with detailed step-by-step instructions on how to reproduce the issue)

Expected result

Participant is deleted.

(Write here what you expected to happen)

Actual result

500 Internal error

(Write here what happened instead)

TagsNo tags attached.
Bug heat10
Complete LimeSurvey version number (& build)6.12.0+250317
I will donate to the project if issue is resolvedNo
BrowserChrome / any browser
Database type & versionMicrosoft Azure SQL Server
Server OS (if known)Ubuntu Server
Webserver software & version (if known)Apache
PHP Version8.1.32

Users monitoring this issue

mo2025

Activities

mo2025

mo2025

2025-03-19 10:55

reporter   ~82285

The SQL
SELECT * FROM [dbo].[lime_tokens_841351] [lime_tokens_841351] WHERE [dbo].[lime_tokens_841351].[tid]=1

I added in
/limesurvey/vendor/yiisoft/yii/framework/db/schema/CDbCommandBuilder.php

in function
public function createColumnCriteria($table,$columns,$condition='',$params=array(),$prefix=null)

after

if($prefix===null)
$prefix=$table->rawName.'.';

the line
$prefix = '';

to remove the "[dbo]." from the [dbo].[lime_tokens_841351].[tid]=1

so the WHERE clause fit the alias Name.

I'm sure that this "fix" is not valid for all situation and should be somewhere in the limesurvey part, but it would be good if this issue cloud be fixed for all user, who also use Microsoft SQL Server.

mo2025

mo2025

2025-03-19 10:59

reporter   ~82286

Probably in limesurvey/application/models/LSActiveRecord.php

mo2025

mo2025

2025-03-19 12:37

reporter   ~82288

Yes, it is better to change line 206 in application/models/LSActiveRecord.php to damange not other parts of the application.
I changed
$criteria = $builder->createColumnCriteria($table, $attributes, $condition, $params);
to
$criteria = $builder->createColumnCriteria($table, $attributes, $condition, $params,"");

gabrieljenik

gabrieljenik

2025-04-03 21:20

manager   ~82369

Last edited: 2025-04-03 21:20

Couldn't reproduce netiher on msqql nor azure.

Not sure at what point in the token deletion process a query like the one in the ticket is generated.
Can you please expand?

That aside, when deleting the token, the following SQL is executed and works correctly:
DELETE FROM [dbo].[lime_tokens_422295] WHERE [dbo].[lime_tokens_422295].[tid] = 2

mo2025

mo2025

2025-04-04 10:47

reporter   ~82370

Thank you, @gabrieljenik, for taking care of this issue.
I will add more information as soon as I can revert my changes. In the meantime, can you take a look at this ticket? It looks to me like the same issue is present here:
https://bugs.limesurvey.org/view.php?id=20035

gabrieljenik

gabrieljenik

2025-04-07 16:55

manager   ~82385

I would suggest to set debug to 2 (on config), reproduce the issue, capture the error output and poist it here. Thanks

mo2025

mo2025

2025-04-09 13:44

reporter   ~82402

Hi @gabrieljenik :
This is the output:
CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The multi-part identifier "dbo.lime_tokens_891925.tid" could not be bound.. The SQL statement executed was: SELECT * FROM [dbo].[lime_tokens_891925] [lime_tokens_891925] WHERE [dbo].[lime_tokens_891925].[tid]=6

limesurvey/vendor/yiisoft/yii/framework/db/CDbCommand.php(543)

531 {
532 if($this->_connection->enableProfiling)
533 Yii::endProfile('system.db.CDbCommand.query('.$this->getText().$par.')','system.db.CDbCommand.query');
534
535 $errorInfo=$e instanceof PDOException ? $e->errorInfo : null;
536 $message=$e->getMessage();
537 Yii::log(Yii::t('yii','CDbCommand::{method}() failed: {error}. The SQL statement executed was: {sql}.',
538 array('{method}'=>$method, '{error}'=>$message, '{sql}'=>$this->getText().$par)),CLogger::LEVEL_ERROR,'system.db.CDbCommand');
539
540 if(YII_DEBUG)
541 $message.='. The SQL statement executed was: '.$this->getText().$par;
542
543 throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
544 array('{error}'=>$message)),(int)$e->getCode(),$errorInfo);
545 }
546 }
547
548 /*
549
Builds a SQL SELECT statement from the given query specification.
550 @param array $query the query specification in name-value pairs. The following
551
query options are supported: {@link select}, {@link distinct}, {@link from},
552 {@link where}, {@link join}, {@link group}, {@link having}, {@link order},
553
{@link limit}, {@link offset} and {@link union}.
554 @throws CDbException if "from" key is not present in given query parameter
555
@return string the SQL statement
Stack Trace
#0

  • limesurvey/vendor/yiisoft/yii/framework/db/CDbCommand.php(396): CDbCommand->queryInternal()
    #1
  • limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(1359): CDbCommand->queryAll()
    #2
    – limesurvey/application/models/LSActiveRecord.php(77): CActiveRecord->query()
    72 @since 1.1.7
    73
    /
    74 protected function query($criteria, $all = false, $asAR = true)
    75 {
    76 if ($asAR === true) {
    77 return parent::query($criteria, $all);
    78 } else {
    79 $this->beforeFind();
    80 $this->applyScopes($criteria);
    81 if (!$all) {
    82 $criteria->limit = 1;
    #3
  • limesurvey/vendor/yiisoft/yii/framework/db/ar/CActiveRecord.php(1478): LSActiveRecord->query()
    #4
    – limesurvey/application/core/plugins/AuditLog/AuditLog.php(441): CActiveRecord->findAll()
    436 // We are given a DELETE query criteria and need to use it on a SELECT query.
    437 // Add the alias.
    438 $tableName = Token::model($surveyId)->getTableSchema()->name;
    439 $filterCriteria->alias = $tableName;
    440
    441 $tokens = Token::model($surveyId)->findAll($filterCriteria);
    442
    443 $oCurrentUser = $this->api->getCurrentUser();
    444
    445 foreach ($tokens as $token) {
    446 $aValues = $token->getAttributes();
    #5
    unknown(0): AuditLog->beforeTokenDeleteMany()
    #6
    – limesurvey/application/libraries/PluginManager/PluginManager.php(269): call_user_func()
    264 if (
    265 !$event->isStopped()
    266 && (empty($target) || in_array(get_class($subscription[0]), $target))
    267 ) {
    268 $subscription[0]->setEvent($event);
    269 call_user_func($subscription);
    270 }
    271 }
    272 }
    273
    274 return $event;
gabrieljenik

gabrieljenik

2025-04-11 19:55

manager   ~82414

https://github.com/LimeSurvey/LimeSurvey/pull/4239

DenisChenu

DenisChenu

2025-04-14 10:03

developer   ~82419

Reviewed by Carsten

LimeBot

LimeBot

2025-04-15 11:37

administrator   ~82426

Fixed in Release 6.13.0+250415

Issue History

Date Modified Username Field Change
2025-03-19 09:26 mo2025 New Issue
2025-03-19 09:27 mo2025 Issue Monitored: mo2025
2025-03-19 09:27 mo2025 Bug heat 0 => 2
2025-03-19 10:55 mo2025 Note Added: 82285
2025-03-19 10:55 mo2025 Bug heat 2 => 4
2025-03-19 10:59 mo2025 Note Added: 82286
2025-03-19 12:37 mo2025 Note Added: 82288
2025-03-30 22:51 tibor.pacalat Assigned To => gabrieljenik
2025-03-30 22:51 tibor.pacalat Status new => assigned
2025-04-03 21:20 gabrieljenik Status assigned => feedback
2025-04-03 21:20 gabrieljenik Note Added: 82369
2025-04-03 21:20 gabrieljenik Bug heat 4 => 6
2025-04-03 21:20 gabrieljenik Note Edited: 82369
2025-04-04 10:47 mo2025 Note Added: 82370
2025-04-04 10:47 mo2025 Status feedback => assigned
2025-04-07 16:55 gabrieljenik Note Added: 82385
2025-04-09 13:44 mo2025 Note Added: 82402
2025-04-11 19:55 gabrieljenik Assigned To gabrieljenik => DenisChenu
2025-04-11 19:55 gabrieljenik Status assigned => ready for code review
2025-04-11 19:55 gabrieljenik Note Added: 82414
2025-04-14 10:03 DenisChenu Assigned To DenisChenu => tibor.pacalat
2025-04-14 10:03 DenisChenu Status ready for code review => ready for testing
2025-04-14 10:03 DenisChenu Note Added: 82419
2025-04-14 10:03 DenisChenu Bug heat 6 => 8
2025-04-14 13:24 tibor.pacalat Status ready for testing => resolved
2025-04-14 13:24 tibor.pacalat Resolution open => fixed
2025-04-15 11:37 LimeBot Note Added: 82426
2025-04-15 11:37 LimeBot Status resolved => closed
2025-04-15 11:37 LimeBot Bug heat 8 => 10