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 6220189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:54:54+00:00 2026-05-24T07:54:54+00:00

I am having problems when inserting data into a sqlite table, I have read

  • 0

I am having problems when inserting data into a sqlite table, I have read lots of posts but still not found any solution, hope you can help me.

My table definition is:

CREATE TABLE "forum_topics" ("id" INTEGER (11) PRIMARY KEY  NOT NULL  UNIQUE  DEFAULT 1, "id_user" INTEGER (11) NOT NULL  DEFAULT 0, "title" TEXT NOT NULL  DEFAULT None, "description" TEXT NOT NULL  DEFAULT None)

I am having that problem when executing the following function:

- (void)addTopic{
    if (addStmt == nil) {
        const char *sql = "INSERT INTO forum_topics (id_user, title, description) VALUES (?, ?, ?)";
        if (sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK) {
            NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
        }
    }
    sqlite3_bind_int(addStmt, 1, id_user);
    sqlite3_bind_text(addStmt, 2, [title UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(addStmt, 3, [desc UTF8String], -1, SQLITE_TRANSIENT);


    if (SQLITE_DONE != sqlite3_step(addStmt)) {
        NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
    }
    else {
        self._id = sqlite3_last_insert_rowid(database);
    }
    sqlite3_reset(addStmt);
    sqlite3_finalize(addStmt);
    addStmt = nil;
}

Well, I also tried to force binding the id column of the table, and it did not crash despite of the fact that id has PRIMARY KEY and UNIQUE constraints and it is supposed to be unsettable…
Any suggestion? Thank you.

  • 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-24T07:54:55+00:00Added an answer on May 24, 2026 at 7:54 am

    Can you tell us what error you are getting?
    Is you id_user variable is a real integer, if not then i = [id_user intValue];

    Because there is an sql error column id is not unique when your inserting the row second time.

    You are inserting the new record by specifying column name, but you are not specifying the value for ‘id’ column so it assume the default value 1, but which is already set to table when you insert the first record.

    INSERT INTO forum_topics (id_user, title, description) VALUES (2,’A’ , ‘A’); //very first time

    but when you are inserting second time you are not specifying the value for ‘id’ column and default value for this column is 1 (but it is already saved when you insert the record first time).
    so if you want to avoid you must specify the ‘id’ column value unique

    INSERT INTO forum_topics (id,id_user, title, description) VALUES (2,2,’A’ , ‘A’);// now this will insert the row successfully.
    Change the schema to

    CREATE TABLE "forum_topics" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "id_user" INTEGER (11) NOT NULL  DEFAULT 0, "title" TEXT NOT NULL  DEFAULT None, "description" TEXT NOT NULL  DEFAULT None);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am having problem inserting data into multiple table from one view. First
I'm having a strange problem in that I have php inserting text into a
I'm having performance problems when inserting many rows into a GTK treeview (using PyGTK)
This is a rather simple question, I am having problems inserting data from Javascript
I'm having problems with adding another primary key to my table. I have 3
Im having problems building a query with the linq to sql data query expression
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
I am having problems getting text within a table to appear centered in IE.
I am having problems manually looping through xml data that is received via an
I am still having problems with figuring out how to create winforms in a

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.