summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/js/setup.js4
-rw-r--r--core/setup.php2
-rw-r--r--core/templates/installation.php2
-rw-r--r--lib/db.php36
-rw-r--r--lib/setup.php191
5 files changed, 148 insertions, 87 deletions
diff --git a/core/js/setup.js b/core/js/setup.js
index fb6e7c5097c..cb8392d0a39 100644
--- a/core/js/setup.js
+++ b/core/js/setup.js
@@ -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);
diff --git a/core/setup.php b/core/setup.php
index 0da9b35a35a..6ea16cdcc4e 100644
--- a/core/setup.php
+++ b/core/setup.php
@@ -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(),
diff --git a/core/templates/installation.php b/core/templates/installation.php
index 6a6370785d3..4a41527c906 100644
--- a/core/templates/installation.php
+++ b/core/templates/installation.php
@@ -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; ?>
diff --git a/lib/db.php b/lib/db.php
index 58f46c1171f..c3ff481e19e 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -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" );
- }
-
- if ($type == 'mssql') {
- $this->tryFixSubstringLastArgumentDataForMSSQL($input);
- }
-
+ $this->lastArguments = $input;
+ if (count($input) > 0) {
+
+ 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 />';
diff --git a/lib/setup.php b/lib/setup.php
index d4ea26354ef..3efad79cfad 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -610,98 +610,155 @@ 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);
+ }
+ }
+ }
}
}
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 === 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) {
+ $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) {
$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