ããã«æ¸ããã¦ããæ¹æ³ã«ã¯èª¤ããããã¾ã。æ£ããæ¹æ³ãå¥éæ¸ãã¾ããã®ã§、ãã¡ããåããã¦èªãã§ä¸ãã。
Cocoaã®æ¥ã : [Mac][iOS] NSPredicate - ï¼å¯¾å¤é¢é£ã®ã¨ã³ãã£ãã£ã®æ¤ç´¢æ¡ä»¶è¦æ¬(è¨æ£〜ãµãã¯ã¨ãªã¼ã®å©ç¨)
ãé¡
ãããªï¼å¯¾å¤ã®ã¨ã³ãã£ãã£ããã£ãã¨ãã。
çºå£²æ¥(Book.date)ãæå®æ¥ä»¥éã®æ¬ãæ¸ããèè (Author)ã®ä¸è¦§ãåå¾ããã。ãã®æã®æ¡ä»¶(NSPredicate)ã¯ã©ãæ¸ãã¹ãã。
æ¡ä»¶è¦æ¬
NSPredicate ã§ã¯ãã¼ãã¹ãæå®ã§ããã®ã§æ¥ä»ã®æ¡ä»¶ã¯ããæ¸ãã。
books.date <= %@Author ã«å¯¾ãã¦ãã®æ¡ä»¶ãæããããã ã、ä»åçµæã¨ãã¦æ¬²ããã®ã¯èè ã®ä¸è¦§ãªã®ã§è©²å½ãã Bookãåå¨ãã Authorã ãã帰ã£ã¦ããããã«ããã。ãã®å ´å㯠ANY ãã¤ãã¦ãã。
ANY books.date <= %@Author ã対象ã¨ããæ¤ç´¢æ¡ä»¶ NSPredicate ã¯ãããªã。
NSPredicate* p = [NSPredicate predicateWithFormat:@"ANY books.date <= %@", date];å®éã«çºè¡ããã¦ããSQLæã確èªãã¦ã¿ãã。
SELECT DISTINCT 0, t0.Z_PK FROM ZAUTHOR t0 JOIN ZBOOK t1 ON t0.Z_PK = t1.ZAUTHOR WHERE t1.ZDATE >= ?親åã®ãã¼ãã«ãJOINãã¦、æ¡ä»¶ã«ãããããã¬ã³ã¼ããDISTINCTã使ã£ã¦éè¤ããªããã¦ãã。æå³éãã 。SQLã®EXISTSã使ãã°ããå°ãå¹çãä¸ãããããã§ã¯ããã件æ°ãå¤ããªããã°ããã§ãåå。
æ¡ä»¶ãè¤æ°
ããä¸ã¤æ¡ä»¶ãå ãã¦、ããæéå ã«çºå£²ãããæ¬ãæ¸ããèè ã®ä¸è¦§ãåå¾ãã。åç´ã«æ¡ä»¶ãå ãã¦ã¿ãã¨ãããªæã。
ANY (books.date >= %@ AND books.date < %@)ããã¯å®ã¯NG。NSInvalidArgumentException (Unsupported predicate) ãçºçãã。æ£è§£ã¯ãã。
ANY books.date >= %@ AND ANY books.date < %@ANY ãããããã®é ã«ã¤ãã¦ãã。
SQLã¯ãããªã。
SELECT DISTINCT 0, t0.Z_PK FROM ZAUTHOR t0 JOIN ZBOOK t1 ON t0.Z_PK = t1.ZAUTHOR JOIN ZBOOK t2 ON t0.Z_PK = t2.ZAUTHOR WHERE ( t1.ZDATE >= ? AND t2.ZDATE < ?)ï¼å JOINããã¦ããã®ãã¢ã¬ã ã、ã¾ãæå³éãã®åãã«ã¯
åè
ç¯å²æ¡ä»¶æå®ã«ã¯ BETWEEN ã¨ããã®ããã。
(ä¾) NSNumber *one = [NSNumber numberWithInteger:1]; NSNumber *ten = [NSNumber numberWithInteger:10]; NSPredicate *betweenPredicate = [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", [NSArray arrayWithObjects:one, ten, nil]];ãã NSDate ãæ¡ä»¶ã«ããå ´åä¾å¤ãåºã¦ãã¾ã£ã。使ãæ¹ãã¾ããã®ãä»æ§ãªã®ã。
.
Responses
Leave a Response