Bugfixes and cleanup MS SQL Server installation
This commit is contained in:
parent
d577f790c8
commit
41ec976fd7
5 changed files with 148 additions and 87 deletions
|
@ -5,7 +5,7 @@ $(document).ready(function() {
|
||||||
mysql:!!$('#hasMySQL').val(),
|
mysql:!!$('#hasMySQL').val(),
|
||||||
postgresql:!!$('#hasPostgreSQL').val(),
|
postgresql:!!$('#hasPostgreSQL').val(),
|
||||||
oracle:!!$('#hasOracle').val(),
|
oracle:!!$('#hasOracle').val(),
|
||||||
mssql:!!$('#hasMSSQL').val()
|
mssql:!!$('#hasMSSQL').val()
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#selectDbType').buttonset();
|
$('#selectDbType').buttonset();
|
||||||
|
@ -43,7 +43,7 @@ $(document).ready(function() {
|
||||||
$('#dbhostlabel').show(250);
|
$('#dbhostlabel').show(250);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#mssql').click(function() {
|
$('#mssql').click(function() {
|
||||||
$('#use_other_db').slideDown(250);
|
$('#use_other_db').slideDown(250);
|
||||||
$('#dbhost').show(250);
|
$('#dbhost').show(250);
|
||||||
$('#dbhostlabel').show(250);
|
$('#dbhostlabel').show(250);
|
||||||
|
|
|
@ -27,7 +27,7 @@ $opts = array(
|
||||||
'hasMySQL' => $hasMySQL,
|
'hasMySQL' => $hasMySQL,
|
||||||
'hasPostgreSQL' => $hasPostgreSQL,
|
'hasPostgreSQL' => $hasPostgreSQL,
|
||||||
'hasOracle' => $hasOracle,
|
'hasOracle' => $hasOracle,
|
||||||
'hasMSSQLServer' => $hasMSSQL,
|
'hasMSSQL' => $hasMSSQL,
|
||||||
'directory' => $datadir,
|
'directory' => $datadir,
|
||||||
'secureRNG' => OC_Util::secureRNG_available(),
|
'secureRNG' => OC_Util::secureRNG_available(),
|
||||||
'htaccessWorking' => OC_Util::ishtaccessworking(),
|
'htaccessWorking' => OC_Util::ishtaccessworking(),
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
<p>MS SQL <?php echo $l->t( 'will be used' ); ?>.</p>
|
<p>MS SQL <?php echo $l->t( 'will be used' ); ?>.</p>
|
||||||
<input type="hidden" id="dbtype" name="dbtype" value="mssql" />
|
<input type="hidden" id="dbtype" name="dbtype" value="mssql" />
|
||||||
<?php else: ?>
|
<?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'); ?>/>
|
<input type="radio" name="dbtype" value='mssql' id="mssql" <?php OC_Helper::init_radio('dbtype', 'mssql', 'sqlite'); ?>/>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
36
lib/db.php
36
lib/db.php
|
@ -284,7 +284,7 @@ class OC_DB {
|
||||||
$dsn['database'] = $user;
|
$dsn['database'] = $user;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'mssql':
|
case 'mssql':
|
||||||
$dsn = array(
|
$dsn = array(
|
||||||
'phptype' => 'sqlsrv',
|
'phptype' => 'sqlsrv',
|
||||||
'username' => $user,
|
'username' => $user,
|
||||||
|
@ -292,7 +292,7 @@ class OC_DB {
|
||||||
'hostspec' => $host,
|
'hostspec' => $host,
|
||||||
'database' => $name
|
'database' => $name
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -920,28 +920,30 @@ class PDOStatementWrapper{
|
||||||
* make execute return the result instead of a bool
|
* make execute return the result instead of a bool
|
||||||
*/
|
*/
|
||||||
public function execute($input=array()) {
|
public function execute($input=array()) {
|
||||||
$this->lastArguments=$input;
|
$this->lastArguments = $input;
|
||||||
if(count($input)>0) {
|
if (count($input) > 0) {
|
||||||
if (!isset($type)) {
|
|
||||||
$type = OC_Config::getValue( "dbtype", "sqlite" );
|
if (!isset($type)) {
|
||||||
}
|
$type = OC_Config::getValue( "dbtype", "sqlite" );
|
||||||
|
}
|
||||||
if ($type == 'mssql') {
|
|
||||||
$this->tryFixSubstringLastArgumentDataForMSSQL($input);
|
if ($type == 'mssql') {
|
||||||
}
|
$input = $this->tryFixSubstringLastArgumentDataForMSSQL($input);
|
||||||
|
}
|
||||||
|
|
||||||
$result=$this->statement->execute($input);
|
$result=$this->statement->execute($input);
|
||||||
}else{
|
} else {
|
||||||
$result=$this->statement->execute();
|
$result=$this->statement->execute();
|
||||||
}
|
}
|
||||||
if($result) {
|
|
||||||
|
if ($result) {
|
||||||
return $this;
|
return $this;
|
||||||
}else{
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function tryFixSubstringLastArgumentDataForMSSQL(&$input) {
|
private function tryFixSubstringLastArgumentDataForMSSQL($input) {
|
||||||
$query = $this->statement->queryString;
|
$query = $this->statement->queryString;
|
||||||
$pos = stripos ($query, 'SUBSTRING');
|
$pos = stripos ($query, 'SUBSTRING');
|
||||||
|
|
||||||
|
@ -1013,6 +1015,8 @@ class PDOStatementWrapper{
|
||||||
$this->statement = $PDO->prepare($newQuery);
|
$this->statement = $PDO->prepare($newQuery);
|
||||||
|
|
||||||
$this->lastArguments = $input;
|
$this->lastArguments = $input;
|
||||||
|
|
||||||
|
return $input;
|
||||||
} catch (PDOException $e){
|
} catch (PDOException $e){
|
||||||
$entry = 'PDO DB Error: "'.$e->getMessage().'"<br />';
|
$entry = 'PDO DB Error: "'.$e->getMessage().'"<br />';
|
||||||
$entry .= 'Offending command was: '.$this->statement->queryString .'<br />';
|
$entry .= 'Offending command was: '.$this->statement->queryString .'<br />';
|
||||||
|
|
191
lib/setup.php
191
lib/setup.php
|
@ -610,98 +610,155 @@ class OC_Setup {
|
||||||
|
|
||||||
self::mssql_createDatabase($dbname, $masterConnection);
|
self::mssql_createDatabase($dbname, $masterConnection);
|
||||||
|
|
||||||
self::mssql_createDBUser($dbuser, $dbpass, $masterConnection);
|
self::mssql_createDBUser($dbuser, $dbname, $masterConnection);
|
||||||
|
|
||||||
sqlsrv_close($masterConnection);
|
sqlsrv_close($masterConnection);
|
||||||
|
|
||||||
$connectionInfo = array( "Database" => $dbname, "UID" => $dbuser, "PWD" => $dbpass);
|
self::mssql_createDatabaseStructure($dbname, $dbuser, $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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function mssql_createDBLogin($name, $password, $connection) {
|
private static function mssql_createDBLogin($name, $password, $connection) {
|
||||||
$query = "SELECT * FROM master.sys.server_principals WHERE name = '".$name."';";
|
$query = "SELECT * FROM master.sys.server_principals WHERE name = '".$name."';";
|
||||||
$result = sqlsrv_query($connection, $query);
|
$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);
|
$row = sqlsrv_fetch_array($result);
|
||||||
}
|
|
||||||
|
|
||||||
if (!$result or $row[0] == 0) {
|
if ($row === false) {
|
||||||
$query = "CREATE LOGIN [".$name."] WITH PASSWORD = '".$password."';";
|
if ( ($errors = sqlsrv_errors() ) != null) {
|
||||||
$result = sqlsrv_query($connection, $query);
|
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
|
||||||
if (!$result or $result === false) {
|
} else {
|
||||||
if ( ($errors = sqlsrv_errors() ) != null) {
|
$entry = '';
|
||||||
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
|
}
|
||||||
} else {
|
$entry.='Offending command was: '.$query.'<br />';
|
||||||
$entry = '';
|
echo($entry);
|
||||||
}
|
} else {
|
||||||
$entry.='Offending command was: '.$query.'<br />';
|
if ($row == null) {
|
||||||
echo($entry);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function mssql_createDBUser($name, $dbname, $connection) {
|
private static function mssql_createDBUser($name, $dbname, $connection) {
|
||||||
$query = "SELECT * FROM [".$dbname."].sys.database_principals WHERE name = '".$name."';";
|
$query = "SELECT * FROM [".$dbname."].sys.database_principals WHERE name = '".$name."';";
|
||||||
$result = sqlsrv_query($connection, $query);
|
$result = sqlsrv_query($connection, $query);
|
||||||
if($result) {
|
if ($result === false) {
|
||||||
$row=sqlsrv_fetch_array($result);
|
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) {
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function mssql_createDatabase($dbname, $connection) {
|
private static function mssql_createDatabase($dbname, $connection) {
|
||||||
$query = "CREATE DATABASE [".$dbname."];";
|
$query = "CREATE DATABASE [".$dbname."];";
|
||||||
$result = sqlsrv_query($connection, $query);
|
$result = sqlsrv_query($connection, $query);
|
||||||
if (!$result or $result === false) {
|
if (!$result || $result === false) {
|
||||||
if ( ($errors = sqlsrv_errors() ) != null) {
|
if ( ($errors = sqlsrv_errors() ) != null) {
|
||||||
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
|
$entry='DB Error: "'.print_r(sqlsrv_errors()).'"<br />';
|
||||||
} else {
|
} else {
|
||||||
$entry = '';
|
$entry = '';
|
||||||
}
|
}
|
||||||
$entry.='Offending command was: '.$query.'<br />';
|
$entry.='Offending command was: '.$query.'<br />';
|
||||||
echo($entry);
|
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
|
* create .htaccess files for apache hosts
|
||||||
|
|
Loading…
Reference in a new issue