Skip to content

Commit

Permalink
Fixed issue #7610: Missing MSSQL support under Linux (pdo_dblib support)
Browse files Browse the repository at this point in the history
Dev Note: Not completed yet
  • Loading branch information
c-schmitz committed Sep 24, 2013
1 parent 6aff262 commit 5852098
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 241 deletions.
7 changes: 5 additions & 2 deletions application/commands/InstallCommand.php
Expand Up @@ -60,6 +60,8 @@ public function run($sArgument)
$createDb=false;
}
break;

case 'dblib':
case 'mssql':
case 'odbc':
try
Expand Down Expand Up @@ -90,7 +92,7 @@ public function run($sArgument)
{
$createDb=false;
}
break;
break;
}
if (!$createDb)
{
Expand All @@ -117,13 +119,14 @@ public function run($sArgument)
}
$sql_file = 'pgsql';
break;
case 'dblib':
case 'mssql':
$sql_file = 'mssql';
break;
default:
throw new Exception(sprintf('Unkown database type "%s".', $sDatabaseType));
}
$this->_executeSQLFile(dirname(Yii::app()->basePath).'/installer/sql/create-'.$sql_file.'.sql', $aConfig['db']['tablePrefix']);
$this->_executeSQLFile(dirname(Yii::app()->basePath).'/installer/sql/create-'.$sql_file.'.sql', $aConfig['db']['tablePrefix']);
$this->connection->createCommand()->insert($aConfig['db']['tablePrefix'].'users', array(
'users_name'=>$sArgument[0],
'password'=>hash('sha256',$sArgument[1]),
Expand Down
72 changes: 72 additions & 0 deletions application/config/config-sample-dblib.php
@@ -0,0 +1,72 @@
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| 'connectionString' Hostname, database, port and database type for
| the connection. Driver example: mysql. Currently supported:
| mysql, pgsql, mssql, sqlite, oci
| 'username' The username used to connect to the database
| 'password' The password used to connect to the database
| 'tablePrefix' You can add an optional prefix, which will be added
| to the table name when using the Active Record class
|
*/
return array(
'basePath' => dirname(dirname(__FILE__)),
'runtimePath' => dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'runtime',
'name' => 'LimeSurvey',
'defaultController' => 'survey',

'import' => array(
'application.core.*',
'application.models.*',
'application.controllers.*',
'application.modules.*',
),

'components' => array(
'db' => array(
'connectionString' => 'dblib:host=localhost;dbname=limesurvey',
'username' => 'sa',
'password' => 'somepassword',
'charset' => 'utf8',
'tablePrefix' => 'lime_',
'initSQLs'=>array('SET DATEFORMAT ymd;','SET QUOTED_IDENTIFIER ON;'),
),

// Uncomment the following line if you need table-based sessions
// 'session' => array (
// 'class' => 'system.web.CDbHttpSession',
// 'connectionID' => 'db',
// 'sessionTableName' => '{{sessions}}',
// ),

'urlManager' => array(
'urlFormat' => 'get',
'rules' => require('routes.php'),
'showScriptName' => true,
),

),
// Use the following config variable to set modified optional settings copied from config-defaults.php
'config'=>array(
// debug: Set this to 1 if you are looking for errors. If you still get no errors after enabling this
// then please check your error-logs - either in your hosting provider admin panel or in some /logs directory
// on your webspace.
// LimeSurvey developers: Set this to 2 to additionally display STRICT PHP error messages and get full access to standard templates
'debug'=>0,
'debugsql'=>0 // Set this to 1 to enanble sql logging, only active when debug = 2
)
);
/* End of file config.php */
/* Location: ./application/config/config.php */
27 changes: 16 additions & 11 deletions application/controllers/InstallerController.php
Expand Up @@ -290,7 +290,6 @@ private function stepDatabaseConfiguration()
Yii::app()->session['dblocation'] = $sDatabaseLocation;

//check if table exists or not
$sTestTablename = 'surveys';
$bTablesDoNotExist = false;

// Check if the surveys table exists or not
Expand Down Expand Up @@ -338,7 +337,7 @@ private function stepDatabaseConfiguration()
}

// Setting dateformat for mssql driver. It seems if you don't do that the in- and output format could be different
if (in_array($model->dbtype, array('mssql', 'sqlsrv'))) {
if (in_array($model->dbtype, array('mssql', 'sqlsrv', 'dblib'))) {
@$this->connection->createCommand('SET DATEFORMAT ymd;')->execute(); //Checked
@$this->connection->createCommand('SET QUOTED_IDENTIFIER ON;')->execute(); //Checked
}
Expand Down Expand Up @@ -446,6 +445,7 @@ function stepCreateDb()
$createDb=false;
}
break;
case 'dblib':
case 'mssql':
case 'odbc':
try
Expand Down Expand Up @@ -540,6 +540,7 @@ function stepPopulateDb()
case 'mysql':
$sql_file = 'mysql';
break;
case 'dblib':
case 'sqlsrv':
case 'mssql':
$sql_file = 'mssql';
Expand Down Expand Up @@ -818,7 +819,7 @@ function check_DirectoryWriteable($directory, &$data, $base, $keyError, $bRecurs
// JSON library check
if (!check_PHPFunction('json_encode', $data['bJSONPresent']))
$bProceed = false;

// ** file and directory permissions checking **

// config directory
Expand All @@ -832,13 +833,13 @@ function check_DirectoryWriteable($directory, &$data, $base, $keyError, $bRecurs
//upload directory check
if (!check_DirectoryWriteable(Yii::app()->getConfig('uploaddir').'/', $data, 'uploaddir', 'uerror',true) )
$bProceed = false;

// Session writable check
$session = Yii::app()->session; /* @var $session CHttpSession */
$sessionWritable = ($session->get('saveCheck', null)==='save');
$data['sessionWritable'] = $sessionWritable;
$data['sessionWritableImg'] = check_HTML_image($sessionWritable);
if (!$sessionWritable){
if (!$sessionWritable){
// For recheck, try to set the value again
$session['saveCheck'] = 'save';
$bProceed = false;
Expand All @@ -860,7 +861,7 @@ function check_DirectoryWriteable($directory, &$data, $base, $keyError, $bRecurs

// zlib php library check
check_PHPFunction('zlib_get_coding_type', $data['zlibPresent']);

// imap php library check
check_PHPFunction('imap_open', $data['bIMAPPresent']);

Expand Down Expand Up @@ -965,7 +966,7 @@ function _writeConfigFile()
{
$sURLFormat='get'; // Fall back to get if an Apache server cannot be determined reliably
}

$dbdata = "<?php if (!defined('BASEPATH')) exit('No direct script access allowed');" . "\n"
."/*"."\n"
."| -------------------------------------------------------------------"."\n"
Expand Down Expand Up @@ -1007,7 +1008,7 @@ function _writeConfigFile()
."\t" . "'components' => array(" . "\n"
."\t\t" . "'db' => array(" . "\n"
."\t\t\t" . "'connectionString' => '$sDsn'," . "\n";
if ($sDatabaseType!='sqlsrv')
if ($sDatabaseType!='sqlsrv' && $sDatabaseType!='dblib' )
{
$dbdata .="\t\t\t" . "'emulatePrepare' => true," . "\n";

Expand All @@ -1017,7 +1018,7 @@ function _writeConfigFile()
."\t\t\t" . "'charset' => 'utf8'," . "\n"
."\t\t\t" . "'tablePrefix' => '$sDatabasePrefix'," . "\n";

if (in_array($sDatabaseType, array('mssql', 'sqlsrv'))) {
if (in_array($sDatabaseType, array('mssql', 'sqlsrv', 'dblib'))) {
$dbdata .="\t\t\t" ."'initSQLs'=>array('SET DATEFORMAT ymd;','SET QUOTED_IDENTIFIER ON;')," . "\n";
}

Expand Down Expand Up @@ -1077,7 +1078,7 @@ function _writeConfigFile()
}

/**
* Create a random ASCII string
* Create a random ASCII string
*
* @return string
*/
Expand Down Expand Up @@ -1120,6 +1121,9 @@ function _getDsn($sDatabaseType, $sDatabaseLocation, $sDatabasePort, $sDatabaseN
}
break;

case 'dblib' :
$dsn = $sDatabaseType.":host={$sDatabaseLocation};dbname={$sDatabaseName}";
break;
case 'mssql' :
case 'sqlsrv':
if ($sDatabasePort!=''){$sDatabaseLocation=$sDatabaseLocation.','.$sDatabasePort;}
Expand Down Expand Up @@ -1152,6 +1156,7 @@ function _getDbPort($sDatabaseType, $sDatabasePort = '')
case 'pgsql':
$sDatabasePort = '5432';
break;
case 'dblib' :
case 'mssql' :
case 'sqlsrv':
default:
Expand Down Expand Up @@ -1193,7 +1198,7 @@ function _dbConnect($aDbConfig = array(), $aData = array())

try {
$this->connection = new CDbConnection($sDsn, $sDatabaseUser, $sDatabasePwd);
if($sDatabaseType!='sqlsrv'){
if($sDatabaseType!='sqlsrv' && $sDatabaseType!='dblib'){
$this->connection->emulatePrepare = true;
}

Expand Down
10 changes: 5 additions & 5 deletions application/controllers/Statistics_userController.php
Expand Up @@ -167,10 +167,10 @@ function actionAction($surveyid,$language)
* only show questions where question attribute "public_statistics" is set to "1"
*/

$query = "SELECT q.* , group_name, group_order FROM {{questions}} q, {{groups}} g, {{question_attributes}} qa
$query = "SELECT q.* , group_name, group_order FROM {{questions}} q, {{groups}} g, {{question_attributes}} qa
WHERE g.gid = q.gid AND g.language = :lang1 AND q.language = :lang2 AND q.sid = :surveyid AND q.qid = qa.qid AND q.parent_qid = 0 AND qa.attribute = 'public_statistics'";
$databasetype = Yii::app()->db->getDriverName();
if ($databasetype=='mssql' || $databasetype=="sqlsrv")
if ($databasetype=='mssql' || $databasetype=="sqlsrv" || $databasetype=="dblib")
{
$query .=" AND CAST(CAST(qa.value as varchar) as int)='1'\n";
}
Expand Down Expand Up @@ -355,7 +355,7 @@ function actionAction($surveyid,$language)
}// end if -> for removing the error message in case there are no filters
$summary = $allfields;


// Get the survey inforamtion
$thissurvey = getSurveyInfo($surveyid,$language);

Expand All @@ -368,8 +368,8 @@ function actionAction($surveyid,$language)
{
$data['sTemplatePath'] = validateTemplateDir($thissurvey['templatedir']);
}


//---------- CREATE STATISTICS ----------
$redata = compact(array_keys(get_defined_vars()));
doHeader();
Expand Down

1 comment on commit 5852098

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to try sqlite ;)

Please sign in to comment.