Delete data from sqlite3 based on time

Source: Internet
Author: User

Delete based on time

-(void) Deletedatawithtime: (NSString *) time at: (NSString *) tablename{

NSString *deletesql = @ "Delete from lbbmestable where Id =?";

NSString *tab = [TableName stringbyreplacingoccurrencesofstring:@ ". db" withstring:@ ""];

NSString *deletesql = [NSString stringwithformat:@ "Delete from%@ where time <?", Tab];

NSData *messagedata = [message datausingencoding:nsutf8stringencoding];

NSString *path = [Nshomedirectory () stringbyappendingstring:[nsstring stringwithformat:@ "/Documents/%@", TableName]] ;

_database = [Fmdatabase Databasewithpath:path];

if ([_database Open]) {

if (![ _database Executeupdate:deletesql,time]) {

NSLog (@ "Delete error:%@", _database.lasterrormessage);

}

}

[_database Close];

}

This allows the data to be deleted directly, where time is stored as a string, equivalent to the comparison string,

Calculate the distance now how many seconds, the return is the full string of time, such as 2014-01-04 06:06:06, if the incoming negative, it is the previous time

+ (NSString *) Timestrsincenow: (nstimeinterval) timeinterval{

nsdate* dat = [NSDate datewithtimeintervalsincenow:timeinterval];//calculates a time before so much time

NSDateFormatter *formatter=[[nsdateformatter alloc] init];

[Formatter setdateformat:@ "Yyyy-mm-dd HH:mm:ss"];

NSString *pasttime = [Formatter stringfromdate:dat];

return pasttime;

}

Delete data from sqlite3 based on time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.