Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7182283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:44:16+00:00 2026-05-28T17:44:16+00:00

I have created an sqlite table using the following statement: CREATE TABLE IF NOT

  • 0

I have created an sqlite table using the following statement:

"CREATE TABLE IF NOT EXISTS reminders (ID INTEGER PRIMARY KEY,Name VARCHAR(64), Event VARCHAR(64), Date VARCHAR(64), Bfr VARCHAR(64), Val VARCHAR(64),Num VARCHAR(64), Bod VARCHAR(400) ,Grp VARCHAR(64))";

I have successfully inserted data and retrieved data from sqlite database and displayed the reminders in view reminders too programmatically!

But I am struck with deletion of records from sqlite database.I mean I have used a model class to hold the values like name,event,date etc…In add reminder page,I have assigned the values for the variables declared in the model class,i.e.

textField.text = remClass.Name etc..

My description might sound confusing,but the above information is always useful to answer this question with ease.

I have add reminder page,where user enters data and clicks save,then data gets inserted in to database.There is View Reminders page where the user can view the saved reminder.In that there are 3 different ways to view reminders:viewAll,viewMonthly,viewGroup.Now in view all I was able to display the unique ID for every reminder using the following statement:

ReminderClass *loadedReminder = [[ReminderClass alloc] init];

loadedReminder.reminderID = sqlite3_column_int(statement, 0); 

Where reminder class is a model class which holds all the values entered in add reminder page.

In order to display the saved reminder,I have used an array and added the model class object after retrieving every row,i.e. id,name,event,date etc.. and populated the table view accordingly.Say if i save 3 reminders,then sections are 3 like wise and so on…

Now if I click the edit button in view group reminders page,then as we know we can delete the row(section) of table view by clicking the orientation button on left.

If I delete the row,say a row with reminder.Then the data corresponding to that reminder should also be deleted from sqlite database.

How can I do this,I have gone through this link sounds similar to my requirement.But its not working.

Finally I have implemented the following code for deletion:

if (editingStyle == UITableViewCellEditingStyleDelete) 
    {        
        [self.grpArray objectAtIndex:indexPath.section];

        if(sqlite3_open([databasePath UTF8String], &remindersDB)==SQLITE_OK)
        {   
            sqlite3_stmt *compiledstatement;

            int pk = sqlite3_column_int(compiledstatement, 0);
            NSString *querySQL = [NSString stringWithFormat:@"delete from reminders where ID = %i",pk];

            const char *sqlstmt=[querySQL UTF8String];

            if(sqlite3_prepare_v2(remindersDB, sqlstmt, -1, &compiledstatement, NULL)==SQLITE_OK)
            {                
                if(SQLITE_DONE != sqlite3_step(compiledstatement))

                    NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(remindersDB));
            }
            NSLog(@"delete DONE");
            sqlite3_finalize(compiledstatement);
        }
        sqlite3_close(remindersDB);

        [self.gTable reloadData];
    }

RETRIEVAL CODE:

-(void)loadgReminders
{

    EventsReminderAppDelegate *appDelegate = (EventsReminderAppDelegate *)[[UIApplication sharedApplication]delegate];
    NSLog(@"String = %@",appDelegate.groupString);

    self.grpArray = nil;
    self.grpArray = [[NSMutableArray alloc]init];

    //Retrieve the group of reminder
    const char *thePath = [self.databasePath UTF8String];
    sqlite3_stmt *statment;

    if (sqlite3_open(thePath, &remindersDB) == SQLITE_OK)
    {
        NSString *getQuery = [NSString stringWithFormat:@"SELECT * FROM reminders WHERE Grp = '%@' ORDER BY Date ASC",appDelegate.groupString];
        const char *sqlite_stmt = [getQuery UTF8String];

        if (sqlite3_prepare_v2(self.remindersDB, sqlite_stmt, -1, &statment, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(statment) == SQLITE_ROW) 
            {
                ReminderClass *remind = [[ReminderClass alloc]init];
                remind.reminderID = sqlite3_column_int(statment, 0);
                **NSLog(@"reminderID=%d",remind.reminderID);**
                remind.Name = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 1)];
                remind.Event = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 2)];
                remind.Date = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 3)];
                remind.numDays = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 4)];
                remind.selString = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 5)];
                remind.number = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 6)];
                remind.msgBody = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 7)];
                remind.remGroup = [[NSString alloc]initWithUTF8String:(const char *)sqlite3_column_text(statment, 8)];

                NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
                [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                NSDate *date = [dateFormat dateFromString:remind.Date];
                [dateFormat setDateFormat:@"MMMM dd"];
                NSString *dateVal = [dateFormat stringFromDate:date];
                remind.Date = dateVal;

                [self.grpArray addObject:remind];

                [remind release];
            }

            sqlite3_finalize(statment);
        }

        sqlite3_close(remindersDB);
    }
}

There I used NSLog for checking whether reminder ID values are getting displayed properly or not it is getting displayed as:

enter image description here

But what’s wrong when I try to do the same with deletion to retrieve the id values and assign that id value to where id=?.

It’s not working, where am I wrong?

Can any one please help me out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:44:17+00:00Added an answer on May 28, 2026 at 5:44 pm

    You can do like this. This will definitely work out

    if (editingStyle == UITableViewCellEditingStyleDelete) 
            {
    
                NSString *dbPath = [self getDBPath];
    
                NSString *couponIdValue = [listOfCouponId objectAtIndex:indexPath.row];
    
    
                if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
    
                    const char *sql = "delete from reminders where ID = ?";
                    sqlite3_stmt *deletestmt;
                    if(sqlite3_prepare_v2(database, sql, -1, &deletestmt, NULL) != SQLITE_OK) {
                        NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database));
                    }
    
    
    
                    sqlite3_bind_int(deletestmt, 1, [IdValue intValue]);
    
    
                    if (SQLITE_DONE != sqlite3_step(deletestmt)) 
                        NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database));
    
    
                    sqlite3_reset(deletestmt);
    
    }
    

    pass the value of id in sqlite3_bind_int() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created tables in android sqlite using create statement and also inserted values
I have a database/table in SQLITE using the following structure CREATE TABLE milestones (
Given the following schema: CREATE TABLE players ( id BIGINT PRIMARY KEY, name TEXT
I have a table in SQLite: CREATE TABLE test_results(timestamp TEXT, npass INTEGER, nfails INTEGER)
I have created an SQLite FTS3 table that I am using within the Android
I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation
I have installed SQLite and am using the wrapper from: http://sqlite.phxsoftware.com/ I have created
I am new to using the SQLite database in iphone apps. I have created
I have a table: CREATE TABLE [Lines] ( [Value] TEXT NOT NULL, [AddedOn] TIMESTAMP
I have already created a table to the database. Table is something like following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.