xslt/xquery for checking values of two attributes in if conditions - for-loop

I am stuck at a place in my xquery. In the response i want to get back the phone numbers for each Type i.e. HOME and CELL , but only the ones which have highest sequence number .If there are two rows with PhoneType="HOME" , I want back the phone which has highest sequence of two i.e in my case Sequence="3".
With my xquery I am able to get back a phoneType="HOME" and the first row with type HOME. i am not able to add a condition to check the Sequence as well. Where and how can i add it. Please suggest. Thanks in advance
Part of my Xquery:
<acc:phones>
{
for $PersonPhonesRow in $PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[#PhoneType="HOME"][1]
return
if(fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow/#PhoneType="HOME"[1]))
then
<com:phone>
<com:type>{'HOME'}</com:type>
<com:phoneNumber>{fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[#PhoneType="HOME"][1]/#PhoneNumber)}</com:phoneNumber>
<com:carrier>{fn:data($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[#PhoneType="HOME"][1]/#Extension)}</com:carrier>
</com:phone>
else
()
}
</acc:phones>
Request:
<CMPerson xmlns="http://splwg.com/CMPerson.xsd">
<CMPersonService>
<CMPersonDetails>
<PersonPhones>
<PersonPhonesHeader PersonID="1234567890" LastSequenceNumber="9"/>
<PersonPhonesRow PersonID="1234567890" Sequence="1" PhoneType="HOME" IntlPrefix="" PhoneNumber="(850) 123-0000" Extension="" Version="12" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="2" PhoneType="CELL" IntlPrefix="" PhoneNumber="(850) 000-0000" Extension="" Version="3" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="3" PhoneType="HOME" IntlPrefix="" PhoneNumber="(850) 123-1111" Extension="ATT" Version="1" PhoneAlgorithmParamValue="(999) 999-9999"/>
<PersonPhonesRow PersonID="1234567890" Sequence="4" PhoneType="BUSN" IntlPrefix="" PhoneNumber="(904) 111-1111" Extension="" Version="3" PhoneAlgorithmParamValue="(999) 999-9999"/>
</PersonPhones>
</CMPersonDetails>
</CMPersonService>
</CMPerson>
Response required:
<acc:phones>
<com:phone xmlns:com="******">
<com:type>HOME</com:type>
<com:phoneNumber>(850) 123-1111</com:phoneNumber>
<com:carrier>ATT</com:carrier>
</com:phone>
<com:phone xmlns:com="******">
<com:type>CELL</com:type>
<com:phoneNumber>(904) 111-1111</com:phoneNumber>
<com:carrier></com:carrier>
</com:phone>
</acc:phones>

Query to be used:
let $PersonMaintenanceResponse := 'Your request'
let $uniqPhoneType :=distinct-values($PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow/#PhoneType)
for $each at $i in $uniqPhoneType
return
<acc:phones>
{
let $seq := $PersonMaintenanceResponse/ns2:CMPersonService/ns2:CMPersonDetails/ns2:PersonPhones/ns2:PersonPhonesRow[(#PhoneType = $each)]
let $maxValue := max($seq/#Sequence)
let $maxrow := $seq[#Sequence eq $maxValue]
return
<com:phone xmlns:com="*******">
<com:type>{$each}</com:type>
<com:phoneNumber>{$maxrow/#PhoneNumber}</com:phoneNumber>
<com:carrier>{$maxrow/#Extension}</com:carrier>
</com:phone>
}</acc:phones>

Related

how to use golang mongodb driver query $or with $and?

1.judge field label_status is exists, if exists is true find one record.
2.if field label_status exist is false. find one record label_status eq 1 and author
eq sample
i use the code:
bson.D{
{"$or", bson.D{{"label_status", bson.D{{"$exists", false}}}}},
{"$and", bson.A{bson.M{"label_status": Labeling}, bson.M{"annotator": "sample"}}},
}
err := collection.FindOne(context.Background(), bson.D{
{"$or", bson.D{{"label_status", bson.D{{"$exists", false}}}}},
{"$and", bson.A{bson.M{"label_status": Labeling}, bson.M{"annotator": "sample"}}},
}).Decode(&result)

Divisor is equal to zero, Need guidance with case statement

This is my query & I'm getting error divisor is equal to zero, I know i need to build this as a case statement just tried a few things and cant get it to work, thanks in advance.
NVL(ROUND(((SELECT PC.BUCKET_ACCUM_COST
FROM PART_CB PC WHERE
PART_CB_NO = '201'
AND PC.PART_NO = I.PART_NO
AND
PC.CONTRACT = P.CONTRACT
AND
PC.TOP_LEVEL_PART_NO || '' =
Z_BEL_FINANCE_API.GET_PART_COST_TOP_PART_NO(P.CONTRACT, P.PART_NO,
P.COST_SET, P.ALTERNATIVE_NO,
P.ROUTING_ALTERNATIVE_NO)
AND
PC.COST_SET = P.COST_SET
AND
PC.COST_BUCKET_ID != 'SYS'
AND
PC.TOP_ALTERNATIVE_NO =
Z_BEL_FINANCE_API.GET_PART_COST_TOP_ALT_NO(P.CONTRACT, P.PART_NO,
P.COST_SET, P.ALTERNATIVE_NO,
P.ROUTING_ALTERNATIVE_NO)
AND
PC.TOP_ROUTING_NO =
Z_BEL_FINANCE_API.GET_PART_COST_TOP_ROUTING_NO(P.CONTRACT, P.PART_NO,
P.COST_SET, P.ALTERNATIVE_NO,
P.ROUTING_ALTERNATIVE_NO)
AND
PC.BUCKET_SEQ = Z_BEL_FINANCE_API.GET_PART_COST_BUCKET_SEQ(P.CONTRACT,
P.PART_NO, P.COST_SET, P.ALTERNATIVE_NO,
P.ROUTING_ALTERNATIVE_NO)) /
(SELECT WC_RATE
FROM WCT
WHERE WORK_CENTER_NO = 'COST1'
AND COST_SET = '1'
AND CONTRACT = P.CONTRACT)), 4), 0) MACHINE_SETUP_TIME,
The only dividing in this mess is here:
/ (SELECT WC_RATE FROM WCT ...)
If you don't want to divide with zero, you'll have to handle it.
For example, use DECODE (or CASE) and - if you want to get 0 as the result, divide with a very large number (e.g. 1E99)

GA API Filter Failure: Invalid value 'ga:userGender == female' for filters parameter."

I tried to add a filter to extract data only from female users, but encounter the following error:
Invalid value 'ga:userGender == female' for filters parameter.
This is my code:
query.list <- Init(start.date = "2015-10-09", end.date = "2016-10-09", dimensions = "ga:userAgeBracket", metrics = "ga:users,ga:pageviews,ga:sessions", filter = "ga:userGender == female", max.results = 10000, table.id = "ga:xxxxxxxx")
ga.query <- QueryBuilder(query.list) cga.data <- GetReportData(ga.query, oauth_token)
I do not understand what I did wrong -- I thought my code was correct.

CT_FETCH error in PowerBuilder Program

I'm still learning PowerBuilder and trying to get familiar with it. I'm receiving the following error when I try to run a program against a specific document in my database:
ct_fetch(): user api layer: internal common library error: The bind of result set item 4 resulted in an overflow. ErrCode: 2.
What does this error mean? What is item 4? This is only when I run this program against a specific document in my database, any other document works fine. Please see code below:
string s_doc_nmbr, s_doc_type, s_pvds_doc_status, s_sql
long l_rtn, l_current_fl, l_apld_fl, l_obj_id
integer l_pvds_obj_id, i_count
IF cbx_1.checked = True THEN
SELECT dsk_obj.obj_usr_num,
dsk_obj.obj_type,
preaward_validation_doc_status.doc_status,
preaward_validation_doc_status.obj_id
INTO :s_doc_nmbr, :s_doc_type, :s_pvds_doc_status, :l_pvds_obj_id
FROM dbo.dsk_obj dsk_obj,
preaward_validation_doc_status
WHERE dsk_obj.obj_id = :gx_l_doc_obj_id
AND preaward_validation_doc_status.obj_id = dsk_obj.obj_id
using SQLCA;
l_rtn = sqlca.uf_sqlerrcheck("w_pdutl095_main", "ue_run_script", TRUE)
IF l_rtn = -1 THEN
RETURN -1
END IF
//check to see if document (via obj_id) exists in the preaward_validation_doc_status table.
SELECT count(*)
into :i_count
FROM preaward_validation_doc_status
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF i_count = 0 THEN
//document doesn't exist
// messagebox("Update Preaward Validation Doc Status", + gx_s_doc_nmbr + ' does not exist in the Preaward Validation Document Status table.', Stopsign!)
//MC - 070815-0030-MC Updating code to insert row into preaward_validation_doc_status if row doesn't already exist
// s_sql = "insert into preaward_validation_doc_status(obj_id, doc_status) values (:gx_l_doc_obj_id, 'SUCCESS') "
INSERT INTO preaward_validation_doc_status(obj_id, doc_status)
VALUES (:gx_l_doc_obj_id, 'SUCCESS')
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number ' + gx_s_doc_nmbr + ' has been inserted and marked as SUCCESS for PreAward Validation.')
return 1
Else
//Update document status in the preaward_validation_doc_status table to SUCCESS
Update preaward_validation_doc_status
Set doc_status = 'SUCCESS'
where obj_id = :l_pvds_obj_id
USING SQLCA;
IF sqlca.sqldbcode <> 0 then
messagebox('SQL ERROR Message',string(sqlca.sqldbcode)+'-'+sqlca.sqlerrtext)
return -1
end if
MessageBox("PreAward Validation ", 'Document number '+ gx_s_doc_nmbr + ' has been marked as SUCCESS for PreAward Validation.')
End IF
update crt_script
set alt_1 = 'Acknowledged' where
ticket_nmbr = :gx_s_ticket_nmbr and
alt_2 = 'Running' and
doc_nmbr = :gx_s_doc_nmbr
USING SQLCA;
Return 1
ElseIF cbx_1.checked = False THEN
messagebox("Update Preaward Validation Doc Status", 'The acknowledgment checkbox must be selected for the script to run successfully. The script will now exit. Please relaunch the script and try again . ', Stopsign!)
Return -1
End IF
Save yourself a ton of headaches and use datawindows... You'd reduce that entire script to about 10 lines of code.
Paul Horan gave you good advice. This would be simple using DataWindows or DataStores. Terry Voth is on the right track for your problem.
In your code, Variable l_pvds_obj_id needs to be the same type as gx_l_doc_obj_id because if you get a result, it will always be equal to it. From the apparent naming scheme it was intended to be long. This is the kind of stuff we look for in peer reviews.
A few other things:
Most of the time you want SQLCode not SQLDbCode but you didn't say what database you're using.
After you UPDATE crt_script you need to check the result.
I don't see COMMIT or ROLLBACK. Autocommit isn't suitable when you need to update multiple tables.
You aren't using most of the values from the first SELECT. Perhaps you've simplified your code for posting or troubleshooting.

How i can send data from mnesia via websocket

I have mnesia DB with table artists:
(gw#gw)227> lookup:for_test().
{atomic,["Baltic Baroque","Anna Luca","Karel Boehlee Trio",
"Bill Evans","Dino Saluzzi and Anja Lechner",
"Bill Evans Trio with Stan Getz","Duke Pearson",
"The John Butler Trio"]}
(gw#gw)228>
I want send this list to client by websocket in YAWS, but how i can do it? I broke my mind ... and nothing working. Please help by any info.
Best regards!
You have to convert this list of string to binaries and the pass is across over web socket, by the way what kind of data handling are you doing at the receiving end I mean you want to send this as JSON or just Comma separated values?
Yeeeees ... i solve my problem!
My YAWS Handle
handle_message({text, <<"q2">>}) ->
Var555 = unicode:characters_to_binary(my_json4:handle()),
{reply, {text, <<Var555/binary>>}};
And my mnesia select + convert to JSON. my_json4.erl
Data = [{obj,
[{art_id, Line#tmp.artist_id},
{art, unicode:characters_to_binary(Line#tmp.artist)},
{alb_id, Line#tmp.album_id},
{alb, unicode:characters_to_binary(Line#tmp.album)},
{path, unicode:characters_to_binary(Line#tmp.albumpath)},
{image, unicode:characters_to_binary(Line#tmp.image)},
{tracks, [unicode:characters_to_binary(X) ||X <- Line#tmp.tracks]}]}
|| Line <- Lines],
JsonData = {obj, [{data, Data}]},
rfc4627:encode(JsonData).
handle() ->
QHandle = qlc:q( [ X ||
X <- mnesia:table(artists),
X#artists.artist_id == 2]
),
Records = do(qlc:q([{tmp, X#artists.artist_id, X#artists.artist, A#albums.album_id, A#albums.album, A#albums.albumpath, A#albums.image, A#albums.tracklist} ||
X <- QHandle,
A <- mnesia:table(albums),
A#albums.artist_id == X#artists.artist_id])
),
Json = convert_to_json(Records),
Json.
do(Q) ->
F = fun() ->
qlc:e(Q)
end,
{atomic, Value} = mnesia:transaction(F),
Value.

Resources