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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:18:48+00:00 2026-06-10T10:18:48+00:00

i have a view Controller called as VegQuantity which does totalcost=(quantity*cost of the dish)

  • 0

i have a view Controller called as VegQuantity which does totalcost=(quantity*cost of the dish) and inserts the itemname,quantity,totalcost into a table called as FINALORDER with database name FinalOrder

sqlite3_stmt    *statement;

const char *dbpath = [databasePath UTF8String];

if (sqlite3_open(dbpath, &FinalOrder) == SQLITE_OK)
{
    NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO FINALORDER (itemname, quantity, totalcost) VALUES (\"%@\", \"%@\", \"%@\")", itemName.text, input.text, output.text];

    const char *insert_stmt = [insertSQL UTF8String];

    sqlite3_prepare_v2(FinalOrder, insert_stmt, -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        //  status.text = @"Contact added";
        //  name.text = @"";
        //  address.text = @"";
        //  phone.text = @"";
        NSLog(@"added");
    } else {
        NSLog(@"Couldnt add");
    }
    sqlite3_finalize(statement);
    sqlite3_close(FinalOrder);
}

Final View Controller viewdidload method

const char *dbpath = [databasePath UTF8String];
sqlite3_stmt    *statement;

if (sqlite3_open(dbpath, &FinalOrder) == SQLITE_OK)
{
    NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM FINALORDER"];

    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(FinalOrder, query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            NSString *itemname = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
            item.text = itemname;

            NSString *qua = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
            quantity.text = qua;

            NSString *total = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 2)];
            totalcost.text=total;
        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(FinalOrder);
}

But i keep getting this error called expected expression before FinalOrder,and is it correct for me to write this code inside viewdidload? i dont have any button in Final view controller i have a button called order in a view controller called as Restaurant which actually shows me Final view controller..am i supposed to search for the db file again in the Final viewcontroller and i am sorry question seems kind of vague but in brief i just want to know how to retrieve and display the data which i have inserted in VegQuantity view controller into the final view controller 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-10T10:18:49+00:00Added an answer on June 10, 2026 at 10:18 am

    I believe that the problem must rest in the definition of FinalOrder which, on the basis of the error message, looks like has been defined as a class, not as a sqlite3 * variable. Given that the scope of your usage of the database is limited to these two methods, I’d suggest defining a sqlite3 * within that scope, and use that, such as:

    - (void)saveRecord
    {
        sqlite3      *database;
        sqlite3_stmt *statement;
        const char   *dbpath = [databasePath UTF8String];
    
        if (sqlite3_open(dbpath, &database) == SQLITE_OK)
        {
            [self purgeTable:database];
    
            NSString *insertSQL = @"INSERT INTO FINALORDER (itemname, quantity, totalcost) VALUES (?, ?, ?)";
    
            if (sqlite3_prepare_v2(database, [insertSQL UTF8String], -1, &statement, NULL) == SQLITE_OK)
            {
                sqlite3_bind_text(statement, 1, [itemName.text UTF8String], -1, NULL);
                sqlite3_bind_int(statement, 2, [input.text intValue]);
                sqlite3_bind_double(statement, 3, [output.text doubleValue]);
    
                if (sqlite3_step(statement) == SQLITE_DONE)
                {
                    //  status.text = @"Contact added";
                    //  name.text = @"";
                    //  address.text = @"";
                    //  phone.text = @"";
                    NSLog(@"added");
                } else {
                    NSLog(@"%s Couldn't add; errmsg='%s'", __FUNCTION__, sqlite3_errmsg(database));
                }
                sqlite3_finalize(statement);
            } else {
                NSLog(@"%s Couldn't prepare; errmsg='%s'", __FUNCTION__, sqlite3_errmsg(database));
            }
    
            sqlite3_close(database);
        }
    }
    

    Note, in addition to using a sqlite3 * variable for the database, to make this a little more robust:

    1. I have replaced the stringWithFormat statement that built the SQL insert statement with an INSERT statement that uses the ? placeholders and then use sqlite3_bind_text to bind values to that statement. This way, if someone entered a value that included a quotation mark, the insert statement will still work (your original implementation would have crashed and/or was susceptible to a SQL injection attack).

    2. I have also added the sqlite3_errmsg statements so if something goes wrong, I know what the problem was.

    3. Rather than treating these three fields as text fields, I’m assuming your table is defined as CREATE TABLE IF NOT EXISTS FINALORDER (itemname TEXT, quantity INT, totalcost REAL); and therefore use text, int, and double bind statements.

    This, incidentally, invokes a purgeTable method, so if you run it twice, it will remove the old record in there:

    - (void)purgeTable:(sqlite3 *)database
    {
        if (sqlite3_exec(database, "DELETE FROM FINALORDER;", NULL, NULL, NULL) != SQLITE_OK)
            NSLog(@"%s Couldn't purge table %s", __FUNCTION__, sqlite3_errmsg(database));
    }
    

    Anyway, you can then read this data via:

    - (void)loadRecord
    {
        sqlite3      *database;
        const char   *dbpath = [databasePath UTF8String];
        sqlite3_stmt *statement;
    
        if (sqlite3_open(dbpath, &database) == SQLITE_OK)
        {
            NSString *querySQL = @"SELECT * FROM FINALORDER";
    
            if (sqlite3_prepare_v2(database, [querySQL UTF8String], -1, &statement, NULL) == SQLITE_OK)
            {
                if (sqlite3_step(statement) == SQLITE_ROW)
                {
                    NSString *itemname = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
                    item.text = itemname;
                    //[itemname release]; // if not ARC, uncomment this line
    
                    int qua = sqlite3_column_int(statement, 1);
                    quantity.text = [NSString stringWithFormat:@"%1d", qua];
    
                    double total = sqlite3_column_double(statement, 2);
                    totalcost.text = [NSString stringWithFormat:@"%1.2f", total];
                }
                sqlite3_finalize(statement);
            } else {
                NSLog(@"%s Couldn't prepare; errmsg='%s'", __FUNCTION__, sqlite3_errmsg(database));
            }
            sqlite3_close(database);
        }
    }
    

    Note,

    1. I’ve added a sqlite3_errmsg log statement if the sqlite3_prepare fails, and I’ve retired the stringWithFormat (because you weren’t formatting anything).

    2. Given that quantity was INT and total was REAL, I’m retrieving the values using the appropriate variation of sqlite3_column_text, sqlite3_column_int, or sqlite3_column_double, as appropriate.

    3. I infer that you’re not using ARC and therefore, the [NSString alloc] must have an associated release or autorelease.

    Finally, in our chat, you said that you received an error message (presumably an “Undefined Symbols” message) that said:

    OBJC_CLASS_$"_FinalOrder"
    

    This means that you are trying to use an object class of FinalOrder, but you haven’t defined that class anywhere. Take a look at which .o files it’s reporting this error for and look at the corresponding .m file, and look for your use of the FinalOrder class there. You clearly have a FinalOrder class interface defined somewhere, but never defined the class implementation, or, if you have one, for some reason it’s not included in your target’s “Compile Sources” listing, so double check it’s here:

    Add compile source

    Finally, by the way, make sure your database is in the Documents folder, not trying to open a copy of the database in your project’s bundle (because that’s read only). If you have a copy of the database in your bundle, just check to see if you already have it in you Documents folder, and if not, copy it from the bundle to the Documents folder.

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

Sidebar

Related Questions

Ok, so here's the situation. I currently have a view controller called MainViewController which
Hi guys i have controller which returns a partial view, the controller is called
I have view controller, into the view i have put a table view, and
I have a View Controller, called TVOutViewController (.h & .m) which should handle my
I have implemented a view controller with a table view controll called ligatable. This
I have a table view controller that makes an http request, which returns xml.
Let's say I have a view controller called vc1, which a synthesized property called
I have a one View Controller Called ThemeViewController with three nibs, all of which
I have a controller called Diary with an action called View . If I
I have a segue (called ToSettingsSegue ) that pushes a custom view controller (

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.