Bugfixes and cleanup MS SQL Server installation

This commit is contained in:
Administrator 2013-02-10 13:07:59 +01:00
parent d577f790c8
commit 41ec976fd7
5 changed files with 148 additions and 87 deletions

View file

@ -5,7 +5,7 @@ $(document).ready(function() {
mysql:!!$('#hasMySQL').val(),
postgresql:!!$('#hasPostgreSQL').val(),
oracle:!!$('#hasOracle').val(),
mssql:!!$('#hasMSSQL').val()
mssql:!!$('#hasMSSQL').val()
};
$('#selectDbType').buttonset();
@ -43,7 +43,7 @@ $(document).ready(function() {
$('#dbhostlabel').show(250);
});
$('#mssql').click(function() {
$('#mssql').click(function() {
$('#use_other_db').slideDown(250);
$('#dbhost').show(250);
$('#dbhostlabel').show(250);

View file

@ -27,7 +27,7 @@ $opts = array(
'hasMySQL' => $hasMySQL,
'hasPostgreSQL' => $hasPostgreSQL,
'hasOracle' => $hasOracle,
'hasMSSQLServer' => $hasMSSQL,
'hasMSSQL' => $hasMSSQL,
'directory' => $datadir,
'secureRNG' => OC_Util::secureRNG_available(),
'htaccessWorking' => OC_Util::ishtaccessworking(),

View file

@ -107,7 +107,7 @@
<p>MS SQL <?php echo $l->t( 'will be used' ); ?>.</p>
<input type="hidden" id="dbtype" name="dbtype" value="mssql" />
<?php else: ?>
<label class="mssql" for="mssql">MS SQL</label>
<label class="mssql" for="mssql">MS SQL</label>
<input type="radio" name="dbtype" value='mssql' id="mssql" <?php OC_Helper::init_radio('dbtype', 'mssql', 'sqlite'); ?>/>
<?php endif; ?>
<?php endif; ?>

View file

@ -284,7 +284,7 @@ class OC_DB {
$dsn['database'] = $user;
}
break;
case 'mssql':
case 'mssql':
$dsn = array(
'phptype' => 'sqlsrv',
'username' => $user,
@ -292,7 +292,7 @@ class OC_DB {
'hostspec' => $host,
'database' => $name
);
break;
break;
default:
return false;
}
@ -920,28 +920,30 @@ class PDOStatementWrapper{
* make execute return the result instead of a bool
*/
public function execute($input=array()) {
$this->lastArguments=$input;
if(count($input)>0) {
if (!isset($type)) {
$type = OC_Config::getValue( "dbtype", "sqlite" );
}
$this->lastArguments = $input;
if (count($input) > 0) {
if ($type == 'mssql') {
$this->tryFixSubstringLastArgumentDataForMSSQL($input);
}
if (!isset($type)) {
$type = OC_Config::getValue( "dbtype", "sqlite" );
}
if ($type == 'mssql') {
$input = $this->tryFixSubstringLastArgumentDataForMSSQL($input);
}
$result=$this->statement->execute($input);
}else{
} else {
$result=$this->statement->execute();
}
if($result) {
if ($result) {
return $this;
}else{
} else {
return false;
}
}
private function tryFixSubstringLastArgumentDataForMSSQL(&$input) {
private function tryFixSubstringLastArgumentDataForMSSQL($input) {
$query = $this->statement->queryString;
$pos = stripos ($query, 'SUBSTRING');
@ -1013,6 +1015,8 @@ class PDOStatementWrapper{
$this->statement = $PDO->prepare($newQuery);
$this->lastArguments = $input;
return $input;
} catch (PDOException $e){
$entry = 'PDO DB Error: "'.$e->getMessage().'"<br />';
$entry .= 'Offending command was: '.$this->statement->queryString .'<br />';

View file

@ -610,46 +610,49 @@ class OC_Setup {
self::mssql_createDatabase($dbname, $masterConnection);
self::mssql_createDBUser($dbuser, $dbpass, $masterConnection);
self::mssql_createDBUser($dbuser, $dbname, $masterConnection);
sqlsrv_close($masterConnection);
$connectionInfo = array( "Database" => $dbname, "UID" => $dbuser, "PWD" => $dbpass);
$connection = @sqlsrv_connect($dbhost, $connectionInfo);
//fill the database if needed
$query="SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{$dbname}' AND TABLE_NAME = '{$dbtableprefix}users'";
$result = sqlsrv_query($connection, $query);
if($result) {
$row=sqlsrv_fetch_array($result);
}
if(!$result or $row[0] == 0) {
OC_DB::createDbFromStructure('db_structure.xml');
}
sqlsrv_close($connection);
self::mssql_createDatabaseStructure($dbname, $dbuser, $dbpass);
}
private static function mssql_createDBLogin($name, $password, $connection) {
$query = "SELECT * FROM master.sys.server_principals WHERE name = '".$name."';";
$result = sqlsrv_query($connection, $query);
if ($result) {
if ($result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
} else {
$row = sqlsrv_fetch_array($result);
}
if (!$result or $row[0] == 0) {
$query = "CREATE LOGIN [".$name."] WITH PASSWORD = '".$password."';";
$result = sqlsrv_query($connection, $query);
if (!$result or $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
if ($row === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
} else {
if ($row == null) {
$query = "CREATE LOGIN [".$name."] WITH PASSWORD = '".$password."';";
$result = sqlsrv_query($connection, $query);
if (!$result or $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
}
}
}
}
}
@ -657,51 +660,105 @@ class OC_Setup {
private static function mssql_createDBUser($name, $dbname, $connection) {
$query = "SELECT * FROM [".$dbname."].sys.database_principals WHERE name = '".$name."';";
$result = sqlsrv_query($connection, $query);
if($result) {
$row=sqlsrv_fetch_array($result);
}
if (!$result or $row[0] == 0) {
$query = "USE [".$dbname."]; CREATE USER [".$name."] FOR LOGIN [".$name."];";
$result = sqlsrv_query($connection, $query);
if (!$result or $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
if ($result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
} else {
$row = sqlsrv_fetch_array($result);
$query = "USE [".$dbname."]; EXEC sp_addrolemember 'db_owner', '".$name."';";
$result = sqlsrv_query($connection, $query);
if (!$result or $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
if ($row === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
} else {
if ($row == null) {
$query = "USE [".$dbname."]; CREATE USER [".$name."] FOR LOGIN [".$name."];";
$result = sqlsrv_query($connection, $query);
if (!$result || $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry = 'DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
}
}
$query = "USE [".$dbname."]; EXEC sp_addrolemember 'db_owner', '".$name."';";
$result = sqlsrv_query($connection, $query);
if (!$result || $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
}
}
}
}
private static function mssql_createDatabase($dbname, $connection) {
$query = "CREATE DATABASE [".$dbname."];";
$result = sqlsrv_query($connection, $query);
if (!$result or $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
if (!$result || $result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
}
}
private static function mssql_createDatabaseStructure($dbname, $dbuser, $dbpass) {
$connectionInfo = array( "Database" => $dbname, "UID" => $dbuser, "PWD" => $dbpass);
$connection = @sqlsrv_connect($dbhost, $connectionInfo);
//fill the database if needed
$query = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{$dbname}' AND TABLE_NAME = '{$dbtableprefix}users'";
$result = sqlsrv_query($connection, $query);
if ($result === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
} else {
$row = sqlsrv_fetch_array($result);
if ($row === false) {
if ( ($errors = sqlsrv_errors() ) != null) {
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
} else {
$entry = '';
}
$entry.='Offending command was: '.$query.'<br />';
echo($entry);
} else {
if ($row == null) {
OC_DB::createDbFromStructure('db_structure.xml');
}
}
}
sqlsrv_close($connection);
}
/**
* create .htaccess files for apache hosts