Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modified formatting to follow qcodo standards
- Loading branch information
1 parent
c0236d3
commit 7cd0d32
Showing
2 changed files
with
721 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,133 @@ | ||
<?php | ||
/** | ||
* PDO Generic database driver | ||
* @abstract | ||
* @author Marcos Sánchez [marcosdsanchez at thinkclear dot com dot ar] | ||
*/ | ||
abstract class QPdoDatabase extends QDatabaseBase { | ||
const Adapter = 'Generic PDO Adapter (Abstract)'; | ||
|
||
/** | ||
* @var PDO connection handler | ||
* @access protected | ||
*/ | ||
protected $objPdo; | ||
/** | ||
* @var PDOStatement most recent query result | ||
* @access protected | ||
*/ | ||
protected $objMostRecentResult; | ||
|
||
|
||
public function NonQuery($strNonQuery) { | ||
// Connect if Applicable | ||
if (!$this->blnConnectedFlag) $this->Connect(); | ||
|
||
// Log Query (for Profiling, if applicable) | ||
$this->LogQuery($strNonQuery); | ||
|
||
// Perform the Query | ||
$objResult = $this->objPdo->query($strNonQuery); | ||
if ($objResult === false) | ||
throw new QPdoDatabaseException($this->objPdo->errorInfo(), $this->objPdo->errorCode(), $strNonQuery); | ||
$this->objMostRecentResult = $objResult; | ||
} | ||
|
||
public function __get($strName) { | ||
switch ($strName) { | ||
case 'AffectedRows': | ||
return $this->objMostRecentResult->rowCount(); | ||
default: | ||
try { | ||
return parent::__get($strName); | ||
} catch (QCallerException $objExc) { | ||
$objExc->IncrementOffset(); | ||
throw $objExc; | ||
} | ||
} | ||
} | ||
|
||
public function Close() { | ||
$this->objPdo = null; | ||
} | ||
|
||
|
||
public function TransactionBegin() { | ||
$this->objPdo->beginTransaction(); | ||
} | ||
|
||
public function TransactionCommit() { | ||
$this->objPdo->commit(); | ||
} | ||
|
||
public function TransactionRollBack() { | ||
$this->objPdo->rollback(); | ||
} | ||
|
||
} | ||
/** | ||
* QPdoDatabaseResult | ||
* | ||
* @abstract | ||
*/ | ||
abstract class QPdoDatabaseResult extends QDatabaseResultBase { | ||
/** | ||
* @var PDOStatement Query result | ||
* @access protected | ||
*/ | ||
protected $objPdoResult; | ||
/** | ||
* @var PDO Connection object | ||
* @access protected | ||
*/ | ||
protected $objPdo; | ||
|
||
public function __construct($objResult, QPdoDatabase $objDb) { | ||
$this->objPdoResult = $objResult; | ||
$this->objPdo = $objDb; | ||
} | ||
|
||
public function FetchArray() { | ||
return $this->objPdoResult->fetch(); | ||
} | ||
|
||
public function FetchRow() { | ||
return $this->objPdoResult->fetch(PDO::FETCH_NUM); | ||
} | ||
|
||
public function CountRows() { | ||
return $this->objPdoResult->rowCount(); | ||
} | ||
|
||
public function CountFields() { | ||
return $this->objPdoResult->columnCount(); | ||
} | ||
|
||
public function Close() { | ||
$this->objPdoResult = null; | ||
} | ||
|
||
public function GetRows() { | ||
$objDbRowArray = array(); | ||
while ($objDbRow = $this->GetNextRow()) | ||
array_push($objDbRowArray, $objDbRow); | ||
return $objDbRowArray; | ||
} | ||
} | ||
/** | ||
* PdoDatabaseException | ||
*/ | ||
class QPdoDatabaseException extends QDatabaseExceptionBase { | ||
public function __construct($strMessage, $intNumber, $strQuery) { | ||
parent::__construct(sprintf("PDO %s", $strMessage[2]), 2); | ||
$this->intErrorNumber = $intNumber; | ||
$this->strQuery = $strQuery; | ||
} | ||
} | ||
|
||
/** | ||
* PDO Generic database driver | ||
* @abstract | ||
* @author Marcos Sánchez [marcosdsanchez at thinkclear dot com dot ar] | ||
*/ | ||
abstract class QPdoDatabase extends QDatabaseBase { | ||
const Adapter = 'Generic PDO Adapter (Abstract)'; | ||
|
||
/** | ||
* @var PDO connection handler | ||
* @access protected | ||
*/ | ||
protected $objPdo; | ||
/** | ||
* @var PDOStatement most recent query result | ||
* @access protected | ||
*/ | ||
protected $objMostRecentResult; | ||
|
||
|
||
public function NonQuery($strNonQuery) { | ||
// Connect if Applicable | ||
if (!$this->blnConnectedFlag) | ||
$this->Connect(); | ||
|
||
// Log Query (for Profiling, if applicable) | ||
$this->LogQuery($strNonQuery); | ||
|
||
// Perform the Query | ||
$objResult = $this->objPdo->query($strNonQuery); | ||
if ($objResult === false) | ||
throw new QPdoDatabaseException($this->objPdo->errorInfo(), $this->objPdo->errorCode(), $strNonQuery); | ||
$this->objMostRecentResult = $objResult; | ||
} | ||
|
||
public function __get($strName) { | ||
switch ($strName) { | ||
case 'AffectedRows': | ||
return $this->objMostRecentResult->rowCount(); | ||
default: | ||
try { | ||
return parent::__get($strName); | ||
} catch (QCallerException $objExc) { | ||
$objExc->IncrementOffset(); | ||
throw $objExc; | ||
} | ||
} | ||
} | ||
|
||
public function Close() { | ||
$this->objPdo = null; | ||
} | ||
|
||
public function TransactionBegin() { | ||
$this->objPdo->beginTransaction(); | ||
} | ||
|
||
public function TransactionCommit() { | ||
$this->objPdo->commit(); | ||
} | ||
|
||
public function TransactionRollBack() { | ||
$this->objPdo->rollback(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* QPdoDatabaseResult | ||
* | ||
* @abstract | ||
*/ | ||
abstract class QPdoDatabaseResult extends QDatabaseResultBase { | ||
|
||
/** | ||
* @var PDOStatement Query result | ||
* @access protected | ||
*/ | ||
protected $objPdoResult; | ||
/** | ||
* @var PDO Connection object | ||
* @access protected | ||
*/ | ||
protected $objPdo; | ||
|
||
public function __construct($objResult, QPdoDatabase $objDb) { | ||
$this->objPdoResult = $objResult; | ||
$this->objPdo = $objDb; | ||
} | ||
|
||
public function FetchArray() { | ||
return $this->objPdoResult->fetch(); | ||
} | ||
|
||
public function FetchRow() { | ||
return $this->objPdoResult->fetch(PDO::FETCH_NUM); | ||
} | ||
|
||
public function CountRows() { | ||
return $this->objPdoResult->rowCount(); | ||
} | ||
|
||
public function CountFields() { | ||
return $this->objPdoResult->columnCount(); | ||
} | ||
|
||
public function Close() { | ||
$this->objPdoResult = null; | ||
} | ||
|
||
public function GetRows() { | ||
$objDbRowArray = array(); | ||
while ($objDbRow = $this->GetNextRow()) | ||
array_push($objDbRowArray, $objDbRow); | ||
return $objDbRowArray; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* PdoDatabaseException | ||
*/ | ||
class QPdoDatabaseException extends QDatabaseExceptionBase { | ||
|
||
public function __construct($strMessage, $intNumber, $strQuery) { | ||
parent::__construct(sprintf("PDO %s", $strMessage[2]), 2); | ||
$this->intErrorNumber = $intNumber; | ||
$this->strQuery = $strQuery; | ||
} | ||
|
||
} | ||
?> |
Oops, something went wrong.