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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:35:35+00:00 2026-05-29T05:35:35+00:00

I have an SQLite database in my iOS application. I’m trying to use the

  • 0

I have an SQLite database in my iOS application. I’m trying to use the SQL function MAX()

- (void) getMaxTime {

if (sqlite3_open([databasePath UTF8String], &timingsDatabase) == SQLITE_OK) 
{
    NSString *maxTimeStatement = [NSString stringWithFormat:@" SELECT max(NUMBERS) FROM TIMINGS"];
    sqlite3_stmt *statement;
    if(sqlite3_prepare_v2(timingsDatabase, [maxTimeStatement UTF8String], -1, &statement, nil) == SQLITE_OK){
        while (sqlite3_step(statement) == SQLITE_ROW) {
            massimo = sqlite3_column_int(statement, 0);

            NSLog(@"The maximun time is %d seconds ", massimo);
        } 
        sqlite3_finalize(statement);
        sqlite3_close(timingsDatabase);     
    }      
}

All the numbers in the column NUMBERS have 6 digits after the coma.
Everything works fine if all the numbers are > 10 or all the numbers are <10.

But (example) when I try to get the max among:

  • 1.339670
  • 2.955537
  • 11.355558

It prints: “The maximun time is 2 seconds” (instead of 11)! I’m struggling to understand why.

*EDIT

This is how my Database was created:

-(void)createDatabase 
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    databasePath = [[NSString alloc]initWithString:[documentsDirectory stringByAppendingPathComponent:@"timings.db"]];

    if ([[NSFileManager defaultManager] fileExistsAtPath:databasePath] == FALSE)
    {
        if (sqlite3_open([databasePath UTF8String], &timingsDatabase) == SQLITE_OK)
        {
            const char *sqlStatement = "CREATE TABLE IF NOT EXISTS TIMINGS (ID INTEGER PRIMARY KEY AUTOINCREMENT, TIMESTAMP TEXT, TIMING TEXT, NUMBERS TEXT)";
            char *error;
            sqlite3_exec(timingsDatabase, sqlStatement, NULL, NULL, &error);
            sqlite3_close(timingsDatabase);
        }
    }
}

And this is how timings are stored:

-(void)storeTiming 
{
    if (sqlite3_open([databasePath UTF8String], &timingsDatabase) == SQLITE_OK)
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"HH:mm:ss.SSS"];

        NSString *insertStatement = [NSString stringWithFormat:@"INSERT INTO TIMINGS (TIMESTAMP, TIMING, NUMBERS) VALUES (\"%@\", \"%@\", \"%f\")", [dateFormatter stringFromDate:startDate], stopWatchLabel.text , intervallo] ;


        char *error;
        sqlite3_exec(timingsDatabase, [insertStatement UTF8String], NULL, NULL, &error);
        sqlite3_close(timingsDatabase);
    }
} 
  • 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-29T05:35:37+00:00Added an answer on May 29, 2026 at 5:35 am

    Seems that column’s data type is string… You should change it to float to use MAX() function.

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

Sidebar

Related Questions

I have a SQLite database that I am creating in my iOS application. A
I am trying to create entities out of a SQLite database. SQLite doesnt have
I have a datalogging application (c#/.net) that logs data to a SQLite database. This
I have created the application which is based on Sqlite database. So in my
I have an iOS app that stores some data in a sqlite database. The
I am trying to create a SQLite database file for iOS and Android. However,
I have a SQLite database and I am tyring to query the max value
I have an sqlite database full of huge number of URLs and it's taking
I have a SQLite database that contains a huge set of log messages. I
I have an sqlite database, and I would like to keep it read-only without

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.