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

  • SEARCH
  • Home
  • 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 937231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:26:36+00:00 2026-05-15T21:26:36+00:00

Hey what i want to do is update a table if the field exsits

  • 0

Hey what i want to do is update a table if the field exsits or insert the new value as given by the user.

For this what i do is select everything present in the table and check if the name entered by the user exists den update it or else insert it.

However the problem is when there is no data in the table the query fails and no data is inserted in the table.

NSString *query = @"select * from PPM";
sqlite_stmt *statement;

if(sqlite_prepare_v2(database,[query UTF8string],-1,&statement,NULL) == SQLITE_OK)
{
    while (sqlite3_step(statement) == SQLITE_ROW)
     //select data from table  
     //if value entered is same as entered by user update the table
     //else insert in the table
}
  • 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-15T21:26:37+00:00Added an answer on May 15, 2026 at 9:26 pm

    How about INSERT OR REPLACE ?
    You can use it with the UNIQUE constraints in your database structure to replace a value if it already exists, and insert it if it not there already.

    shell> sqlite3
    SQLite version 3.6.23
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> CREATE TABLE user(name UNIQUE, value);
    sqlite> INSERT OR REPLACE INTO user VALUES("foo", 123);
    sqlite> SELECT * FROM user;
    foo|123
    sqlite> INSERT OR REPLACE INTO user VALUES("foo", 321);
    sqlite> SELECT * FROM user;
    foo|321
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all, I want to change a value in a table (in a mysql
Hey guys quick question, I want to update the contents of a div with
Hey I want to select records with name O'Neil, How can i do that
Hey guys, I want to store a categorized list of URLs. This is an
Hey, I'm struggling to copy the Primary Key to another field in Access. This
Hey peepz! I have this footer image, that I want to align to the
Hey i want to use php to redirect a user to a url depending
//Introduction Hey, Welcome..... This is the tutorial //EndIntro //Help1 Select a Stock To use
Hey i want to change the name attribute of a table once the row
hey i want to display a loading progress using ProgressDialog on my aplication, but

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.