Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
New: PDODB module ported to new module format
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartherbert committed Mar 8, 2016
1 parent 7176134 commit b2761e8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 20 deletions.
71 changes: 71 additions & 0 deletions src/php/Storyplayer/SPv2/Modules/PDODB.php
@@ -0,0 +1,71 @@
<?php

/**
* Copyright (c) 2011-present Mediasift Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the names of the copyright holders nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Libraries
* @package Storyplayer/Modules/PDODB
* @author Stuart Herbert <stuart.herbert@datasift.com>
* @copyright 2011-present Mediasift Ltd www.datasift.com
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://datasift.github.io/storyplayer
*/

namespace Storyplayer\SPv2\Modules;

use DataSift\Storyplayer\PlayerLib\StoryTeller;
use Storyplayer\SPv2\Modules\PDODB\FromPDOStatement;
use Storyplayer\SPv2\Modules\PDODB\UsingPDO;
use Storyplayer\SPv2\Modules\PDODB\UsingPDODB;

/**
* support for connecting to, and working with, any database supported by
* PHP's PDO extension
*/
class PDODB
{
public static function fromPDOStatement()
{
return new FromPDOStatement();
}

public static function usingPDO()
{
return new UsingPDO();
}

public static function usingPDODB()
{
return new UsingPDODB();
}
}
Expand Up @@ -34,27 +34,30 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Libraries
* @package Storyplayer/Prose
* @package Storyplayer/Modules/PDODB
* @author Stuart Herbert <stuart.herbert@datasift.com>
* @copyright 2011-present Mediasift Ltd www.datasift.com
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://datasift.github.io/storyplayer
*/

namespace Prose;
namespace Storyplayer\SPv2\Modules\PDODB;

use Exception;
use PDO;
use PDOException;
use PDOStatement;

use Storyplayer\SPv2\Modules\Exceptions;
use Storyplayer\SPv2\Modules\Log;

/**
* work with the results of running a PDO query
*
* great for managing test data
*
* @category Libraries
* @package Storyplayer/Prose
* @package Storyplayer/Modules/PDODB
* @author Stuart Herbert <stuart.herbert@datasift.com>
* @copyright 2011-present Mediasift Ltd www.datasift.com
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
Expand All @@ -79,7 +82,7 @@ public function __construct($st, $args)
public function fetchAll()
{
// what are we doing?
$log = usingLog()->startAction("fetch all rows from the PDO query result");
$log = Log::usingLog()->startAction("fetch all rows from the PDO query result");

try
{
Expand All @@ -99,7 +102,7 @@ public function fetchAll()
public function fetchAssoc()
{
// what are we doing?
$log = usingLog()->startAction("fetch 1 row from the PDO query result");
$log = Log::usingLog()->startAction("fetch 1 row from the PDO query result");

try
{
Expand All @@ -119,7 +122,7 @@ public function fetchAssoc()
public function fetchNum()
{
// what are we doing?
$log = usingLog()->startAction("fetch 1 row from the PDO query result");
$log = Log::usingLog()->startAction("fetch 1 row from the PDO query result");

try
{
Expand All @@ -139,7 +142,7 @@ public function fetchNum()
public function fetchObj()
{
// what are we doing?
$log = usingLog()->startAction("fetch 1 row from the PDO query result");
$log = Log::usingLog()->startAction("fetch 1 row from the PDO query result");

try
{
Expand All @@ -159,7 +162,7 @@ public function fetchObj()
public function getRowCount()
{
// what are we doing?
$log = usingLog()->startAction("how many rows were affected by the last SQL query?");
$log = Log::usingLog()->startAction("how many rows were affected by the last SQL query?");

// get the answer
$rowCount = $this->args[0]->rowCount();
Expand All @@ -168,4 +171,4 @@ public function getRowCount()
$log->endAction($rowCount);
return $rowCount;
}
}
}
Expand Up @@ -34,17 +34,20 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Libraries
* @package Storyplayer/Prose
* @package Storyplayer/Modules/PDODB
* @author Stuart Herbert <stuart.herbert@datasift.com>
* @copyright 2011-present Mediasift Ltd www.datasift.com
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://datasift.github.io/storyplayer
*/

namespace Prose;
namespace Storyplayer\SPv2\Modules\PDODB;
use PDO;
use PDOException;

use Storyplayer\SPv2\Modules\Execeptions;
use Storyplayer\SPv2\Modules\Log;

/**
* connect to a database using PDO
*
Expand All @@ -62,7 +65,7 @@ class UsingPDO extends Prose
public function connect($dsn, $username = null, $password = null, $options = [])
{
// what are we doing?
$log = usingLog()->startAction("connect to database '{$dsn}'");
$log = Log::usingLog()->startAction("connect to database '{$dsn}'");

// make the connection
try {
Expand Down
Expand Up @@ -34,20 +34,23 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Libraries
* @package Storyplayer/Prose
* @package Storyplayer/Modules/PDODB
* @author Stuart Herbert <stuart.herbert@datasift.com>
* @copyright 2011-present Mediasift Ltd www.datasift.com
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://datasift.github.io/storyplayer
*/

namespace Prose;
namespace Storyplayer\SPv2\Modules\PDODB;

use Exception;
use PDO;
use PDOException;
use PDOStatement;

use Storyplayer\SPv2\Modules\Exceptions;
use Storyplayer\SPv2\Modules\Log;

/**
* work with a PDO database connection
*
Expand Down Expand Up @@ -79,7 +82,7 @@ public function __construct($st, $args)
public function query($sql, $params = [], $driverParams = [])
{
// what are we doing?
$log = usingLog()->startAction(["run SQL query:", $sql, "/ with params:", $params, "and driver params:", $driverParams]);
$log = Log::usingLog()->startAction(["run SQL query:", $sql, "/ with params:", $params, "and driver params:", $driverParams]);

try
{
Expand All @@ -104,7 +107,7 @@ public function query($sql, $params = [], $driverParams = [])
public function rawQuery($sql, $driverParams = [])
{
// what are we doing?
$log = usingLog()->startAction(["run raw SQL query:", $sql, "with driver params: ", $driverParams]);
$log = Log::usingLog()->startAction(["run raw SQL query:", $sql, "with driver params: ", $driverParams]);

try
{
Expand All @@ -127,7 +130,7 @@ public function rawQuery($sql, $driverParams = [])
public function beginTransaction()
{
// what are we doing?
$log = usingLog()->startAction("begin PDO database transaction");
$log = Log::usingLog()->startAction("begin PDO database transaction");

try
{
Expand All @@ -145,7 +148,7 @@ public function beginTransaction()
public function commitTransaction()
{
// what are we doing?
$log = usingLog()->startAction("commit PDO database transaction");
$log = Log::usingLog()->startAction("commit PDO database transaction");

try
{
Expand All @@ -163,7 +166,7 @@ public function commitTransaction()
public function rollbackTransaction()
{
// what are we doing?
$log = usingLog()->startAction("rollback PDO database transaction");
$log = Log::usingLog()->startAction("rollback PDO database transaction");

try
{
Expand All @@ -178,4 +181,4 @@ public function rollbackTransaction()
}
}

}
}

0 comments on commit b2761e8

Please sign in to comment.