Android,sqlite,如何自动插入日期记录?

时间:2013-10-31 12:03:44

标签: android sqlite

 -_id   -lesson_id  -start_time -SUMDUEDURATION -COUNTDUEDURATION   -INTERVAL
    -105    -1  -2013-10-16 07:26:52.000    -92736  -9  -301418
    -108    -1  -2013-10-18 07:03:52.000    -164282 -3  -555779
    -116    -1  -2013-10-21 11:49:44.000    -1455866-7  -3533900
    -128    -1  -2013-10-22 11:12:55.000    -53795  -12 -108334
    -132    -1  -2013-10-30 03:27:46.000    -2036   -1  -663295276

以下是用户操作表中的记录,仅在该月的几天,是否有像MySQL这样的事件计划自动插入其他日期。

我使用它来越过日期表,但还不够好:

select _id,lesson_id,start_time, ifnull(sum,0) as SUMDUEDURATION, ifnull(COUNT,0) as COUNTDUEDURATION, ifnull(interval, 0) as INTERVAL
from dates left join (
SELECT month,_id, lesson_id, sum(duration) as sum,count(_id) as count,interval, 
start_time,end_time,
max(date(" + START_TIME + ", 'weekday 0', '-7 day')) as WeekStart,
max(date(" + START_TIME + ", 'weekday 0', '-1 day')) as WeekEnd
FROM user_action where lesson_id = 1 group by month )  monthdate  using(month)  
where strftime('%Y%m',date) = strftime('%Y%m','now')

2 个答案:

答案 0 :(得分:0)

您可以创建一个Service并在您需要时使用它来添加行(例如,在启动时完成,每周一次,等等)。

Here you have good tutorial,如何在Android操作系统中创建服务。

请阅读有关AlarmManager的更多信息,以便按特定时间表启动您的服务。

Calendar cal = Calendar.getInstance();

Intent intent = new Intent(this, MyService.class);
PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);

AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
// Start every 30 seconds
alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 30*1000, pintent); 

答案 1 :(得分:0)

据我所知,这只能通过时间戳来实现,而不是使用日期时间。 这是一个简短的示例,如何添加默认时间戳。

create table test (str varchar(32), ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

编辑:没关系,我不知怎的想你想要mysql。