Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-24-2012, 07:06 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 4
cyberclaw2000 is on a distinguished road
Default can not get into the db, no errors

well i try to get a name and a score from the database, well i try to get 3 of those.

but when i try it in the code it will not show them to the label i wanted to put them in.

plz help me.

Code:
//
//  HighScore.m
//  TheOlympicTournements
//
//  Created by ronald brans on 1/10/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//



#import "HighScore.h"


static sqlite3_stmt *statement = nil;


@implementation HighScore

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
    }
    return self;
}

- (void)dealloc
{
    [top1Tennis release];
    [top2Tennis release];
    [top3Tennis release];
    [top1TennisScore release];
    [top2TennisScore release];
    [top3TennisScore release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [self showHighscoreTennis];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
   
}

- (void)viewDidUnload
{
    [top1Tennis release];
    top1Tennis = nil;
    [top2Tennis release];
    top2Tennis = nil;
    [top3Tennis release];
    top3Tennis = nil;
    [top1TennisScore release];
    top1TennisScore = nil;
    [top2TennisScore release];
    top2TennisScore = nil;
    [top3TennisScore release];
    top3TennisScore = nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)showHighscoreTennis
{
    int i = 1;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"ToTDB.sqlite"];

    if(sqlite3_open([writableDBPath UTF8String], &database) == SQLITE_OK) {
        
        if (statement == nil){
            sqlite3_stmt    *statement;
            
            NSString *querySQL = @"SELECT naam, score FROM highscoreTennis";
            
            const char *query_stmt = [querySQL UTF8String];
            
          sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL);
            
            while (sqlite3_step(statement) == SQLITE_ROW)
            {
                NSString *tennisName = [[NSString alloc] initWithUTF8String:
                                          (const char *) sqlite3_column_text(statement, 0)];
                
                NSString *tennisScore = [[NSString alloc] initWithUTF8String:
                                        (const char *) sqlite3_column_text(statement, 1)];
                
                // Code to do something with extracted data here
                if (i==1) {
                top1Tennis.text=tennisName;
                    top1TennisScore.text=tennisScore;
                }else if(i==2){
                    top2Tennis.text=tennisName;
                    top2TennisScore.text=tennisScore;
            }else
            {
                top3Tennis.text=tennisName;
                top3TennisScore.text=tennisScore;
            }
                i++;
                
                [tennisScore release];
                [tennisName release];
            }
            sqlite3_finalize(statement);
            
            
        }else
        {
            NSLog(@"gelukt");
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Gelukt" message:@"Score Toegevoegd" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            
            [alert show];
            [alert release];
        }
    }
        else
        {
            
            NSAssert(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
            sqlite3_close(database);
            
        }

}
    

- (IBAction)backToMain:(id)sender {
        [self dismissModalViewControllerAnimated:YES];
}
@end
cyberclaw2000 is offline   Reply With Quote
Old 01-24-2012, 07:06 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

Having a little trouble parsing your English here ... are you saying that the 2nd place score appears in the 1st place box, or that the 2nd place score appears on your "New Game" button?

Couple of points ...

First: you probably want to order the scores as you pull them out of the database. If you don't use an "order by" clause the DB is free to return them in any order it feels like - one day the 3rd place guy is first, and the next day he's the 15th row returned. Add an "order by score" or "order by score desc" (assuming "score" is a number - if it's a character you got more work to do).

Second: It's bad form to have a global variable called "statement" and a local variable with the same name. You can do it ... but then you might as well do all your variables "aaaa1", "aaaa2", "aaaa3", and so on. Not sure why you first open your DB, then check your global statement var, then initialize a new "statement" - but I'm sure you've got your reasons. Seems a weird way of tracking a high score hit ...
lgehrig1 is offline   Reply With Quote
Old 01-24-2012, 08:11 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 4
cyberclaw2000 is on a distinguished road
Default

Quote:
Originally Posted by lgehrig1 View Post
Having a little trouble parsing your English here ... are you saying that the 2nd place score appears in the 1st place box, or that the 2nd place score appears on your "New Game" button?

Couple of points ...

First: you probably want to order the scores as you pull them out of the database. If you don't use an "order by" clause the DB is free to return them in any order it feels like - one day the 3rd place guy is first, and the next day he's the 15th row returned. Add an "order by score" or "order by score desc" (assuming "score" is a number - if it's a character you got more work to do).

Second: It's bad form to have a global variable called "statement" and a local variable with the same name. You can do it ... but then you might as well do all your variables "aaaa1", "aaaa2", "aaaa3", and so on. Not sure why you first open your DB, then check your global statement var, then initialize a new "statement" - but I'm sure you've got your reasons. Seems a weird way of tracking a high score hit ...

the score is a string, could change that and use order by, good point, forgot about it.

2th point, i used it from an example, as i am kinda new to objective c.

the point is, it will not get the names in the labels and the score neither.


thx for your reply, hopefully you can see the error..
cyberclaw2000 is offline   Reply With Quote
Old 01-25-2012, 06:27 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

Quote:
Originally Posted by cyberclaw2000 View Post
the score is a string, could change that and use order by, good point, forgot about it.

2th point, i used it from an example, as i am kinda new to objective c.

the point is, it will not get the names in the labels and the score neither.


thx for your reply, hopefully you can see the error..
From the snippet you've provided - no. Could be a million reasons. Plus you aren't telling what you ARE seeing - are you getting errors, "gelukt", or what have you?

First thing I'd check is that you linked up your variables and outlets. Then I'd throw some NSLog statements in and verify you actually are pulling data from the database - in other words, is there actually data to pull? If your table is empty then your program is working fine!
lgehrig1 is offline   Reply With Quote
Old 01-25-2012, 06:33 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 4
cyberclaw2000 is on a distinguished road
Default

Quote:
Originally Posted by lgehrig1 View Post
From the snippet you've provided - no. Could be a million reasons. Plus you aren't telling what you ARE seeing - are you getting errors, "gelukt", or what have you?

First thing I'd check is that you linked up your variables and outlets. Then I'd throw some NSLog statements in and verify you actually are pulling data from the database - in other words, is there actually data to pull? If your table is empty then your program is working fine!

gelukt= passed in dutch.

i have reconnecting the outlets then i got null errors with the nsstring line(in the while loop)

Code:
 NSString *tennisName = [[NSString alloc] initWithUTF8String:
                                          (const char *) sqlite3_column_text(statement, 0)];
                
                NSString *tennisScore = [[NSString alloc] initWithUTF8String:
                                        (const char *) sqlite3_column_text(statement, 1)];
also i used 2 nslog, 1 on writeblepath, it gave me a path, and the 2th one on database variable, not sure what that 1 does, but it came out with nothing.

but how can i see into the database of the db on the ipad?
cyberclaw2000 is offline   Reply With Quote
Old 01-27-2012, 04:06 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2011
Location: South Florida, US
Posts: 357
lgehrig1 is on a distinguished road
Default

Quote:
Originally Posted by cyberclaw2000 View Post
... but how can i see into the database of the db on the ipad?
Yeah ... okay ... let's start from first principles.

Question: does your database have any data?

See - your call to open will create the database if it didn't already exist. And an empty database would contain no tables. You are not checking the return code on your prepare statement - and while I would hope the step would fail (i.e. return something other than a success code) on a bad statement, it could be one of those "undefined" things.

And, apparently, you chose not to write the values of tennisName or tennisScore to NSLog (hint hint).

Run it on the simulator, then navigate into the folder $HOME/Library/Application Support/iPhone Simulator/<version>/Applications/<app>/Documents, open your DB file (I'd suggest downloading a sqlite GUI because it doesn't seem like you have a whole lot of DB experience), and look. If there's no data, then I'd think you have an EBKAC issue.
lgehrig1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
12 members and 387 guests
7twenty7, Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0