BUG 9087 Procedimientos Almacenado que empiezan con BEGIN ...SOLVED
- Procedimientos Almacenado no funcionan con executeQuery en Triggers. - Several Adjustments for execution the Queries, CRUDs, Stored Procedures and User Defined Functions in Oracle.
This commit is contained in:
@@ -254,43 +254,46 @@ function pauseCase($sApplicationUID = '', $iDelegation = 0, $sUserUID = '', $sUn
|
|||||||
* @return array or string | $Resultquery | Result | Result of the query | If executing a SELECT statement, it returns an array of associative arrays
|
* @return array or string | $Resultquery | Result | Result of the query | If executing a SELECT statement, it returns an array of associative arrays
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function executeQuery($SqlStatement, $DBConnectionUID = 'workflow') {
|
function executeQuery($SqlStatement, $DBConnectionUID = 'workflow', $aParameter = array()) {
|
||||||
|
$con = Propel::getConnection($DBConnectionUID);
|
||||||
|
$con->begin();
|
||||||
try {
|
try {
|
||||||
$statement = trim($SqlStatement);
|
$statement = trim($SqlStatement);
|
||||||
$statement = str_replace('(', '', $statement);
|
$statement = str_replace('(', '', $statement);
|
||||||
$con = Propel::getConnection($DBConnectionUID);
|
|
||||||
$con->begin();
|
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
|
if (getEngineDataBaseName($con) != 'oracle' ) {
|
||||||
|
switch(true) {
|
||||||
|
case preg_match("/^(SELECT|EXECUTE|EXEC|SHOW|DESCRIBE|EXPLAIN|BEGIN)\s/i", $statement):
|
||||||
|
$rs = $con->executeQuery($SqlStatement);
|
||||||
|
$con->commit();
|
||||||
|
|
||||||
switch(true) {
|
$result = Array();
|
||||||
case preg_match("/^SELECT\s/i", $statement):
|
$i = 1;
|
||||||
case preg_match("/^EXECUTE\s/i", $statement):
|
while ($rs->next()) {
|
||||||
$rs = $con->executeQuery($SqlStatement);
|
$result[$i++] = $rs->getRow();
|
||||||
$con->commit();
|
}
|
||||||
|
break;
|
||||||
$result = Array();
|
case preg_match("/^INSERT\s/i", $statement):
|
||||||
$i=1;
|
$rs = $con->executeUpdate($SqlStatement);
|
||||||
while ($rs->next()) {
|
$con->commit();
|
||||||
$result[$i++] = $rs->getRow();
|
//$result = $lastId->getId();
|
||||||
}
|
$result = 1;
|
||||||
break;
|
break;
|
||||||
case preg_match("/^INSERT\s/i", $statement):
|
case preg_match("/^UPDATE\s/i", $statement):
|
||||||
$rs = $con->executeUpdate($SqlStatement);
|
$rs = $con->executeUpdate($SqlStatement);
|
||||||
$con->commit();
|
$con->commit();
|
||||||
//$result = $lastId->getId();
|
$result = $con->getUpdateCount();
|
||||||
$result = 1;
|
break;
|
||||||
break;
|
case preg_match("/^DELETE\s/i", $statement):
|
||||||
case preg_match("/^UPDATE\s/i", $statement):
|
$rs = $con->executeUpdate($SqlStatement);
|
||||||
$rs = $con->executeUpdate($SqlStatement);
|
$con->commit();
|
||||||
$con->commit();
|
$result = $con->getUpdateCount();
|
||||||
$result = $con->getUpdateCount();
|
break;
|
||||||
break;
|
}
|
||||||
case preg_match("/^DELETE\s/i", $statement):
|
}
|
||||||
$rs = $con->executeUpdate($SqlStatement);
|
else {
|
||||||
$con->commit();
|
$result = executeQueryOci($SqlStatement, $con, $aParameter);
|
||||||
$result = $con->getUpdateCount();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -630,4 +630,110 @@ function registerError($iType, $sError, $iLine, $sCode)
|
|||||||
{
|
{
|
||||||
$sType = ($iType == 1 ? 'ERROR' : 'FATAL');
|
$sType = ($iType == 1 ? 'ERROR' : 'FATAL');
|
||||||
$_SESSION['TRIGGER_DEBUG']['ERRORS'][][$sType] = $sError . ($iLine > 0 ? ' (line ' . $iLine . ')' : '') . ':<br /><br />' . $sCode;
|
$_SESSION['TRIGGER_DEBUG']['ERRORS'][][$sType] = $sError . ($iLine > 0 ? ' (line ' . $iLine . ')' : '') . ':<br /><br />' . $sCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtain engine Data Base name
|
||||||
|
*
|
||||||
|
* @param type $connection
|
||||||
|
* @return type
|
||||||
|
*/
|
||||||
|
function getEngineDataBaseName($connection)
|
||||||
|
{
|
||||||
|
$aDNS = $connection->getDSN();
|
||||||
|
return $aDNS["phptype"];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute Queries for Oracle Database
|
||||||
|
*
|
||||||
|
* @param type $sql
|
||||||
|
* @param type $connection
|
||||||
|
*/
|
||||||
|
function executeQueryOci($sql, $connection, $aParameter = array())
|
||||||
|
{
|
||||||
|
|
||||||
|
$aDNS = $connection->getDSN();
|
||||||
|
$sUsername = $aDNS["username"];
|
||||||
|
$sPassword = $aDNS["password"];
|
||||||
|
$sHostspec = $aDNS["hostspec"];
|
||||||
|
$sDatabse = $aDNS["database"];
|
||||||
|
$sPort = $aDNS["port"];
|
||||||
|
// $sEncoding = $aDNS["encoding"];
|
||||||
|
|
||||||
|
if ($sPort != "1521") { // if not default port
|
||||||
|
$conn = oci_connect($sUsername, $sPassword, $sHostspec . ":" . $sPort . "/" . $sDatabse);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$conn = oci_connect($sUsername, $sPassword, $sHostspec . "/" . $sDatabse);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$conn) {
|
||||||
|
$e = oci_error();
|
||||||
|
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
|
||||||
|
return $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(true) {
|
||||||
|
case preg_match("/^(SELECT|SHOW|DESCRIBE|DESC)\s/i", $sql):
|
||||||
|
$stid = oci_parse($conn, $sql);
|
||||||
|
if (count($aParameter) > 0){
|
||||||
|
foreach ($aParameter as $key => $val) {
|
||||||
|
oci_bind_by_name($stid, $key, $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
oci_execute($stid, OCI_DEFAULT);
|
||||||
|
|
||||||
|
$result = Array();
|
||||||
|
$i = 1;
|
||||||
|
while ($row = oci_fetch_array($stid, OCI_ASSOC + OCI_RETURN_NULLS)) {
|
||||||
|
$result[$i++] = $row;
|
||||||
|
}
|
||||||
|
oci_free_statement($stid);
|
||||||
|
oci_close($conn);
|
||||||
|
return $result;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case preg_match("/^(INSERT|UPDATE|DELETE)\s/i", $sql):
|
||||||
|
$stid = oci_parse($conn, $sql);
|
||||||
|
$isValid = true;
|
||||||
|
if (count($aParameter) > 0){
|
||||||
|
foreach ($aParameter as $key => $val) {
|
||||||
|
oci_bind_by_name($stid, $key, $val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$objExecute = oci_execute($stid, OCI_DEFAULT);
|
||||||
|
if ($objExecute) {
|
||||||
|
oci_commit($conn);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
oci_rollback($conn);
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
if ($isValid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return oci_error();
|
||||||
|
}
|
||||||
|
oci_free_statement($stid);
|
||||||
|
oci_close($conn);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Stored procedures
|
||||||
|
$stid = oci_parse($conn, $sql);
|
||||||
|
$aParameterRet = array();
|
||||||
|
if (count($aParameter) > 0){
|
||||||
|
foreach ($aParameter as $key => $val) {
|
||||||
|
$aParameterRet[$key] = $aParameter[$key];
|
||||||
|
oci_bind_by_name($stid, $key, $aParameterRet[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$objExecute = oci_execute($stid, OCI_DEFAULT);
|
||||||
|
oci_free_statement($stid);
|
||||||
|
oci_close($conn);
|
||||||
|
return $aParameterRet;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user