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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:41:49+00:00 2026-06-10T17:41:49+00:00

i am trying to insert into sqlite database using objective c, the following is

  • 0

i am trying to insert into sqlite database using objective c,
the following is my code:

-(void)insertCustomer:(CustomerDetails *)cd{

CustomerDetails *cDetails=[[CustomerDetails alloc] initWithIdNumber:cd.idNumber name:cd.name surname:cd.surname];

NSString *name= cDetails.name;
NSString *surname=cDetails.surname;
NSString *idNumber=cDetails.idNumber;


NSString *insertQuery=[NSString stringWithFormat:@"INSERT INTO CUSTOMER_DETAILS(Name,Surname,ID_Number) VALUES(?,?,?);"];
sqlite3_stmt *insertStatement;
sqlite3_prepare_v2(database, [insertQuery UTF8String], 1, &insertStatement, NULL);

sqlite3_bind_text(insertStatement, 1,[name UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 2,[surname UTF8String], -1, SQLITE_TRANSIENT);
    sqlite3_bind_text(insertStatement, 3,[idNumber UTF8String], -1, SQLITE_TRANSIENT);

sqlite3_step(insertStatement);
sqlite3_finalize(insertStatement);
sqlite3_close(database);

}

this is not inserting anything, also when i debug insertStatement seems to be null
i am new to objective c so would appreciate any help 🙂

Thanks

  • 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-06-10T17:41:50+00:00Added an answer on June 10, 2026 at 5:41 pm

    The third parameter of sqllite3_prepare_v2 is the number of bytes to read from the SQL statement. Since you are passing 1, one byte is read, in other words you are trying to execute the SQL statement "I". This is not going to work, and sqllite_prepare_v2 is probably failing and therefore not assigning anything to insertStatement – but since you are not checking the return value for an error code, your code just continues on.

    You can pass -1 to have the prepare function read until the null terminator of the UTF8 string. In other words, this should work:

    sqlite3_prepare_v2(database, [insertQuery UTF8String], -1, &insertStatement, NULL);
    

    Also, you really should check for errors when using the sqllite API in your code; this will likely avoid or explain other issues in the future. According to the docs:

    On success, the sqlite3_prepare() family of routines return SQLITE_OK;
    otherwise an error code is returned.

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

Sidebar

Related Questions

I'm trying to insert data into the SQLite database using get EditText, but I
I am trying to insert a data into SQLite database using Python. INSERT INTO
I'm trying to insert new records into SQLite database from Python code. con =
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
I am trying to execute INSERT sqlite statements into my database using a method
I'm trying to adapt my database dump into SQLite format, using the following command:
i'm trying to insert some data on a database using this code: -(void)insertLocationOnDatabase:(LocationType *)aLocation
I'm tring to insert some records into my Sqlite database using the Entity Framework.
I am trying to insert into my database table using the database helper class.
I am trying to insert a datetime value into a SQLite database. It seems

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.