Skip to content

Commit

Permalink
Fixed issue #6671: Impossible to import correctly a group of question
Browse files Browse the repository at this point in the history
Dev  getCommandBuilder()->getLastInsertID('<sometablename>') does not work reliably on MySQL. Added getLastInsertID helper function
  • Loading branch information
c-schmitz committed Oct 12, 2012
1 parent c278e09 commit 8d33229
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions application/controllers/admin/dataentry.php
Expand Up @@ -1869,14 +1869,13 @@ public function insert()
$utresult = dbExecuteAssoc($utquery); //Yii::app()->db->Execute($utquery) or safeDie ("Couldn't update tokens table!<br />\n$utquery<br />\n".Yii::app()->db->ErrorMsg());

// save submitdate into survey table
$srid = Yii::app()->db->getLastInsertID(); // Yii::app()->db->getLastInsertID();
$sdquery = "UPDATE {{survey_$surveyid}} SET submitdate='".$submitdate."' WHERE id={$srid}\n";
$sdquery = "UPDATE {{survey_$surveyid}} SET submitdate='".$submitdate."' WHERE id={$new_response}\n";
$sdresult = dbExecuteAssoc($sdquery) or safeDie ("Couldn't set submitdate response in survey table!<br />\n$sdquery<br />\n");
$last_db_id = Yii::app()->db->getLastInsertID();
$last_db_id = getLastInsertID("{{survey_$surveyid}}");
}
if (isset($_POST['save']) && $_POST['save'] == "on")
{
$srid = Yii::app()->db->getLastInsertID(); //Yii::app()->db->getLastInsertID();
$srid = $last_db_id;
$aUserData=Yii::app()->session;
//CREATE ENTRY INTO "saved_control"

Expand Down Expand Up @@ -1906,13 +1905,12 @@ public function insert()
$this->load->model('saved_control_model');*/
if (dbExecuteAssoc($SQL))
{
$scid = Yii::app()->db->getLastInsertID(); // Yii::app()->db->getLastInsertID("{{saved_control}}","scid");
$scid = getLastInsertID('{{saved_control}}');

$aDataentrymsgs[] = CHtml::tag('font', array('class'=>'successtitle'), $clang->gT("Your survey responses have been saved successfully. You will be sent a confirmation e-mail. Please make sure to save your password, since we will not be able to retrieve it for you."));
//$aDataentryoutput .= "<font class='successtitle'></font><br />\n";

$tokens_table = "{{tokens_$surveyid}}";
$last_db_id = Yii::app()->db->getLastInsertID();
if (tableExists($tokens_table)) //If the query fails, assume no tokens table exists
{
$tkquery = "SELECT * FROM {$tokens_table}";
Expand Down Expand Up @@ -1940,8 +1938,6 @@ public function insert()
//Yii::app()->db->AutoExecute(db_table_name("tokens_".$surveyid), $tokendata,'INSERT');
$aDataentrymsgs[] = CHtml::tag('font', array('class'=>'successtitle'), $clang->gT("A token entry for the saved survey has been created too."));
//$aDataentryoutput .= "<font class='successtitle'></font><br />\n";
$last_db_id = Yii::app()->db->getLastInsertID();

}
if ($saver['email'])
{
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/common_helper.php
Expand Up @@ -6714,7 +6714,7 @@ function getLastInsertID($sTableName)
$sDBDriver=Yii::app()->db->getDriverName();
if ($sDBDriver=='mysql' || $sDBDriver=='mysqli')
{
return Yii::app()->db->getLastInsertID();
return getLastInsertID();
}
else
{
Expand Down
Expand Up @@ -20,5 +20,5 @@
<li><?php echo $clang->gT("Question attributes:") . $aImportResults['question_attributes'] ?></li>
</ul><br/>
<p><strong><?php $clang->eT("Question group import is complete.") ?></strong></p><br />
<input type='submit' value="<?php $clang->eT("Go to question group") ?>" onclick="window.open('<?php echo $this->createUrl('admin/survey/view/surveyid/'.$surveyid.'/gid/'.$aImportResults['newgid']) ?>')" />
<input type='submit' value="<?php $clang->eT("Go to question group") ?>" onclick="window.open('<?php echo $this->createUrl('admin/survey/view/surveyid/'.$surveyid.'/gid/'.$aImportResults['newgid']) ?>', '_top')" />
</div><br />

0 comments on commit 8d33229

Please sign in to comment.