30define(
'CAS_PGT_STORAGE_DB_DEFAULT_TABLE',
'cas_pgts');
115 return 'table=`' . $this->
_getTable() .
'\'';
144 $driver_options =
null
148 parent::__construct($cas_parent);
154 if (!is_array($driver_options)) {
155 $driver_options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
159 if ($dsn_or_pdo instanceof PDO) {
160 $this->_pdo = $dsn_or_pdo;
162 $this->_dsn = $dsn_or_pdo;
163 $this->_username = $username;
165 $this->_driver_options = $driver_options;
195 if (!($this->_pdo instanceof PDO)) {
197 $this->_pdo =
new PDO(
201 $this->_driver_options
203 }
catch (PDOException $e) {
204 phpCAS::error(
'Database connection error: ' . $e->getMessage());
230 $this->_errMode =
$pdo->getAttribute(PDO::ATTR_ERRMODE);
231 $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
243 $pdo->setAttribute(PDO::ATTR_ERRMODE, $this->_errMode);
260 return 'CREATE TABLE ' . $this->
_getTable()
261 .
' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)';
272 return 'INSERT INTO ' . $this->
_getTable()
273 .
' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)';
285 return 'SELECT pgt FROM ' . $this->
_getTable() .
' WHERE pgt_iou = :pgt_iou';
296 return 'DELETE FROM ' . $this->
_getTable() .
' WHERE pgt_iou = :pgt_iou';
322 $pdo->beginTransaction();
324 $query =
$pdo->query($this->createTableSQL());
328 }
catch (PDOException $e) {
332 }
catch (PDOException $e) {
334 phpCAS::error(
'error creating PGT storage table: ' . $e->getMessage());
352 public function write($pgt, $pgt_iou)
361 $pdo->beginTransaction();
364 $query->bindValue(
':pgt', $pgt, PDO::PARAM_STR);
365 $query->bindValue(
':pgt_iou', $pgt_iou, PDO::PARAM_STR);
370 }
catch (PDOException $e) {
374 }
catch (PDOException $e) {
376 phpCAS::error(
'error writing PGT to database: ' . $e->getMessage());
403 $pdo->beginTransaction();
407 $query->bindValue(
':pgt_iou', $pgt_iou, PDO::PARAM_STR);
409 $pgt =
$query->fetchColumn(0);
414 $query->bindValue(
':pgt_iou', $pgt_iou, PDO::PARAM_STR);
419 }
catch (PDOException $e) {
423 }
catch (PDOException $e) {
425 phpCAS::trace(
'error reading PGT from database: ' . $e->getMessage());
const CAS_PGT_STORAGE_DB_DEFAULT_TABLE
while(count($oldTaskList) > 0) foreach(array_keys( $newTaskList) as $task) init()
An exception for terminatinating execution or to throw for unit testing.
Basic class for PGT storage The CAS_PGTStorage_AbstractStorage class is a generic class for PGT stora...
Basic class for PGT database storage The CAS_PGTStorage_Db class is a class for PGT database storage.
$_table
the table to use for storing/retrieving pgt's
read($pgt_iou)
This method reads a PGT corresponding to a PGT Iou and deletes the corresponding db entry.
_resetErrorMode()
this method will reset the error mode on the PDO object
$_errMode
attribute that stores the previous error mode for the PDO handle while processing a transaction
_getPdo()
This method returns the PDO object to use for database interactions.
getStorageType()
This method returns an informational string giving the type of storage used by the object (used for d...
write($pgt, $pgt_iou)
This method stores a PGT and its corresponding PGT Iou in the database.
createTableSql()
This method returns the query used to create a pgt storage table.
_getTable()
This method returns the table to use when storing/retrieving PGT's.
init()
This method is used to initialize the storage.
getStorageInfo()
This method returns an informational string giving informations on the parameters of the storage.
storePgtSql()
This method returns the query used to store a pgt.
$_pdo
the PDO object to use for database interactions
createTable()
This method creates the database table used to store pgt's and pgtiou's.
_setErrorMode()
This method will enable the Exception error mode on the PDO object.
retrievePgtSql()
This method returns the query used to retrieve a pgt.
__construct( $cas_parent, $dsn_or_pdo, $username='', $password='', $table='', $driver_options=null)
The class constructor.
$_dsn
database connection options to use when creating a new PDO object
deletePgtSql()
This method returns the query used to delete a pgt.
isInitialized()
This method tells if the storage has already been intialized.
static trace($str)
This method is used to log something in debug mode.
static traceEnd($res='')
This method is used to indicate the end of the execution of a function in debug mode.
static traceBegin()
This method is used to indicate the start of the execution of a function in debug mode.
static error($msg)
This method is used by interface methods to print an error and where the function was originally call...
if(empty($password)) $table