RRULE parsing in Postgresql

﹥>﹥吖頭↗ 提交于 2019-12-04 12:42:46

There are two obvious pointer-related flaws in the code shown:

First:

    *rrule = PG_GETARG_CHAR(0);

At this point of execution, rrule is a non-initialized pointer, and this instruction tries to write a char into the random location it points to. This generally causes the kind of crash you're seeing.

Second:

time_t   *result[count]; /* output array */

icalrecur_expand_recurrence(rrule, start, count, *result);

result should be an array of time_t, not an array of time_t*, and it should be passed as result, not *result which again is not initialized at this point.

Now you can use this extension for postgresql.

Example usage:

SELECT * FROM
     unnest(
         rrule_get_occurrences('FREQ=WEEKLY;INTERVAL=1;WKST=MO;UNTIL=20200101T045102Z;BYDAY=SA;BYHOUR=10;BYMINUTE=51;BYSECOND=2'::rrule,
             '2019-12-07 10:51:02+00'::timestamp with time zone)
     );

          unnest
 ------------------------
  2019-12-07 10:51:02+00
  2019-12-14 10:51:02+00
  2019-12-21 10:51:02+00
  2019-12-28 10:51:02+00
 (4 rows)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!