Skip to content

Commit

Permalink
drivers: getResource() and getResultResource() checks if resource is …
Browse files Browse the repository at this point in the history
…alive
  • Loading branch information
dg committed Jan 19, 2012
1 parent c7b9a91 commit 660a9db
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions dibi/drivers/firebird.php
Expand Up @@ -235,7 +235,7 @@ public function inTransaction()
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -359,7 +359,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -431,7 +431,7 @@ public function free()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}


Expand Down
6 changes: 3 additions & 3 deletions dibi/drivers/mssql.php
Expand Up @@ -177,7 +177,7 @@ public function rollback($savepoint = NULL)
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -307,7 +307,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -387,7 +387,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}


Expand Down
6 changes: 3 additions & 3 deletions dibi/drivers/mssql2005.php
Expand Up @@ -184,7 +184,7 @@ public function rollback($savepoint = NULL)
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -314,7 +314,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -393,7 +393,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}

}
6 changes: 3 additions & 3 deletions dibi/drivers/mysql.php
Expand Up @@ -255,7 +255,7 @@ public function rollback($savepoint = NULL)
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -384,7 +384,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -473,7 +473,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}

}
6 changes: 3 additions & 3 deletions dibi/drivers/mysqli.php
Expand Up @@ -252,7 +252,7 @@ public function rollback($savepoint = NULL)
*/
public function getResource()
{
return $this->connection;
return @$this->connection->thread_id ? $this->connection : NULL;
}


Expand Down Expand Up @@ -380,7 +380,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -479,7 +479,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return @$this->resultSet->type === NULL ? NULL : $this->resultSet;
}

}
6 changes: 3 additions & 3 deletions dibi/drivers/odbc.php
Expand Up @@ -200,7 +200,7 @@ public function inTransaction()
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -327,7 +327,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -417,7 +417,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}


Expand Down
6 changes: 3 additions & 3 deletions dibi/drivers/oracle.php
Expand Up @@ -191,7 +191,7 @@ public function rollback($savepoint = NULL)
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -321,7 +321,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -400,7 +400,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}


Expand Down
6 changes: 3 additions & 3 deletions dibi/drivers/postgre.php
Expand Up @@ -231,7 +231,7 @@ public function inTransaction()
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -374,7 +374,7 @@ public function applyLimit(&$sql, $limit, $offset)
*/
public function __destruct()
{
$this->resultSet && @$this->free();
$this->getResultResource() && $this->free();
}


Expand Down Expand Up @@ -455,7 +455,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}


Expand Down
4 changes: 2 additions & 2 deletions dibi/drivers/sqlite.php
Expand Up @@ -202,7 +202,7 @@ public function rollback($savepoint = NULL)
*/
public function getResource()
{
return $this->connection;
return is_resource($this->connection) ? $this->connection : NULL;
}


Expand Down Expand Up @@ -412,7 +412,7 @@ public function getResultColumns()
*/
public function getResultResource()
{
return $this->resultSet;
return is_resource($this->resultSet) ? $this->resultSet : NULL;
}


Expand Down
2 changes: 1 addition & 1 deletion dibi/libs/DibiConnection.php
Expand Up @@ -144,7 +144,7 @@ public function __construct($config, $name = NULL)
public function __destruct()
{
// disconnects and rolls back transaction - do not rely on auto-disconnect and rollback!
$this->connected && $this->disconnect();
$this->connected && $this->driver->getResource() && $this->disconnect();
}


Expand Down
4 changes: 3 additions & 1 deletion examples/using-profiler.php
Expand Up @@ -13,7 +13,9 @@
dibi::connect(array(
'driver' => 'sqlite',
'database' => 'data/sample.sdb',
'profiler' => TRUE,
'profiler' => array(
'run' => TRUE,
)
));


Expand Down

0 comments on commit 660a9db

Please sign in to comment.