Merged in gproly/processmaker/HOR-91 (pull request #3552)

HOR-91
This commit is contained in:
Julio Cesar Laura Avendaño
2016-01-27 17:02:04 -04:00
2 changed files with 64 additions and 8 deletions

View File

@@ -176,9 +176,9 @@ class pmDynaform
$json->sql = "";
$json->optionsSql = array();
if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") {
$cnn = Propel::getConnection($json->dbConnection);
$stmt = $cnn->createStatement();
try {
$cnn = Propel::getConnection($json->dbConnection);
$stmt = $cnn->createStatement();
$sql = G::replaceDataField($json->sql, $this->getValuesDependentFields($json));
$rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
while ($rs->next()) {

View File

@@ -556,13 +556,16 @@ class Variable
\G::LoadClass('pmDynaform');
$pmDynaform = new \pmDynaform();
$field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $arrayVariable["field_id"]);
$variableDbConnectionUid = $field !== null ? $field->dbConnection : "";
$dbConnection = "workflow";
if ($field !== null && !empty($field->dbConnection)) {
$dbConnection = $field->dbConnection;
}
$variableSql = $field !== null ? $field->sql : "";
//Get data
$_SESSION["PROCESS"] = $processUid;
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
$cnn = \Propel::getConnection($dbConnection);
$stmt = $cnn->createStatement();
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
@@ -677,13 +680,16 @@ class Variable
\G::LoadClass('pmDynaform');
$pmDynaform = new \pmDynaform();
$field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $variableName);
$variableDbConnectionUid = $field !== null ? $field->dbConnection : "";
$dbConnection = "workflow";
if ($field !== null && !empty($field->dbConnection)) {
$dbConnection = $field->dbConnection;
}
$variableSql = $field !== null ? $field->sql : "";
//Get data
$_SESSION["PROCESS"] = $processUid;
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "") ? $variableDbConnectionUid : "workflow");
$cnn = \Propel::getConnection($dbConnection);
$stmt = $cnn->createStatement();
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
@@ -702,7 +708,7 @@ class Variable
}
$parser = new \PHPSQLParser($replaceFields);
$filter = str_replace("'", "''", $filter);
$replaceFields = $this->queryModified($parser->parsed, $filter, "*searchtype*", $start, $limit);
$replaceFields = $this->queryModified($parser->parsed, $filter, "*searchtype*", $start, $limit, $dbConnection);
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
while ($rs->next()) {
@@ -721,7 +727,7 @@ class Variable
}
}
public function queryModified($sqlParsed, $inputSel = "", $searchType, $start, $limit)
public function queryModified($sqlParsed, $inputSel = "", $searchType = "*searchtype*", $start = 0, $limit = "", $dbConnection = "workflow")
{
if (!empty($sqlParsed['SELECT'])) {
$sqlSelectOptions = (isset($sqlParsed["OPTIONS"]) && count($sqlParsed["OPTIONS"]) > 0) ? implode(" ", $sqlParsed["OPTIONS"]) : null;
@@ -844,6 +850,26 @@ class Variable
if (!empty($sqlParsed['LIMIT'])) {
$sqlLimit = " LIMIT " . $sqlParsed['LIMIT']['start'] . ", " . $sqlParsed['LIMIT']['end'];
}
//get database provider
$a = new \Criteria("workflow");
$a->addSelectColumn(\DbSourcePeer::DBS_TYPE);
$a->add(\DbSourcePeer::DBS_UID, $dbConnection, \Criteria::EQUAL);
$ds = \DbSourcePeer::doSelectRS($a);
$ds->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$ds->next();
$row = $ds->getRow();
if (isset($row["DBS_TYPE"])) {
if ($row["DBS_TYPE"] === "pgsql") {
$sqlLimit = $this->limitPgsql($start, $limit);
}
if ($row["DBS_TYPE"] === "mssql") {
return $this->limitMssqlOracle($sqlSelect, $sqlFrom, $sqlWhere, $sqlGroupBy, $sqlHaving, $sqlOrderBy, $start, $limit, true);
}
if ($row["DBS_TYPE"] === "oracle") {
return $this->limitMssqlOracle($sqlSelect, $sqlFrom, $sqlWhere, $sqlGroupBy, $sqlHaving, $sqlOrderBy, $start, $limit, false);
}
}
return $sqlSelect . $sqlFrom . $sqlWhere . $sqlGroupBy . $sqlHaving . $sqlOrderBy . $sqlLimit;
}
@@ -873,6 +899,36 @@ class Variable
}
}
public function limitPgsql($start = 0, $limit = "")
{
$sqlLimit = "";
if ($start >= 0) {
$sqlLimit = " OFFSET " . $start;
}
if ($limit !== "") {
$sqlLimit = $sqlLimit . " LIMIT " . $limit;
}
return $sqlLimit;
}
public function limitMssqlOracle($sqlSelect = "", $sqlFrom = "", $sqlWhere = "", $sqlGroupBy = "", $sqlHaving = "", $sqlOrderBy = "", $start = 0, $limit = "", $isMssql = true)
{
$sqlLimit = "";
if ($start >= 0) {
$sqlLimit = "WHERE rn >= " . $start;
}
if ($start >= 0 && $limit != "") {
$sqlLimit = "WHERE rn BETWEEN " . $start . " AND " . $limit;
}
$sql = ""
. "SELECT * FROM ("
. " " . $sqlSelect . ", ROW_NUMBER() OVER( " . $sqlOrderBy . " desc )-1 " . ($isMssql ? " AS " : "") . " rn "
. " " . $sqlFrom . $sqlWhere . $sqlGroupBy . $sqlHaving
. ")" . ($isMssql ? " AS A " : "")
. $sqlLimit;
return $sql;
}
public function getVariableTypeByName($processUid, $variableName)
{
try {