forked from yajra/laravel-oci8
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first draft shortcut function for procedure fetch all
- Loading branch information
mstaack
committed
Aug 24, 2016
1 parent
1617c9a
commit abdf6fd
Showing
2 changed files
with
51 additions
and
11 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ build | |
composer.lock | ||
docs | ||
vendor | ||
.idea |
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 |
---|---|---|
|
@@ -34,15 +34,15 @@ class Oci8Connection extends Connection | |
|
||
/** | ||
* @param PDO|\Closure $pdo | ||
* @param string $database | ||
* @param string $tablePrefix | ||
* @param array $config | ||
* @param string $database | ||
* @param string $tablePrefix | ||
* @param array $config | ||
*/ | ||
public function __construct($pdo, $database = '', $tablePrefix = '', array $config = []) | ||
{ | ||
parent::__construct($pdo, $database, $tablePrefix, $config); | ||
$this->sequence = new Sequence($this); | ||
$this->trigger = new Trigger($this); | ||
$this->trigger = new Trigger($this); | ||
} | ||
|
||
/** | ||
|
@@ -64,7 +64,7 @@ public function getSchema() | |
public function setSchema($schema) | ||
{ | ||
$this->schema = $schema; | ||
$sessionVars = [ | ||
$sessionVars = [ | ||
'CURRENT_SCHEMA' => $schema, | ||
]; | ||
|
||
|
@@ -212,17 +212,17 @@ protected function getDoctrineDriver() | |
* 'bye'], PDO::PARAM_LOB) | ||
* | ||
* @author Tylerian - [email protected] | ||
* @param string $sql (mixed) | ||
* @param array $bindings (kvp array) | ||
* @param int $returnType (PDO::PARAM_*) | ||
* @param string $sql (mixed) | ||
* @param array $bindings (kvp array) | ||
* @param int $returnType (PDO::PARAM_*) | ||
* @return mixed $returnType | ||
*/ | ||
public function executeFunction($sql, array $bindings = [], $returnType = PDO::PARAM_STR) | ||
{ | ||
$query = $this->getPdo()->prepare('begin :result := ' . $sql . '; end;'); | ||
|
||
foreach ($bindings as $key => &$value) { | ||
if (! preg_match('/^:(.*)$/i', $key)) { | ||
if (!preg_match('/^:(.*)$/i', $key)) { | ||
$key = ':' . $key; | ||
} | ||
|
||
|
@@ -235,11 +235,50 @@ public function executeFunction($sql, array $bindings = [], $returnType = PDO::P | |
return $result; | ||
} | ||
|
||
/** | ||
* Execute a PL/SQL Procedure and return its result. | ||
* Usage: DB::executeProcedure($procedureName, $bindings) | ||
* | ||
* $bindings looks like: | ||
* $bindings = [ | ||
* 'p_userid' => [ | ||
* 'value' => $id, | ||
* 'type' => PDO::PARAM_INT, | ||
* ], | ||
* | ||
* @param $procedureName | ||
* @param $bindings | ||
* @return array | ||
*/ | ||
private function executeProcedure($procedureName, $bindings) | ||
{ | ||
$pdo = DB::getPdo(); | ||
|
||
$command = sprintf('begin %s(:%s, :cursor); end;', $procedureName, implode(', :', array_keys($bindings))); | ||
|
||
$stmt = $pdo->prepare($command); | ||
|
||
foreach ($bindings as $bindingName => $bindingOption) { | ||
$stmt->bindParam(':' . $bindingName, $bindingOption['value'], $bindingOption['type']); | ||
} | ||
|
||
$cursor = null; | ||
|
||
$stmt->bindParam(':cursor', $cursor, PDO::PARAM_STMT); | ||
$stmt->execute(); | ||
|
||
oci_execute($cursor, OCI_DEFAULT); | ||
oci_fetch_all($cursor, $array, 0, -1, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC); | ||
oci_free_cursor($cursor); | ||
|
||
return $array; | ||
} | ||
|
||
/** | ||
* Bind values to their parameters in the given statement. | ||
* | ||
* @param \PDOStatement $statement | ||
* @param array $bindings | ||
* @param array $bindings | ||
* @return void | ||
*/ | ||
public function bindValues($statement, $bindings) | ||
|
@@ -248,7 +287,7 @@ public function bindValues($statement, $bindings) | |
$statement->bindParam( | ||
$key, | ||
$bindings[$key], | ||
! is_string($value) && is_numeric($value) ? PDO::PARAM_INT : PDO::PARAM_STR | ||
!is_string($value) && is_numeric($value) ? PDO::PARAM_INT : PDO::PARAM_STR | ||
); | ||
} | ||
} | ||
|