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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:05:53+00:00 2026-05-22T19:05:53+00:00

I have a method, which generates a dictionary of returned values from database: –

  • 0

I have a method, which generates a dictionary of returned values from database:

- (NSDictionary *)getParametersForPreset:(NSUInteger)presetID plants:(NSArray *)plants
{

NSString *loggers = @"";
NSString *invertors = @"";
NSString *plantsList = @"";

const char *sql = "SELECT loggerID, invertorID FROM records WHERE presetID IN (?) AND plantID IN (?)";  
BOOL isEmpty = YES;

sqlite3_stmt *statement;

if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) != SQLITE_OK)
{
    NSLog(@"Error: '%s'.", sqlite3_errmsg(database));
}

for (int i = 0; i < [plants count]; i++) {
    if (i == 0)
    {
        plantsList = [NSString stringWithFormat:@"'%@'",[[plants objectAtIndex:0] valueForKey:@"id"]];
    }
    else
    {
        plantsList = [plantsList stringByAppendingFormat:@",'%@'",[[plants objectAtIndex:i] valueForKey:@"id"]];
    }
}

NSLog(@"plants: %@", plantsList);
NSLog(@"preset: %d", presetID);

sqlite3_bind_int(statement, 1, presetID);
sqlite3_bind_text(statement, 2, [plantsList UTF8String], -1, SQLITE_TRANSIENT);

NSMutableDictionary *dictionary = [[[NSMutableDictionary alloc] init] autorelease];
int i = 0;

while (sqlite3_step(statement) == SQLITE_ROW)
{
    if (i == 0)
    {
        loggers = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
        invertors = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];

        isEmpty = NO;
        i++;
    }
    else
    {
        loggers = [loggers stringByAppendingFormat:@",%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]];
        invertors = [invertors stringByAppendingFormat:@",%@",[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)]];
    }
} 

sqlite3_reset(statement);

if (isEmpty == YES)
{
    return nil;
}

[dictionary setValue:[NSString stringWithString:[plantsList stringByReplacingOccurrencesOfString:@"'" withString:@""]] forKey:@"plants"];
[dictionary setValue:loggers forKey:@"loggers"];
[dictionary setValue:invertors forKey:@"invertors"];

return dictionary;

}

This query returns me nothing in the code, but then I do the same query in the SQLite Manager in Firefox for the same database, it returns me the correct data. Please, help me find my mistakes, I’m really exhausted of this.

Here is the query I do in Manager:

SELECT loggerID, invertorID FROM records WHERE presetID=1 AND plantID IN ('3','2','1','6','5','4')

And here are logged values from the code:

preset: 1

plants: '3','2','1','6','5','4'

Thanks a lot!

  • 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-22T19:05:54+00:00Added an answer on May 22, 2026 at 7:05 pm

    I have recently been working on similar query.

    I had a NSMutableArray which stored a list of ID’s. I joined them as a string using the function componentsJoinedByString.

    I then had a NSString object which held my SQL statement, using the stringWithFormat function.

    So your code to generate the SQLite query could be along the lines of:

    NSString * query = [NSString stringWithFormat:@"SELECT loggerID, invertorID FROM records WHERE presetID IN (%d) AND plantID IN (%@)",presetID,[plantsList componentsJoinedByString:@","]];
    

    Hope this helps.

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

Sidebar

Related Questions

I have a method which should be delayed from running for a specified amount
An iPhone app which I am creating generates reports from a Core Data database
I have a method, which generates a JPA Criteria: private CriteriaQuery<ResultSetType> createQuery (ReportFilter reportFilter)
I have a method, which generates a random number, heres the code for it:
I have a method which takes params object[] such as: void Foo(params object[] items)
I have a method which should be executed in an exclusive fashion. Basically, it's
I have an method which save files to the internet, it works but just
I have a method which is given the parameter bool sortAscending. Now I want
I have a method which constructs an object, calls an Execute method, and frees
I have a method which never returns a null object. I want to make

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.