Skip to content

Commit

Permalink
Fixed issue #7095: Usage of wrong db engine when mysql database is co…
Browse files Browse the repository at this point in the history
…nfigured to not default to MyISAM
  • Loading branch information
c-schmitz committed Dec 19, 2012
1 parent 334ee5a commit 8a8880a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
7 changes: 3 additions & 4 deletions application/helpers/admin/activate_helper.php
Expand Up @@ -377,10 +377,10 @@ function activateSurvey($iSurveyID, $simulate = false)
//$createsurvey = rtrim($createsurvey, ",\n")."\n"; // Does nothing if not ending with a comma

$tabname = "{{survey_{$iSurveyID}}}";
$command = new CDbCommand(Yii::app()->db);
Yii::app()->loadHelper("database");
try
{
$execresult = $command->createTable($tabname,$createsurvey);
$execresult = createTable($tabname, $createsurvey);
}
catch (CDbException $e)
{
Expand Down Expand Up @@ -427,11 +427,10 @@ function activateSurvey($iSurveyID, $simulate = false)
$column[$field] = 'FLOAT';
}

$command = new CDbCommand(Yii::app()->db);
$tabname = "{{survey_{$iSurveyID}}}_timings";
try
{
$execresult = $command->createTable($tabname,$column);
$execresult = createTable($tabname,$column);
}
catch (CDbException $e)
{
Expand Down
11 changes: 8 additions & 3 deletions application/helpers/database_helper.php
Expand Up @@ -193,9 +193,9 @@ function dbGetTablesLike($table)
*
* @param mixed $sTableName
* @param mixed $aColumns
* @param mixed $aOptions
* @param mixed $sOptions
*/
function createTable($sTableName, $aColumns, $aOptions=null)
function createTable($sTableName, $aColumns, $sOptions=null)
{
$sDBDriverName=Yii::app()->db->getDriverName();

Expand All @@ -214,5 +214,10 @@ function createTable($sTableName, $aColumns, $aOptions=null)
$sType=str_replace('varchar','character varying',$sType);
}
}
Yii::app()->db->createCommand()->createTable($sTableName,$aColumns,$aOptions);
if (Yii::app()->db->driverName == 'mysql' || Yii::app()->db->driverName == 'mysqli')
{
if (is_null($sOptions))
$sOptions='ENGINE=MyISAM';
}
Yii::app()->db->createCommand()->createTable($sTableName,$aColumns,$sOptions);
}
36 changes: 18 additions & 18 deletions application/helpers/update/updatedb_helper.php
Expand Up @@ -91,7 +91,7 @@ function db_upgrade_all($oldversion) {
upgradeTokenTables126();

// Create quota table
Yii::app()->db->createCommand()->createTable('{{quota}}',array(
createTable('{{quota}}',array(
'id' => 'pk',
'sid' => 'integer',
'qlimit' => 'integer',
Expand All @@ -101,7 +101,7 @@ function db_upgrade_all($oldversion) {
));

// Create quota_members table
Yii::app()->db->createCommand()->createTable('{{quota_members}}',array(
createTable('{{quota_members}}',array(
'id' => 'pk',
'sid' => 'integer',
'qid' => 'integer',
Expand All @@ -112,15 +112,15 @@ function db_upgrade_all($oldversion) {


// Create templates_rights table
Yii::app()->db->createCommand()->createTable('{{templates_rights}}',array(
createTable('{{templates_rights}}',array(
'uid' => 'integer NOT NULL',
'folder' => 'string NOT NULL',
'use' => 'integer',
'PRIMARY KEY (uid, folder)'
));

// Create templates table
Yii::app()->db->createCommand()->createTable('{{templates}}',array(
createTable('{{templates}}',array(
'folder' => 'string NOT NULL',
'creator' => 'integer NOT NULL',
'PRIMARY KEY (folder)'
Expand Down Expand Up @@ -365,7 +365,7 @@ function db_upgrade_all($oldversion) {
'modified' => "datetime NOT NULL",
'sessdata' => 'text'
);
Yii::app()->db->createCommand()->createTable('{{sessions}}',$fields);
createTable('{{sessions}}',$fields);
addPrimaryKey('sessions',array('sesskey'));
Yii::app()->db->createCommand()->createIndex('sess2_expiry','{{sessions}}','expiry');
Yii::app()->db->createCommand()->createIndex('sess2_expireref','{{sessions}}','expireref');
Expand Down Expand Up @@ -430,7 +430,7 @@ function db_upgrade_all($oldversion) {
'import_p' => "integer NOT NULL default 0",
'export_p' => "integer NOT NULL default 0"
);
Yii::app()->db->createCommand()->createTable('{{survey_permissions}}',$fields);
createTable('{{survey_permissions}}',$fields);
addPrimaryKey('survey_permissions', array('sid','uid','permission'));

upgradeSurveyPermissions145();
Expand Down Expand Up @@ -585,7 +585,7 @@ function db_upgrade_all($oldversion) {

addColumn('{{surveys_languagesettings}}','surveyls_numberformat',"integer NOT NULL DEFAULT 0");

Yii::app()->db->createCommand()->createTable('{{failed_login_attempts}}',array(
createTable('{{failed_login_attempts}}',array(
'id' => "pk",
'ip' => $sVarchar.'(37) NOT NULL',
'last_attempt' => $sVarchar.'(20) NOT NULL',
Expand Down Expand Up @@ -614,7 +614,7 @@ function db_upgrade_all($oldversion) {
{
addColumn('{{users}}','participant_panel',"integer NOT NULL default 0");

Yii::app()->db->createCommand()->createTable('{{participants}}',array(
createTable('{{participants}}',array(
'participant_id' => $sVarchar.'(50) NOT NULL',
'firstname' => $sVarchar.'(40) default NULL',
'lastname' => $sVarchar.'(40) default NULL',
Expand All @@ -625,42 +625,42 @@ function db_upgrade_all($oldversion) {
));
addPrimaryKey('participants', array('participant_id'));

Yii::app()->db->createCommand()->createTable('{{participant_attribute}}',array(
createTable('{{participant_attribute}}',array(
'participant_id' => $sVarchar.'(50) NOT NULL',
'attribute_id' => "integer NOT NULL",
'value' => $sVarchar.'(50) NOT NULL'
));
addPrimaryKey('participant_attribute', array('participant_id','attribute_id'));

Yii::app()->db->createCommand()->createTable('{{participant_attribute_names}}',array(
createTable('{{participant_attribute_names}}',array(
'attribute_id' => $sAutoIncrement,
'attribute_type' => $sVarchar.'(4) NOT NULL',
'visible' => $sVarchar.'(5) NOT NULL',
'PRIMARY KEY (attribute_id,attribute_type)'
));

Yii::app()->db->createCommand()->createTable('{{participant_attribute_names_lang}}',array(
createTable('{{participant_attribute_names_lang}}',array(
'attribute_id' => 'integer NOT NULL',
'attribute_name' => $sVarchar.'(30) NOT NULL',
'lang' => $sVarchar.'(20) NOT NULL'
));
addPrimaryKey('participant_attribute_names_lang', array('attribute_id','lang'));

Yii::app()->db->createCommand()->createTable('{{participant_attribute_values}}',array(
createTable('{{participant_attribute_values}}',array(
'attribute_id' => 'integer NOT NULL',
'value_id' => 'pk',
'value' => $sVarchar.'(20) NOT NULL'
));

Yii::app()->db->createCommand()->createTable('{{participant_shares}}',array(
createTable('{{participant_shares}}',array(
'participant_id' => $sVarchar.'(50) NOT NULL',
'share_uid' => 'integer NOT NULL',
'date_added' => 'datetime NOT NULL',
'can_edit' => $sVarchar.'(5) NOT NULL'
));
addPrimaryKey('participant_shares', array('participant_id','share_uid'));

Yii::app()->db->createCommand()->createTable('{{survey_links}}',array(
createTable('{{survey_links}}',array(
'participant_id' => $sVarchar.'(50) NOT NULL',
'token_id' => 'integer NOT NULL',
'survey_id' => 'integer NOT NULL',
Expand All @@ -685,7 +685,7 @@ function db_upgrade_all($oldversion) {
'targetqid' => 'integer',
'targetsqid' => 'integer'
);
Yii::app()->db->createCommand()->createTable('{{survey_url_parameters}}',$fields);
createTable('{{survey_url_parameters}}',$fields);
Yii::app()->db->createCommand()->update('{{settings_global}}',array('stg_value'=>149),"stg_name='DBVersion'");
}

Expand Down Expand Up @@ -749,7 +749,7 @@ function db_upgrade_all($oldversion) {
{
// do nothing
}
Yii::app()->db->createCommand()->createTable('{{survey_url_parameters}}',array(
createTable('{{survey_url_parameters}}',array(
'id' => 'pk',
'sid' => 'integer NOT NULL',
'parameter' => $sVarchar.'(50) NOT NULL',
Expand All @@ -760,15 +760,15 @@ function db_upgrade_all($oldversion) {
Yii::app()->db->createCommand()->dropTable('{{sessions}}');
if ($sDBDriverName=='mysql')
{
Yii::app()->db->createCommand()->createTable('{{sessions}}',array(
createTable('{{sessions}}',array(
'id' => $sVarchar.'(32) NOT NULL',
'expire' => 'integer',
'data' => 'longtext'
));
}
else
{
Yii::app()->db->createCommand()->createTable('{{sessions}}',array(
createTable('{{sessions}}',array(
'id' => $sVarchar.'(32) NOT NULL',
'expire' => 'integer',
'data' => 'text'
Expand Down

0 comments on commit 8a8880a

Please sign in to comment.