Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
tbl
Commits
34322eca
Commit
34322eca
authored
Jul 01, 2020
by
Laurent Lécluse
Browse files
Travaux en cours
parent
678d07de
Pipeline
#7786
failed with stage
in 5 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/UnicaenTbl/Service/QueryGeneratorService.php
View file @
34322eca
...
...
@@ -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
)
{
...
...
src/UnicaenTbl/Service/SchemaService.php
View file @
34322eca
...
...
@@ -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
,
[]);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment