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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:51:43+00:00 2026-06-16T08:51:43+00:00

i am trying to get a random string from database i have tried to

  • 0

i am trying to get a random string from database i have tried to convert array in a String but when i click button i only get address can anyone help me how to show that string in my button action?

- (IBAction)randBtn:(id)sender {

        SendQuoteVC *svc= [[SendQuoteVC alloc]initWithNibName:@"SendQuoteVC" bundle:nil];

        DBHandler *db =[[DBHandler alloc]init];
        arr =[db randomQuote];

        NSMutableString * show = [[NSMutableString alloc] init];
        for (NSObject * obj in arr)
        {
            [show appendString:[obj description]];
        }
        NSLog(@"The concatenated string is %@", show);

        NSString *rs =[NSString stringWithFormat:@" %@",show];
        svc.quote=rs;
      [self.navigationController pushViewController:svc animated:YES];
}

and my log message is

    2012-12-26 17:02:46.062 SendQuote[2281:c07] QUERY: SELECT * FROM quotes ORDER BY RANDOM() LIMIT 1
2012-12-26 17:02:46.097 SendQuote[2281:c07] txtQuote is  (
    "<quoteDC: 0xa9a94c0>"
)
2012-12-26 17:02:46.100 SendQuote[2281:c07] rand is  (
    "<quoteDC: 0xa9a94c0>"
)

i have changed my user entity class to quoteDC class and my Db function is

-(NSMutableArray *)randomQuote{
    NSMutableArray *dataArray =[[NSMutableArray alloc]init];
    NSString * sqlStr=[NSString stringWithFormat:@"SELECT * FROM quotes ORDER BY RANDOM() LIMIT 1"];
    sqlite3_stmt *ReturnStatement = (sqlite3_stmt *) [self getStatement: sqlStr];
    while (sqlite3_step(ReturnStatement)==SQLITE_ROW)
    {
        @try
        {
            quoteDC *worddc = [[quoteDC alloc] init];

            NSString *userid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement, 0)];
            NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement, 1)];


            worddc.quote_id=[userid integerValue];
            worddc.quotes=name;
            [dataArray addObject:worddc];
        }
        @catch (NSException *ept) {
            NSLog(@"Exception in %s, Reason: %@", __PRETTY_FUNCTION__, [ept reason]);
        }
    }
    return dataArray;


}
  • 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-16T08:51:44+00:00Added an answer on June 16, 2026 at 8:51 am

    This code makes the issue:

    for (NSObject * obj in arr)
    {
        [show appendString:[obj description]];
    }
    

    Because your entity class don’t have a property like description.
    Instead of this write:

    for (quoteDC * obj in arr)
    {
        [show appendString:[obj quotes]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert my char array to string and I get some random
I am trying to get a random string from an array when I press
Trying to get a random string out of ListArray on the button pressed. Always
I am trying to get a random string from a list of strings in
i am trying to display a random string each time a button is pressed
What I'm trying to do here is to always get a random value from
I'm trying to grab a random item from a string list and save that
I've trying to display random data from the database example in my database i
So I'm trying to get the values from a SQLite database into a cursor,
I'm trying to get objects from a multi-level JSON array. This is the an

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.