Hi,
Req Path is stored in the DB as a sequence of three letters. For example the path "Requirements\MyFolder1\Fold2" could be something like AAAAACAAF. This information is the REQ_PATH of Fold2.
I think you would like a Function that when you pass a string like "Requirements\MyFolder1\Fold2" it returns all of children that are under Fold2. So a query from REQ that retrieve all the items whom the RQ_REQ_PATH like 'AAAAACAAF%'
I suppose the connection to the project you are able to do it. Suppose also tdc is the TDConnection object. So I should do:
Dim myStartPath, myDBReqPath, strIDandName
strIDandName = ""
myDBReqPath = ""
myStartPath = "Requirements\MyFolder1\MyFolder2"
'1st I need to understand if the path is correct, if it exists it returns the REQ_PATH as AAAAAC...
myDBReqPath = strDBReqPath(myStartPath)
'2nd if the value of myDBreqPath is something valid then we go on...
if myDBReqPath <>"" then
'3rd I can run a query to retrieve all the Reqs under that path
dim myComm, RecSet
set myComm = tdc.Command
myComm.CommandText = "Select RQ_REQ_ID, RQ_REQ_NAME from REQ " & _
"where RQ_REQ_PATH like '" & myDBReqPath & "%'"
set RecSet = myComm.Execute
if RecSet.RecordCount > 0 then
do while not(RecSet.EOR)
strIDandName = strIDandName & "ID: " & RecSet.FieldValue(0) & " - Name: " & RecSet.FieldValue(1) & vbNewLine
RecSet.Next
loop
msgbox strIDandName
end if
end if
Function strDBReqPath(myStartPath)
Dim strRes, arrReq, myComm, RecSet
strRes = ""
if myStartPath <> "" then
if instr(myStartPath, "\") > 0 then
arrReq = split(myStartPath,"\")
'1st query to retrieve the 1st ID of the path
set myComm = tdc.command
myComm.CommandText = "Select RQ_REQ_ID from REQ where RQ_REQ_NAME = '" & arrReq(0) & "'"
set RecSet = myComm.Execute
if RecSet.RecordCount > 0 then
RecSet.first
Father_ID = RecSet.FieldValue(0)
'2nd I do a for cycle to understand if the path is ok
bolExist = false
for i= 1 to ubound(arrReq)
myComm.CommadText = "select RQ_REQ_ID from Req " & _
"where RQ_FATHER_ID = " & Father_ID & " and RQ_REQ_NAME = '" & arrReq(i) & "'"
set RecSet = myComm.Execute
if RecSet.RecordCount = 1 then
RecSet.First
Father_ID = RecSet.FieldValue(0)
if i = ubound(arrReq) then
bolExist = true
end if
else
exit for
end if
next
if bolExist then
myComm.CommandText = "Select RQ_REQ_PATH from REQ " & _
"where RQ_REQ_NAME = '" & arrReq(ubound(arrReq)) & _
"' and RQ_REQ_ID = " & Father_ID 'the last ID of the requirement in the path
set RecSet = myComm.Execute
strRes = RecSet.FieldValue(0) 'This must be ok.
end if
end if
else
strRes = myStartPath 'There is only a folder
end if
end if
strDBReqPath = strRes
End Function