Download In olden times, pre–relational database, database systems were

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
In olden times, pre–relational database, database systems were structured using network
or hierarchical models. The hierarchical databases were great for data organized like the
QC test plan and test lab folders.
Relational databases are great for general purpose data processing, but hierarchical data
structures don’t come naturally. Hierarchies are a recursive data structure; recursion is
quite difficult in SQL queries. That’s why I got excited when Common Table Expressions
(CTE) were included in Transact–SQL for SQL Server 2005. I haven’t actually used CTE’s
much because early in my TestDirector adventures I figured out that the QC database
includes fields that create a hierarchical structure using a technique call a Materialized
Path. Each record includes a field that stores the whole path to the root of the tree or
hierarchy.
The Materialized Path fields in QC that I’m aware of are CF_ITEM_PATH in the
CYCL_FOLD table, AL_ABSOLUTE_PATH in the ALL_LISTS table, and LS_PATH in the
LISTS table. I use CF_ITEM_PATH in many of my QC reports to traverse the Test Lab
folder structure. (I believe that this is the topic you’re interested in.)
AL_ABSOLUTE_PATH will give you the Test Plan folder structure. I’ve only experimented
with it. I have not used it in a production report. LS_PATH has been of no use to me.
The HP documentation for ALM 11.0 is much improved over previous versions. They
actually tell you how to use these materialized path fields.
The remarks in the CYCLE table documentation above are useful because they explain key
relationships between Test Lab tables.
OK, then, with this information you can create a query to traverse the Materialized Path
(CF_ITEM_PATH) through the Test Set Folder Tree. I carried the query down to the Test
Set level and displayed the Test Set Name (CY_CYCLE). I left it to the student to extend
the query to access test cases in the TEST table, which can be reached through the
TESTCYCL table. The project that I used as an example has Test Set folders four levels
deep.
The magic in the query is in the FROM clause with the self–referential Left Join: on
T1.CF_ITEM_PATH like T2.CF_ITEM_PATH + '%'.
This is a string comparison. The HP table descriptions above explain the content of the
strings. Each level in the tree is represented by three letters. The first folder at the top
level is AAA. Its first child folder is AAAAAB and so it goes all the way down with each
level adding another three letters to the path. (Actually, the Root folder is AAA and the
first test set folder in the tree is AAAAAA, but that would have cluttered my explanation
with too many letters.)
The SPACE function with the DATALENGTH function in the query is just to display the
folder names as an indented list. The second DATALENGTH function is also unnecessary
for the basic query. It displays the test set folder level in the tree with Root as level zero
and not displayed.
-- Test Set Tree.sql
10/10/11
use [<database name>];
select distinct
SPACE((DATALENGTH(T1.CF_ITEM_PATH)-6)*2)+T1.CF_ITEM_NAME 'Test
Folder',
CY_CYCLE 'Test Set',
((DATALENGTH(T1.CF_ITEM_PATH)-3)/3) 'Level',
T1.CF_ITEM_PATH
from td.CYCL_FOLD T1 left join td.CYCL_FOLD T2
on T1.CF_ITEM_PATH like T2.CF_ITEM_PATH + '%'
left join td.CYCLE
on T2.CF_ITEM_ID = CY_CYCLE_ID
order by T1.CF_ITEM_PATH;
Here’s an example of a SQL Query using a materialized path approach to traverse the Test
Plan tree using a self–join of the ALL_LISTS table based on the AL_ABSOLUTE_PATH
field. As I explained in a separate email on Tuesday, a materialized path is a field added to
a database to enable queries against a hierarchical or tree data structure. The materialized
path field maintains a complete path to the root of the tree in each record. HP’s
implementation of a materialized path is explained in their QC Database document.
I added joins to additional tables in the query to demonstrate how to add additional fields to
the SELECT statement. Comment out fields you aren’t interested in. If all the fields in
the SELECT statement are uncommented the number of records in the returned result set
may be quite large. Of course, if you are creating your own query you need only include the
tables and fields that contain data that you are interested in.
-- Test Plan Tree Exploration.sql
10/14/11
-Uses Materialized Patch approach using AL_ABSOLUTE_PATH
-as the basis for a self-join of the ALL_LISTS table
--
Comment out SELECT fields to reduce the size of the returned data set
use [<database_name>];
select distinct ((DATALENGTH(T1.AL_ABSOLUTE_PATH) - 6)/3) 'Level',
SPACE((DATALENGTH(T1.AL_ABSOLUTE_PATH)-9)*2)+ T1.AL_DESCRIPTION
'Component',
TS_NAME 'Test Case',
-- DS_STEP_NAME 'Design Step',
TC_STATUS 'Test Case Status',
CY_CYCLE 'Test Set',
RN_RUN_NAME 'Run Name',
RN_STATUS 'Run Status',
T1.AL_ABSOLUTE_PATH
from td.ALL_LISTS T1 left join td.ALL_LISTS T2
on T1.AL_ABSOLUTE_PATH like T2.AL_ABSOLUTE_PATH + '%'
join td.TEST on T1.AL_ITEM_ID = TS_SUBJECT
join td.TESTCYCL on TS_TEST_ID = TC_TEST_ID
join td.CYCLE on TC_CYCLE_ID = CY_CYCLE_ID
join td.RUN on CY_CYCLE_ID = RN_CYCLE_ID
join td.DESSTEPS on TS_TEST_ID = DS_TEST_ID
order by T1.AL_ABSOLUTE_PATH;