Commit
…page Fixed issue #9140: Auto ID is not set properly when using Postgres and deactivating and reactivating the survey
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,31 +394,27 @@ function activateSurvey($iSurveyID, $simulate = false) | |
} | ||
|
||
$anquery = "SELECT autonumber_start FROM {{surveys}} WHERE sid={$iSurveyID}"; | ||
if ($anresult=Yii::app()->db->createCommand($anquery)->query()->readAll()) | ||
{ | ||
//if there is an autonumber_start field, start auto numbering here | ||
foreach($anresult as $row) | ||
$iAutoNumberStart=Yii::app()->db->createCommand($anquery)->queryScalar(); | ||
//if there is an autonumber_start field, start auto numbering here | ||
if ($iAutoNumberStart!==false && $iAutoNumberStart>0) | ||
{ | ||
if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib') { | ||
mssql_drop_primary_index('survey_'.$iSurveyID); | ||
mssql_drop_constraint('id','survey_'.$iSurveyID); | ||
$sQuery = "alter table {{survey_{$iSurveyID}}} drop column id "; | ||
Yii::app()->db->createCommand($sQuery)->execute(); | ||
$sQuery = "alter table {{survey_{$iSurveyID}}} add [id] int identity({$iAutoNumberStart},1)"; | ||
Yii::app()->db->createCommand($sQuery)->execute(); | ||
} | ||
elseif (Yii::app()->db->driverName=='pgsql') | ||
{ | ||
if ($row['autonumber_start'] > 0) | ||
{ | ||
if (Yii::app()->db->driverName=='mssql' || Yii::app()->db->driverName=='sqlsrv' || Yii::app()->db->driverName=='dblib') { | ||
mssql_drop_primary_index('survey_'.$iSurveyID); | ||
mssql_drop_constraint('id','survey_'.$iSurveyID); | ||
$autonumberquery = "alter table {{survey_{$iSurveyID}}} drop column id "; | ||
Yii::app()->db->createCommand($autonumberquery)->execute(); | ||
$autonumberquery = "alter table {{survey_{$iSurveyID}}} add [id] int identity({$row['autonumber_start']},1)"; | ||
Yii::app()->db->createCommand($autonumberquery)->execute(); | ||
} | ||
elseif (Yii::app()->db->driverName=='pgsql') | ||
{ | ||
|
||
} | ||
else | ||
{ | ||
$autonumberquery = "ALTER TABLE {{survey_{$iSurveyID}}} AUTO_INCREMENT = ".$row['autonumber_start']; | ||
$result = @Yii::app()->db->createCommand($autonumberquery)->execute(); | ||
} | ||
} | ||
$sQuery = "SELECT setval(pg_get_serial_sequence('{{survey_{$iSurveyID}}}', 'id'),{$iAutoNumberStart},false);"; | ||
$result = @Yii::app()->db->createCommand($sQuery)->execute(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Shnoulle
Collaborator
|
||
} | ||
else | ||
{ | ||
$sQuery = "ALTER TABLE {{survey_{$iSurveyID}}} AUTO_INCREMENT = {$iAutoNumberStart}"; | ||
$result = @Yii::app()->db->createCommand($sQuery)->execute(); | ||
} | ||
} | ||
|
||
|
1 comment
on commit ea2d73b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see that ??? When you have it ?
Activate new survey get the good control :
"id" serial NOT NULL PRIMARY KEY,
serial is nextval('lime_survey_XXXX_id_seq'::regclass)
The next ID is saved in the survey properties on deactivation. Here is the ID restored :-)