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 08-05-2010, 11:24 PM   #1 (permalink)
Tim
Registered Member
 
Join Date: Oct 2009
Posts: 8
Tim is on a distinguished road
Default sqlite return entire column

I am trying to have an entire column of my sqlite database returned and placed into an array, but am having much difficulty getting it done. The query string itself works fine as I have tested it against my database in a database managing app. They code that I am using works fine in returning an array of a row, because I have used it elsewhere in my app many times.

Code:
NSMutableArray *locationList = [[NSMutableArray alloc] init];
	
const char *sql = [[NSString stringWithFormat:@"SELECT ColumnName FROM TableName"] UTF8String];
NSString *file = [[NSBundle mainBundle] pathForResource:@"databaseName" ofType:@"sqlite"];
	
sqlite3 *database = NULL;
if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
	sqlite3_exec(database, sql, MyCallback, locationList, NULL);
}
	
sqlite3_close(database);
also here is the function "MyCallback"

Code:
static int MyCallback(void *context, int count, char **values, char **columns)
{
    NSMutableArray *names = (NSMutableArray *)context;
    for (int i=0; i < count; i++) {
        const char *nameCString = values[i];
        [names addObject:[NSString stringWithUTF8String:nameCString]];
    }
    return SQLITE_OK;
}
I have a feeling it might have to do with this function, but I am not entirely sure what it does. :/ I placed it there based on some tutorial I followed a while ago.

I am self taught, so I am not so great at understanding documentation, but any resources you can give me that might help would definitely be appreciated.

Thanks in advance all who are much more knowledgeable than I!
Tim is offline   Reply With Quote
Old 08-05-2010, 11:35 PM   #2 (permalink)
Tim
Registered Member
 
Join Date: Oct 2009
Posts: 8
Tim is on a distinguished road
Default

Of coarse this happens right after I submit, even though I have been trying to work on this issue for days now, but I just tested something, and I not longer believe this to be my problem at all. In fact I am pretty sure the code I posted works perfectly. I cannot seem to find a way to delete my thread tho. Could an admin do it?
Tim is offline   Reply With Quote
Reply

Bookmarks

Tags
callback, database, queary, sqlite, sqlite3

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: 304
11 members and 293 guests
alexP, arash5500, gordo26, HemiMG, linkmx, mediaspree, nobstudio, Objective Zero, Sloshmonster, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

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