View Issue Details

This bug affects 1 person(s).
 8
IDProjectCategoryView StatusLast Update
17189Bug reportsImport/Exportpublic2021-03-22 15:27
Reporterzufolo441 Assigned Toc_schmitz  
PrioritynoneSeveritypartial_block 
Status closedResolutionfixed 
Product Version4.4.13 
Summary17189: wrong field size in SPSS syntax export
Description

Hi, when I export data in SPSS, the size of text field is always 1:
for example:
V25 A1

I suppose the problem is in row 398 of export_helper.php

if (in_array($field['LStype'], array('Q', 'S', 'T', 'U', ';', '*'))) {
    return array(
        'SPSStype' => "A",
        'size' => stringSize($field['sql_name']),
    );
}
Steps To Reproduce

export syntax file of SPSS.

TagsNo tags attached.
Bug heat8
Complete LimeSurvey version number (& build)4.4.13
I will donate to the project if issue is resolvedNo
Browser
Database type & versionPostgreSQL 11.9
Server OS (if known)
Webserver software & version (if known)
PHP Version7.1.33

Users monitoring this issue

There are no users monitoring this issue.

Activities

zufolo441

zufolo441

2021-03-17 16:43

reporter   ~63408

in the function stringSize(), the variable $lengthReal has empty value. DB is PostgreSQL.

zufolo441

zufolo441

2021-03-17 17:19

reporter   ~63411

I found the problem:
it is in this query:

SELECT LENGTH("734558X76X2746") FROM "lime_survey_734558" ORDER BY LENGTH("734558X76X2746") DESC

For PostgreSQL, LENGTH(NULL) = NULL, so, that query puts NULL values as first rows. The result is that queryScalar() returns NULL if at least one field in column is null, and stringSize() almost always return 1 as field length.

I had to modify function in this way, by adding a WHERE condition:

function stringSize($sColumn)
{
// Find the sid
$iSurveyId = substr($sColumn, 0, strpos($sColumn, 'X'));
switch (Yii::app()->db->driverName) {
case 'sqlsrv':
case 'dblib':
case 'mssql':
$lengthWord = 'LEN';
break;
default:
$lengthWord = 'LENGTH';
}

$lengthCmd = Yii::app()->db->createCommand()
->select("{$lengthWord}(" . Yii::app()->db->quoteColumnName($sColumn) . ")")
->from("{{survey_" . $iSurveyId . "}}")
->order("{$lengthWord}(" . Yii::app()->db->quoteColumnName($sColumn) . ")  DESC")
->where(Yii::app()->db->quoteColumnName($sColumn)." IS NOT NULL ")
->limit(1);
$lengthReal = $lengthCmd->queryScalar();
// PSPP didn't accept A0 then min value to 1, see bug 13008

return max(1, (int) $lengthReal);

}

...and problem solved, at least for me: I cannot try this in other DB.

DenisChenu

DenisChenu

2021-03-17 17:26

developer   ~63414

Great : can you create a pull request ?

c_schmitz

c_schmitz

2021-03-17 20:17

administrator   ~63419

Fix committed to 3.x-LTS branch: http://bugs.limesurvey.org/plugin.php?page=Source/view&id=31340

c_schmitz

c_schmitz

2021-03-17 20:21

administrator   ~63420

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

lime_release_bot

lime_release_bot

2021-03-22 15:27

administrator   ~63533

Fixed in Release 4.4.14+210322

Related Changesets

LimeSurvey: 3.x-LTS 2eaeaeae

2021-03-17 20:17:34

c_schmitz

Details Diff
Fixed issue 17189: Wrong field size in SPSS syntax export Affected Issues
17189
mod - application/helpers/export_helper.php Diff File

LimeSurvey: master 8e2f185c

2021-03-17 20:17:34

c_schmitz

Details Diff
Fixed issue 17189: Wrong field size in SPSS syntax export when using Postgres Affected Issues
17189
mod - application/helpers/export_helper.php Diff File

Issue History

Date Modified Username Field Change
2021-03-17 13:00 zufolo441 New Issue
2021-03-17 16:43 zufolo441 Note Added: 63408
2021-03-17 17:19 zufolo441 Note Added: 63411
2021-03-17 17:26 DenisChenu Note Added: 63414
2021-03-17 20:17 c_schmitz Changeset attached => LimeSurvey 3.x-LTS 2eaeaeae
2021-03-17 20:17 c_schmitz Note Added: 63419
2021-03-17 20:17 c_schmitz Assigned To => c_schmitz
2021-03-17 20:17 c_schmitz Resolution open => fixed
2021-03-17 20:21 c_schmitz Changeset attached => LimeSurvey master 8e2f185c
2021-03-17 20:21 c_schmitz Note Added: 63420
2021-03-17 20:21 c_schmitz Status new => resolved
2021-03-22 15:27 lime_release_bot Note Added: 63533
2021-03-22 15:27 lime_release_bot Status resolved => closed