This commit is contained in:
Roly Rudy Gutierrez Pinto
2018-12-20 16:45:51 -04:00
parent 8a854f7657
commit 3d8e15bb00
4 changed files with 77 additions and 65 deletions

View File

@@ -191,16 +191,18 @@ class MSSQLConnection extends ConnectionCommon implements Connection
{
$this->lastQuery = $sql;
if (extension_loaded('sqlsrv')) {
$result = sqlsrv_query($this->dblink, $sql);
$result = @sqlsrv_query($this->dblink, $sql);
if (!$result) {
throw new SQLException('Could not execute query', print_r(sqlsrv_errors(), true));
}
} else {
if (!@mssql_select_db($this->database, $this->dblink)) {
throw new SQLException('No database selected');
}
$result = @mssql_query($sql, $this->dblink);
}
if (!$result) {
throw new SQLException('Could not execute query', mssql_get_last_message());
if (!$result) {
throw new SQLException('Could not execute query', mssql_get_last_message());
}
}
return new MSSQLResultSet($this, $result, $fetchmode);
}
@@ -210,23 +212,23 @@ class MSSQLConnection extends ConnectionCommon implements Connection
*/
function executeUpdate($sql)
{
$this->lastQuery = $sql;
if (extension_loaded('sqlsrv')) {
$result = sqlsrv_query($this->dblink, $sql);
$result = @sqlsrv_query($this->dblink, $sql);
if (!$result) {
throw new SQLException('Could not execute update', print_r(sqlsrv_errors(), true), $sql);
}
return (int) sqlsrv_rows_affected($this->dblink);
} else {
$this->lastQuery = $sql;
if (!mssql_select_db($this->database, $this->dblink)) {
throw new SQLException('No database selected');
}
$result = @mssql_query($sql, $this->dblink);
if (!$result) {
throw new SQLException('Could not execute update', mssql_get_last_message(), $sql);
}
return (int) mssql_rows_affected($this->dblink);
}
if (!$result) {
throw new SQLException('Could not execute update', mssql_get_last_message(), $sql);
}
return (int) mssql_rows_affected($this->dblink);
// return $this->getUpdateCount();
}
/**
@@ -237,12 +239,15 @@ class MSSQLConnection extends ConnectionCommon implements Connection
protected function beginTrans()
{
if (extension_loaded('sqlsrv')) {
$result = sqlsrv_begin_transaction($this->dblink);
$result = @sqlsrv_begin_transaction($this->dblink);
if (!$result) {
throw new SQLException('Could not begin transaction', print_r(sqlsrv_errors(), true));
}
} else {
$result = @mssql_query('BEGIN TRAN', $this->dblink);
}
if (!$result) {
throw new SQLException('Could not begin transaction', mssql_get_last_message());
if (!$result) {
throw new SQLException('Could not begin transaction', mssql_get_last_message());
}
}
}
@@ -254,15 +259,18 @@ class MSSQLConnection extends ConnectionCommon implements Connection
protected function commitTrans()
{
if (extension_loaded('sqlsrv')) {
$result = sqlsrv_commit($this->dblink);
$result = @sqlsrv_commit($this->dblink);
if (!$result) {
throw new SQLException('Could not commit transaction', print_r(sqlsrv_errors(), true));
}
} else {
if (!@mssql_select_db($this->database, $this->dblink)) {
throw new SQLException('No database selected');
}
$result = @mssql_query('COMMIT TRAN', $this->dblink);
}
if (!$result) {
throw new SQLException('Could not commit transaction', mssql_get_last_message());
if (!$result) {
throw new SQLException('Could not commit transaction', mssql_get_last_message());
}
}
}
@@ -274,15 +282,18 @@ class MSSQLConnection extends ConnectionCommon implements Connection
protected function rollbackTrans()
{
if (extension_loaded('sqlsrv')) {
$result = sqlsrv_rollback($this->dblink);
$result = @sqlsrv_rollback($this->dblink);
if (!$result) {
throw new SQLException('Could not rollback transaction', print_r(sqlsrv_errors(), true));
}
} else {
if (!@mssql_select_db($this->database, $this->dblink)) {
throw new SQLException('no database selected');
}
$result = @mssql_query('ROLLBACK TRAN', $this->dblink);
}
if (!$result) {
throw new SQLException('Could not rollback transaction', mssql_get_last_message());
if (!$result) {
throw new SQLException('Could not rollback transaction', mssql_get_last_message());
}
}
}

View File

@@ -154,12 +154,14 @@ class MSSQLResultSet extends ResultSetCommon implements ResultSet
{
if (extension_loaded('sqlsrv')) {
$rows = @sqlsrv_num_rows($this->result);
if ($rows === null) {
throw new SQLException('Error getting record count', print_r(sqlsrv_errors(), true));
}
} else {
$rows = @mssql_num_rows($this->result);
}
if ($rows === null) {
throw new SQLException('Error getting record count', mssql_get_last_message());
if ($rows === null) {
throw new SQLException('Error getting record count', mssql_get_last_message());
}
}
// adjust count based on emulated LIMIT/OFFSET
$rows -= $this->offset;

View File

@@ -38,28 +38,27 @@ class MSSQLDatabaseInfo extends DatabaseInfo
protected function initTables()
{
include_once 'creole/drivers/mssql/metadata/MSSQLTableInfo.php';
$dsn = $this->conn->getDSN();
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'";
if (extension_loaded('sqlsrv')) {
$result = sqlsrv_query(
"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'",
$this->conn->getResource()
);
$result = sqlsrv_query($sql, $this->conn->getResource());
if (!$result) {
throw new SQLException("Could not list tables", print_r(sqlsrv_errors(), true));
}
while ($row = sqlsrv_fetch_array($result)) {
$this->tables[strtoupper($row[0])] = new MSSQLTableInfo($this, $row[0]);
}
} else {
if (!@mssql_select_db($this->dbname, $this->conn->getResource())) {
throw new SQLException('No database selected');
}
$result = mssql_query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME <> 'dtproperties'", $this->conn->getResource());
}
if (!$result) {
throw new SQLException("Could not list tables", mssql_get_last_message());
}
while ($row = mssql_fetch_row($result)) {
$this->tables[strtoupper($row[0])] = new MSSQLTableInfo($this, $row[0]);
$result = mssql_query($sql, $this->conn->getResource());
if (!$result) {
throw new SQLException("Could not list tables", mssql_get_last_message());
}
while ($row = mssql_fetch_row($result)) {
$this->tables[strtoupper($row[0])] = new MSSQLTableInfo($this, $row[0]);
}
}
}

View File

@@ -253,14 +253,7 @@ class Net
break;
case 'mssql':
//todo
if (!extension_loaded('sqlsrv')) {
if ($this->db_instance != "") {
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
}
} else {
if (extension_loaded('sqlsrv')) {
if ($this->db_instance != "") {
$server = $this->ip . "\\" . $this->db_instance;
} else {
@@ -274,6 +267,13 @@ class Net
'Database' => $this->db_sourcename
];
$link = @sqlsrv_connect($server, $opt);
} else {
if ($this->db_instance != "") {
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
}
}
if ($link) {
@@ -397,14 +397,7 @@ class Net
}
break;
case 'mssql':
if (!extension_loaded('sqlsrv')) {
if ($this->db_instance != "") {
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
}
} else {
if (extension_loaded('sqlsrv')) {
if ($this->db_instance != "") {
$server = $this->ip . "\\" . $this->db_instance;
} else {
@@ -418,6 +411,13 @@ class Net
'Database' => $this->db_sourcename
];
$link = $db = @sqlsrv_connect($server, $opt);
} else {
if ($this->db_instance != "") {
$link = @mssql_connect($this->ip . "\\" . $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":" . $this->db_port;
$link = @mssql_connect($this->ip . $port, $this->db_user, $this->db_passwd);
}
}
if ($link) {
if (!extension_loaded('sqlsrv')) {