-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Labels
enhancementNew feature or requestNew feature or requestquestionFurther information is requestedFurther information is requested
Description
To help with creating APIs in RPG for querying tables, I was thinking it would be useful to add an SQL prefix that goes beyond what rpg does and generates an actual RPG procedure.
For example, given:
select
empno,
rtrim(firstnme) || ' ' || rtrim(midinit) || ' ' || rtrim(lastname),
salary + bonus + comm
from
sample.employee
where
empno = ?;We could generate something like:
**free
ctl-opt nomain;
dcl-ds employee_t qualified template;
empno char(6);
name varchar(50);
netincome packed(9:2);
end-ds;
dcl-proc getEmployee export;
dcl-pi *n like(employee_t);
empno char(6) const;
end-pi;
dcl-ds employee likeds(employee_t);
exec sql
select
empno,
rtrim(firstnme) || ' ' || rtrim(midinit) || ' ' || rtrim(lastname),
salary + bonus + comm
into
:employee.empno,
:employee.name,
:employee.netincome
from
sample.employee
where
empno = :empno;
return employee;
end-proc;the template is basically:
**free
ctl-opt nomain;
dcl-ds <table_name>_t qualified template;
<table_columns>
end-ds;
dcl-proc get<table_name> export;
dcl-pi *n like(<table_name>_t);
<prepared_statement_parameters>
end-pi;
dcl-ds <table_name> likeds(<table_name>_t);
exec sql
<user_query_with_into_added_and_where_with_parameters>
return <table_name>;
end-proc;This would tie in really well with the unit test stub generation. Imagine now (all now in a couple seconds!): Write an SQL query -> Generate an RPG procedure -> Generate a RPG test stub -> Celebrate! 🎉
The difficult part may be adding the into ... in the correct spot and properly handling the parameters, but I think this can be done.
Questions:
- What prefix makes sense? Should this simply be
rpg:or have a new prefix (rpgproc:or something else)? Change both prefixes todcl-ds:anddcl-proc:?
@worksofliam @forstie What do you think about this?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestquestionFurther information is requestedFurther information is requested