Commit 34322eca authored by Laurent Lécluse's avatar Laurent Lécluse

Travaux en cours

parent 678d07de
Pipeline #7786 failed with stage
in 5 seconds
......@@ -200,7 +200,7 @@ class QueryGeneratorService extends AbstractService
*/
protected function makeProcDeclaration(TableauBord $tbl)
{
return " PROCEDURE C_" . strtoupper($tbl->getName()) . "( PARAMS UNICAEN_TBL.T_PARAMS );";
return " PROCEDURE C_" . strtoupper($tbl->getName()) . "(param VARCHAR2, value VARCHAR2);";
}
......@@ -219,6 +219,113 @@ class QueryGeneratorService extends AbstractService
$view = strtoupper($tbl->getViewName(true));
$sequence = strtoupper($tbl->getSequenceName(true));
if (empty($tbl->getKeyColumns())){
throw new \Exception('Le tableau de bord '.$tbl->getName().' n\'a pas de contrainte d\'unicité.');
}
$maxKeyColLen = 0;
foreach ($tbl->getKeyColumns() as $column) {
if (strlen($column) > $maxKeyColLen) {
$maxKeyColLen = strlen($column);
}
}
$maxColLen = 0;
foreach ($tbl->getColumns() as $column) {
if (strlen($column) > $maxColLen) {
$maxColLen = strlen($column);
}
}
$join = [];
$testNull = [];
foreach ($tbl->getKeyColumns() as $column) {
$colLen = strlen($column);
$colAjust = str_pad('', $maxColLen - $colLen);
if ($column->isNullable()) {
$join[] = "COALESCE(t.$column,0)$colAjust = COALESCE(v.$column,0)\n";
} else {
$join[] = "t.$column$colAjust = v.$column\n";
}
$testNull[] = "d.$column IS NULL\n";
}
$join = trim(implode(" AND ", $join));
$testNull = trim(implode(" AND ", $testNull));
$testDiff = [];
$cols = [];
foreach ($tbl->getColumns() as $column) {
$colLen = strlen($column);
$colAjust = str_pad('', $maxColLen - $colLen);
if ($column->isNullable()) {
$testDiff[] = "COALESCE(t.$column,0)$colAjust = COALESCE(v.$column,0)\n";
} else {
$testDiff[] = "t.$column$colAjust = v.$column\n";
}
$cols[] = "v.$column";
}
$testDiff = trim(implode(" AND ", $testDiff));
$cols = trim(implode(",\n ", $cols));
// $view = $this->getViewDefinition($view);
// $view = str_replace( '\'', '\'\'', $view);
// $view = str_replace( "\n", "\n ", $view);
$sql = " PROCEDURE C_$tableauBord(param VARCHAR2, value VARCHAR2) IS
TYPE r_cursor IS REF CURSOR;
c r_cursor;
d $table%rowtype;
BEGIN
OPEN c FOR '
SELECT
CASE WHEN
$testDiff
THEN -1 ELSE t.ID END ID,
$cols
FROM
($view) v
FULL JOIN $table t ON
$join
';
LOOP
FETCH c INTO d; EXIT WHEN c%NOTFOUND;
IF d.id IS NULL THEN
d.id := $sequence.NEXTVAL;
INSERT INTO $table values d;
ELSIF
$testNull
THEN
DELETE FROM $table WHERE id = d.id;
ELSIF d.id != -1 THEN
UPDATE $table SET row = d WHERE id = d.id;
END IF;
END LOOP;
CLOSE c;
END;
";
return $sql;
}
/**
* Génère un corps de procédure pour une table donnée
*
* @param TableauBord $tbl
*
* @return string
*/
protected function makeProcBodyOld(TableauBord $tbl)
{
$tableauBord = strtoupper($tbl->getName());
$table = strtoupper($tbl->getTableName(true));
$view = strtoupper($tbl->getViewName(true));
$sequence = strtoupper($tbl->getSequenceName(true));
$maxColLen = 0;
foreach ($tbl->getKeyColumns() as $column) {
if (strlen($column) > $maxColLen) {
......
......@@ -56,7 +56,7 @@ class SchemaService extends AbstractService
/* Récupération des colonnes des tableaux de bord */
if ($tables) {
$sql = "SELECT TABLE_NAME, COLUMN_NAME, NULLABLE FROM USER_TAB_COLS WHERE "
. "TABLE_NAME IN ('" . implode("','", array_keys($tables)) . "')";
. "TABLE_NAME IN ('" . implode("','", array_keys($tables)) . "') ORDER BY COLUMN_ID";
$d = $this->query($sql, []);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment