NSExtension Share Extension limit Photos count - ios8

I have developed a Share Extension and import Photos and Notes from Photos and Notes App.
I want to limit the count of Photos which can be import to only 10 but for Photos i am able to select unlimited photos. Below is the query from info.plist of extension.
Can anyone look into it and guide me to correct query.
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
).#count == $extensionItem.attachments.#count).#count == 1
OR
SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, NOT $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url" AND $uti UTI-CONFORMS-TO "public.plain-text").#count >= 1).#count >= 1).#count >= 1
</string>
</dict>

Got the answer. The change is for line
#count == $extensionItem.attachments.#count).#count == 1
to
#count <= 10).#count >= 1
Which says your count should be <=10 and >=1
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.image"
).#count <= 10).#count >= 1
OR
SUBQUERY(extensionItems, $extensionItem, SUBQUERY($extensionItem.attachments, $attachment, SUBQUERY($attachment.registeredTypeIdentifiers, $uti, NOT $uti UTI-CONFORMS-TO "public.url" AND NOT $uti UTI-CONFORMS-TO "public.file-url" AND $uti UTI-CONFORMS-TO "public.plain-text").#count >= 1).#count >= 1).#count >= 1
</string>
</dict>

IN ShareExtension Info add
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsImageWithMaxCount</key>
<integer>1</integer>
</dict>
</dict>

Related

Update multiple columns based on percentage wise calculation in Oracle

NOTE: Updating total question with sample data and output.
I need to update some columns by comparing from another table and update the columns percentage wise. So here I go.
first of all , the query to get CMM approved length is below with other columns which I need
select CIRCLE,regexp_substr(MP,'[^/]+',1,1)MPNAME,regexp_substr(MP,'[^/]+',1,2)MPCODE,
SPAN_TYPE,SPAN_LINK_ID,NE_LENGTH AS NE_LEN,
ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH from
TBL_FIBER_INV_CMP_REPORT_MV
where CMM_APPROVED_DATE IS NOT NULL OR ROUTE_APPROVED_BY_CMM > 0 OR
JOB_PROGRESS_FLAG = 1;
and the output of above query looks like this below image
[![enter image description here][1]][1]
Now comes the second part which is calculation of the percentage wise ratio
CASE 1: If The CMM approved length in above image is 70km and NE length from (NE,UG, AR len from NE.MV_SPAN#DB_LINK_NE_VIEWER)comes out to be 100Km then divide (UG=80Km and AR=20Km)
Then percentage of bifurcation would be 80% UG_length and 20% AR_length. So, against 70km of CMM approved kilometer, TBL_FIBER_INV_SIGN_OFF_SHEET should update the column as UG = 56Km and AR = 14Km.
the bifurcation should be updated in below table TBL_FIBER_INV_SIGN_OFF_SHEET
and the table sample data looks like below:-
[![enter image description here][2]][2]
CASE 2: IF CMM approved length and NE length is same. for ex: 70km (UG = 60 Km and AR=10Km) then in TBL_FIBER_INV_SIGN_OFF_SHEET table should update UG = 60Km and AR = 10Km.
Below are the table description of both the tables.
CREATE OR REPLACE PROCEDURE UPD_UG_AR_BY_CMM AS
BEGIN
for cur_r in (
select circle,
regexp_substr(MP,'[^/]+',1,1)MAINTENANCE_ZONE_NAME,
regexp_substr(MP,'[^/]+',1,2)MAINTENANCE_ZONE_CODE,
SPAN_TYPE,
SPAN_LINK_ID,
NE_LENGTH,
ROUTE_APPROVED_BY_CMM
from TBL_FIBER_INV_CMP_REPORT_MV
where CMM_APPROVED_DATE IS NOT NULL
OR ROUTE_APPROVED_BY_CMM > 0
OR JOB_PROGRESS_FLAG = 1
)
LOOP
IF cur_r.ROUTE_APPROVED_BY_CMM > SELECT ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH,
ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%' OR RJ_CONSTRUCTION_METHODOLOGY IS NULL THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS UG_LENGTH
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%' THEN NVL(CALCULATED_LENGTH,0) ELSE 0 END)/1000,4) AS AR_LENGTH
FROM NE.MV_SPAN#DB_LINK_NE_VIEWER
THEN
BEGIN
UPDATE TBL_FIBER_INV_SIGN_OFF_SHEET
SET FSA_UG = UG_LENGTH, --- divide 80% of NE_LENGTH
FSA_AERIAL = AR_LENGTH --- divide 20% of NE_LENGTH
WHERE CUR_R.SPAN_LINK_ID = RJ_SPAN_ID
END
NULL;
END UPD_UG_AR_BY_CMM;
but iam stuck at calculation of percentage wise ratio.
ok, so finally after tons of clarifications, looks like it should be:
+update: duplicates
merge into TBL_FIBER_INV_SIGN_OFF_SHEET DST
using (
-- Source: original query
with mv as (
select * from (
select
circle,
regexp_substr(MP,'[^/]+',1,1)MAINTENANCE_ZONE_NAME,
regexp_substr(MP,'[^/]+',1,2)MAINTENANCE_ZONE_CODE,
SPAN_TYPE,
SPAN_LINK_ID,
NE_LENGTH, -- ? NE_LENGTH - 1
ROUTE_APPROVED_BY_CMM as CMM_APPROVED_LENGTH,
row_number()over(partition by SPAN_LINK_ID order by ROUTE_APPROVED_BY_CMM) rn
from TBL_FIBER_INV_CMP_REPORT_MV
where CMM_APPROVED_DATE IS NOT NULL
OR ROUTE_APPROVED_BY_CMM > 0
OR JOB_PROGRESS_FLAG = 1
)
where rn=1
)
,pct as (
SELECT
ROUND(SUM(NVL(CALCULATED_LENGTH,0)/1000),4) AS NE_LENGTH -- ? NE_LENGTH - 2
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY NOT LIKE '%AERIAL%'
OR RJ_CONSTRUCTION_METHODOLOGY IS NULL
THEN NVL(CALCULATED_LENGTH,0)
ELSE 0
END)/1000,4
) AS UG_LENGTH
,ROUND(SUM(CASE WHEN RJ_CONSTRUCTION_METHODOLOGY LIKE '%AERIAL%'
THEN NVL(CALCULATED_LENGTH,0)
ELSE 0
END)/1000,4
) AS AR_LENGTH
FROM NE.MV_SPAN#DB_LINK_NE_VIEWER
)
select
mv.*
--,cpt.*
,case when mv.CMM_APPROVED_LENGTH > pct.NE_LENGTH then 0.8 * pct.UG_length
when mv.CMM_APPROVED_LENGTH = pct.NE_LENGTH then 0.9 * pct.UG_length
end as FSA_UG
,case when mv.CMM_APPROVED_LENGTH > pct.NE_LENGTH then 0.2 * pct.AR_LENGTH
when mv.CMM_APPROVED_LENGTH = pct.NE_LENGTH then 0.1 * pct.AR_LENGTH
end as FSA_AERIAL
from mv, pct
-- end of Source query
) SRC
on ( dst.SPAN_LINK_ID = src.SPAN_LINK_ID )
when matched then update
set FSA_UG = src.FSA_UG
,FSA_AERIAL = src.FSA_AERIAL;
Based on your question explanation the update should be
update TBL_FIBER_INV_CMP_REPORT_MV
set UG = CASE WHEN ROUTE_APPROVED_BY_CMM > 70 AND NE_LENGTH >= 100
THEN NE_LENGTH*0.8
WHEN ROUTE_APPROVED_BY_CMM = NE_LENGTH
THEN NE_LENGTH*(60/70)
ELSE 0 END
, AR = CASE WHEN ROUTE_APPROVED_BY_CMM > 70 AND NE_LENGTH >= 100
THEN NE_LENGTH*0.2
WHEN ROUTE_APPROVED_BY_CMM = NE_LENGTH
THEN NE_LENGTH*(60/10)
ELSE 0 END

Oracle - NVL, cascading NVLs, and COALESCE not working as expected

I want this field cost_total to return 0 if it's null. But for some reason it's still returning null on the front end. I've tried:
SUM(ROUND(NVL(RAC.NL_COST, 0),2)) OVER() cost_total
NVL(SUM(ROUND(RAC.NL_COST,2)) OVER(), 0) cost_total
COALESCE(SUM(ROUND(RAC.NL_COST,2)), 0) OVER() cost_total
SUM(ROUND(COALESCE(RAC.NL_COST, 0),2)) OVER(), 0) cost_total
Why are these still returning null and not 0?
I've also tried these to no avail:
NVL(SUM(ROUND(NVL(RAC.NL_COST, 0),2)), ' ') OVER() cost_total
CASE SUM(ROUND(NVL(RAC.NL_COST,0),2)) OVER() WHEN 0 THEN ' ' END cost_total
Try this:
NVL(ROUND(SUM(RAC.NL_COST) OVER (), 2), 0)
Cheers!!

How to get the sum?

I have an encountered problem in my query in Oracle SQL. I don't know how to get the sum of this query:
select call_type, channel
,count (case when status="no answer" then 1 end else 0) as cnt_no_answer
,count (case when status="answered" then 1 end else 0) as cnt_answer
from app_account.cc_call;
Please Help me. Thanks!
To get the answered and not answered records sum instead of count. To get the number of all records that are either answered or not answered use count(status). To get the count of all records, i.e. also records with status null use count(*). Strings need single quotes, not double quotes. The case statement needs END.
EDITED (there were too many END used):
select call_type, channel
, sum(case when status='no answer' then 1 else 0 end) as cnt_no_answer
, sum(case when status='answered' then 1 else 0 end) as cnt_answer
, count(status) as cnt_all_stated
, count(*) as cnt_all_records
from app_account.cc_call
group by call_type, channel;
try this again, i edit it:
SELECT call_type, channel,
sum (CASE WHEN status='no answer' THEN 1 ELSE 0 END) AS cnt_no_answer,
sum (CASE WHEN status='answered' THEN 1 ELSE 0 END) AS cnt_answer
FROM app_account.cc_call
GROUP BY call_type, channel;
Check this out:
SELECT CALL_TYPE,
CHANNEL,
COUNT (CASE WHEN UPPER(STATUS) = UPPER('no answer') THEN 1 ELSE NULL END)
AS CNT_NO_ANSWER,
COUNT (CASE WHEN UPPER(STATUS) = UPPER('answered') THEN 1 ELSE NULL END)
AS CNT_ANSWER
FROM APP_ACCOUNT.CC_CALL
GROUP BY CALL_TYPE, CHANNEL;
select call_type, channel
, sum(case when status='no answer' then 1 else 0 end) as cnt_no_answer
, sum(case when status='answered' then 1 else 0 end) as cnt_answer
, count(status) as cnt_all_stated
, count(*) as cnt_all_records
from app_account.cc_call
group by call_type, channel;
why usind end twice
SELECT Call_type, Channel
,COUNT(CASE WHEN status="no answer" then 1 else 0 end ) as Cnt_no_answer
,COUNT(CASE WHEN status="answered" then 1 else 0 end ) as Cnt_answer
from App_account.cc_call
GROUP BY call_type,channel;
I think there is some error in table deceleration. Pleas give table structure. And you want SUM and YOU are COUNTING there I dnt think it is error but lack of overview. Please give some more details.

Pick up different values in 1 table

This is the example of my database table:
id -- pen color -- pen type -- pen price -- date purchased
1 -- red -- type A -- 10.00 -- 10/02/2013
1 -- white -- type B -- 21.00 -- 13/02/2013
2 -- blue -- type A -- 12.00 -- 09/02/2013
1 -- yellow -- type C -- 14.00 -- 23/02/2013
My desired output is:
how about if i want it to be grouped by the same id?
id -- price A -- price A + B -- price B -- price C
1 -- 10.00 -- 31.00 -- 21.00 -- 14.00
2 -- 12.00 -- 0 -- 0 -- 0
I am seriously having a problem doing this. I think it might be simple, but I am just running out of ideas.
Assuming only one id and type per date, this should work:
<cfquery name='b'>
SELECT ID
, AVG( DECODE( Pen_Type, 'Type A', Pen_Price, 0 ) ) AS Price_A
, AVG( DECODE( Pen_Type, 'Type B', Pen_Price, 0 ) ) AS Price_B
, AVG( DECODE( Pen_Type, 'Type C', Pen_Price, 0 ) ) AS Price_C
FROM Pen_Table
WHERE Date_Purchase = #Date#
GROUP BY ID
</cfquery>
Note that the aggregate function of AVG can be any of the aggregate functions, it's only purpose is to get it to row one per id. This again only works assuming you only have one pen type per id, per date. If you have more rows, then this won't work. Given the information you've provided, I believe this will work. You can easily calculate A+B in the output, compared to trying to do it in the query.
Hope this helps.
While your exact needs are still unclear, the group attribute of cfoutput might put you on the right path. In your case, try something like this.
<cfquery name="yourquery">
select blah, blah
order by id
</cfquery>
The order by id is important. It leads to
<cfoutput query="yourquery" group ="id">
#grouped data#
<cfoutput>
#ungrouped data#
</cfoutput>
#more grouped data if you want#
</cfoutput>
That's the general idea. You should be able to adapt it to your specific requirements.

Formatting the output of oracle plsql query

I have a data set like this
id subid date(in yyyymmdd) time(in hh24miss) count1 count2
80013727 20000000431 20120429 001500 0 0
80013727 20000000431 20120429 003000 0 0
80013729 20000000432 20120429 001500 0 0
80013729 20000000432 20120429 003000 0 0
80013728 20000000435 20120429 001500 0 0
80013728 20000000435 20120429 003000 0 0
As you can see time is in 15 minutes increment . i want to show output the result set like below.
id Date subid 00:00:00-00:14:59 00:15:00-00:29:59
80013727 20120429 20000000431 0 0
80013729 20120429 20000000432 0 0
as you can see all all the data related to id 80013727 i s shown in one row instead of 2 for the date 20120429.
please tell me how to achieve it.
header row can be printed one time using dbms_output.put_line.
Hi here is your answers-
oracle ver 10.2 g
for a unique id,subid,date combination count1 and count2 is need to be shown in one row.
instead of 4 rows that can be seen from top most result set.
80013727 20000000431 20120429 has 2 rows for different time (i.e. 015000,030000)
I need to show
80013727 20000000431 20120429 count1(from 1st row),count1(from 2nd row)
80013727 20000000431 20120429 count2(from 1st row),count2(from 2nd row)
Obviously you have simplified your data and your output structure. I'm guessing you'll end up with 96 count columns (although I'm not going that far either).
with cte as
( select * from your_table )
select id
, subid
, date
, type
, sum(c01) as "00:00:00-00:14:59"
, sum(c02) as "00:15:00-00:29:59"
, sum(c96) as "23:45:00-23:59:59"
from (
select id
, subid
, date
, 'C1' type
, case when time between 0 and 899 then count1 else 0 end as c01
, case when time between 900 and 1799 then count1 else 0 end as c02
, case when time between 85500 and 86399 then count1 else 0 end as c96
from cte
union all
select id
, subid
, date
, 'C2' type
, case when time between 0 and 899 then count2 else 0 end as c01
, case when time between 900 and 1799 then count2 else 0 end as c02
, case when time between 85500 and 86399 then count2 else 0 end as c96
)
group by id, subid, date, type
order by id, subid, date, type
So, this use a sub-query factoring expression to select only once from your table. It uses case() to assign counts to a specific time column, on the basis of a range of seconds. There are two queries to aggregate the counts for lines 1 and 2.
The sum() calls may be unnecessary; it's not clear from your data whether you have more than one record in each time slot.

Resources