From 8d332290a2f22cda04df9e4025b08f87cbad2136 Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Fri, 12 Oct 2012 10:45:35 +0200 Subject: [PATCH] Fixed issue #6671: Impossible to import correctly a group of question Dev getCommandBuilder()->getLastInsertID('') does not work reliably on MySQL. Added getLastInsertID helper function --- application/controllers/admin/dataentry.php | 12 ++++-------- application/helpers/common_helper.php | 2 +- .../admin/survey/QuestionGroups/import_view.php | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/application/controllers/admin/dataentry.php b/application/controllers/admin/dataentry.php index 09bd7e9414a..c3bd7614385 100644 --- a/application/controllers/admin/dataentry.php +++ b/application/controllers/admin/dataentry.php @@ -1869,14 +1869,13 @@ public function insert() $utresult = dbExecuteAssoc($utquery); //Yii::app()->db->Execute($utquery) or safeDie ("Couldn't update tokens table!
\n$utquery
\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!
\n$sdquery
\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" @@ -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 .= "
\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}"; @@ -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 .= "
\n"; - $last_db_id = Yii::app()->db->getLastInsertID(); - } if ($saver['email']) { diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 713a08e5672..b0c7873eebc 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -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 { diff --git a/application/views/admin/survey/QuestionGroups/import_view.php b/application/views/admin/survey/QuestionGroups/import_view.php index c2a87b589c2..1e7229d77bf 100644 --- a/application/views/admin/survey/QuestionGroups/import_view.php +++ b/application/views/admin/survey/QuestionGroups/import_view.php @@ -20,5 +20,5 @@
  • gT("Question attributes:") . $aImportResults['question_attributes'] ?>

  • eT("Question group import is complete.") ?>


    - " onclick="window.open('createUrl('admin/survey/view/surveyid/'.$surveyid.'/gid/'.$aImportResults['newgid']) ?>')" /> + " onclick="window.open('createUrl('admin/survey/view/surveyid/'.$surveyid.'/gid/'.$aImportResults['newgid']) ?>', '_top')" />