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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:43:39+00:00 2026-06-05T06:43:39+00:00

I have changed the code based on my understanding of the different answers I

  • 0

I have changed the code based on my understanding of the different answers I received on my previous post. The code is as follows:

float lastClicked = 0.0;

- (void)viewDidLoad
{
[super viewDidLoad];

NSString *contentDirectory;
NSArray *directoryPath;
const char *dbpath = [databasePath UTF8String];

directoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
contentDirectory = [directoryPath objectAtIndex:0];

databasePath = [[NSString alloc] initWithString: [contentDirectory stringByAppendingPathComponent: @"MCFRatingDatabase.db"]];

NSFileManager *filemanager = [NSFileManager defaultManager];
if ([filemanager fileExistsAtPath:databasePath] == NO){


    if (sqlite3_open(dbpath, &connectDB) == SQLITE_OK)
    {
        char *errorMessage;
        const char *sql_stmt = "CREATE TABLE IF NOT EXISTS IMAGERATING (CONTENTNAME STRING, RATING FLOAT)";
        if (sqlite3_exec(connectDB, sql_stmt, NULL, NULL, &errorMessage) != SQLITE_OK)
        {
            NSLog(@"FAILED TO CREAT TABLE");
        }
        sqlite3_close(connectDB);

    } else {
        NSLog(@"FAILED TO OPEN/CREATE DATABASE");
    }
}
[filemanager release];

sqlite3_stmt *statement;

if (sqlite3_open(dbpath, &connectDB) == SQLITE_OK)
{
    NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM IMAGERATING WHERE CONTENTNAME = '%@'", titleString];
    const char *query_stmt = [querySQL UTF8String];

    if (sqlite3_prepare_v2(connectDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            display = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 1)];
            rate = sqlite3_column_double(statement, 2);
            NSLog(@"contents are name = %@ and rating = %f", display, rate);                
        }else{

        }
        sqlite3_finalize(statement);
    }
    sqlite3_close(connectDB);
}    
}


-(IBAction)rateSubmitClick:(id)sender{

sqlite3_stmt *statement;
NSString *insertSQL;

const char *dbpath = [databasePath UTF8String];

if (sqlite3_open(dbpath, &connectDB) == SQLITE_OK){

    if(isHalfClicked){
        rating = lastClicked + 0.5;
        insertSQL = [NSString stringWithFormat: @"INSERT INTO IMAGERATING (CONTENTNAME, RATING) VALUES (\"%@\", %f)", titleString, rating];
    }else{

        rating = lastClicked;
        insertSQL = [NSString stringWithFormat: @"INSERT INTO IMAGERATING (CONTENTNAME, RATING) VALUES (\"%@\", %f)", titleString, rating];
    }

    const char *insert_stmt = [insertSQL UTF8String];

    sqlite3_prepare_v2(connectDB, insert_stmt, -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE){

        NSLog(@"Added records are = %@  %f", titleString, rating);
        isRated=YES;
    }else{
        NSLog(@"FAILED TO ADD RECORD");
    }
    sqlite3_finalize(statement);
    sqlite3_close(connectDB);
}   
}

But now the problem is nothing is getting inserted. Log shows “FAILED TO ADD RECORD”.

I am really messed up with this database stuff and need your help.

  • 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-05T06:43:40+00:00Added an answer on June 5, 2026 at 6:43 am

    You are wrapping your integer/float values in the insert statement with quotes. Don’t do that.

    Your SQL stement should look like:

    INSERT INTO USERRATING (CONTENTNAME, RATING) VALUES ("mycontentname", 4.5);
    

    as an example.

    Or put another way, your code should be:

     if(isHalfClicked)
        {
            rating=lastClicked+0.5;
            insertSQL = [NSString stringWithFormat: @"INSERT INTO USERRATING (CONTENTNAME, RATING) VALUES (\"%@\", %f)",titleString,rating];
        }
        else {
    
            insertSQL = [NSString stringWithFormat: @"INSERT INTO USERRATING (CONTENTNAME, RATING) VALUES (\"%@\", %d)",titleString,lastClicked ];
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code as follows: $(#item_select).change(function() { var params = $(#item_select option:selected).val(); $.post('/account/ar_form.php', {idata:
EDIT, Changed the code slightly based on answers below, but still haven't got it
I have changed a lot of things in a java code but now I
I have the following code (changed object names, so syntax/spelling errors ignore). public class
I have following code which works for radio buttons but need to be changed
I have a segmentation fault in the code below, but after I changed it
What do I have to change in the following code to make the A
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
Anything I have tried didn't work. Currenly I have following code to change asp.net
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes

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.