A development approach to embed parametrized SQL statements in software applications. For more details, please visit this link
https://www.researchgate.net/publication/4144158_SQL_Statement_Template_a_development_approach_for_database-driven_applications
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
SQL Statement Template
1. SQL Statement Template: A Development
Approach for Database-Driven
Applications
Osama M. Khaled
The American University in Cairo
okhaled@aucegypt.edu
Hoda M. Hosny
The American University in Cairo
hhosny@aucegypt.edu
2. OUTLINE
Background
Domain Analysis
Roles & Responsibilities
SQL Statement Template Definition
Language
Example
3. BACKGROUND
Brief History about DB.
Database role in application
development.
SQL Statement Externalization.
– Sun DAO Design Pattern
– Business Objects
4. DOMAIN ANALYSIS
Defects of bundling SQL statements inside the
application code.
– SQL maintenance requires code recompilation.
– Deviating focus of application developer.
– Readability and understandability decreases.
– DB experts cannot easily read SQL statements inside the
code.
6. ROLES & RESPONSIBILITIES
Why build SQL statements in design phase.
– DB designer has fresh knowledge about
architecture.
– Helps refining DB design.
– Guarantees consistent SQL statements.
– Implementers will focus more on functional
requirements.
– Speeds up development process.
– DB is a product in itself.
9. ROLES & RESPONSIBILITIES
Affected parties
DB Admin System Administrator
System Support
SQL Statement Templates Files
REVIEW
FOR
OPTIMIZATION
Figure out SQL
problems easily
Resolve bugs
10. SQL STATEMENT TEMPLATE
DEFINITION LANGUAGE
SQL Statements Construction
complexity.
Type Example
No replaceable
value
SELECT *
FROM INVOICES
WHERE
INVOICE_TYPE = 1
AND PRICE > 30
Replaceable value
only
SELECT *
FROM INVOICES
WHERE
INVOICE_TYPE = $INVOICE_TYPE$
AND PRICE > $MIN_PRICE$
Replaceable SQL
constructs
SELECT
--$all$ *
--$invoice_number$ inv_no
FROM
INVOICES
--$inv_type$ WHERE INVOICE_TYPE = $INVOICE_TYPE$
--$min_price$ WHERE PRICE > $MIN_PRICE$
11. SQL STATEMENT TEMPLATE
DEFINITION LANGUAGE
Describing the language
Benefits of using this language
– People with database background are more familiar with this
structure.
– Easy to edit with SQL editors.
– Can support easily the third type of the SQL statements
complexities.
– Can be converted easily to XML.
– Definition semantics
– Documentation
– Implementation complexity.
13. EXAMPLE
SELECT
U.ACTIVITY_NAME AS NUM1,
TO_CHAR(SUM(U.ROUNDED_VOLUME)) AS VALUE
FROM
ACTIVITY U,
GROUPS G,
EMPLOYEE_GROUPS CG
WHERE
U.EMPOLOYEE_ID = $employee_id$ AND
CV.ACTIVITY_TYPE = ’$activity_type$’ AND
CG.EMPLOYEE_KEY = G.EMPLOYEE_KEY AND
CG.GROUPS_KEY = G.GROUPS_KEY AND
U.ACTIVITY_KEY = CG.CACTIVITY_KEY AND
G.EMPLOYEE_KEY = $employee_key$ AND
G.GROUPS_KEY = $group_key$
GROUP BY U.ACTIVITY_NAME ORDER BY
SUM(U.ROUNDED_VOLUME) DESC
14. EXAMPLE
--@begin ACTIVITY_ACCESS
--@group ACTIVITIES
SELECT
--$ achievement $ U.ACTIVITY_NAME AS NUM1,
--$ achievement $ TO_CHAR(COUNT(*)) AS VALUE
--$cost$ U.ACTIVITY_NAME AS NUM1,
--$cost$TO_CHAR(SUM(U.RATED_AMOUNT)) AS VALUE
--$dur$ U.ACTIVITY_NAME AS NUM1,
--$dur$ TO_CHAR(SUM(U.ROUNDED_VOLUME)) AS VALUE
FROM ACTIVITY U
WHERE U.EMPLOYEE_ID = $employee_id$
--$achievement$ GROUP BY U.ACTIVITY_NAME
--$achievement$ ORDER BY COUNT(*) DESC
--$cost$ GROUP BY U.ACTIVITY_NAME
--$cost$ ORDER BY SUM(U.RATED_AMOUNT) DESC
--$dur$ GROUP BY U.ACTIVITY_NAME
--$dur$ ORDER BY SUM(U.ROUNDED_VOLUME) DESC
--@end ACTIVITY_ACCESS
15. EXAMPLE
SQLBlock sqlBlock = SQLIndexer().
getSQL("ACTIVITY_ACCESS");
// enable where keyword
sqlBlock.setTagValue("employee_id",
employee_id);
// report_type is acheivement, cost, or dur
sqlBlock.clearCommentTag(report_type);
Vector result =
select(sqlBlock.getRuntimeSql());
Standardization: Separating SQL statements from code must maintain the standard SQL scripting to facilitate reading, debugging, and modifying them for the DB experts.
Maintainability: The SQL Statement Template interface between the application and the external files must be very clear at the design phase. Although, it may be changed in the development phase.
Complexity: The solution should organize the SQL statements and group them in a professional way. It must also provide a technique to handle the IF conditions by which different blocks of the SQL statements may be grouped together inside the code.
Reusability: The SQL Statement Templates should be available for other applications that may need to access the same Database although they may have different functionality.
. Show the benefits of building the SQL statements in the design phase.
. Explain the activity diagram of the design phase + roles and responsibilities
. Explain the activities of the implementation phase
. Show how other role players could be affected directly by using SQL statement templates. (DB administrators, system administrators, system support)