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-13-2010, 02:07 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: California
Posts: 200
zulfishah is on a distinguished road
Default sqlite: nested select statements

I use a sqlite table to hold my data. While I'm looping through a select statement on one of the tables, I want to do another select (and update) statement on the same table in some conditions. It's pretty complicated to explain why I would want to do this, but I'm pretty sure I need to.

The problem is that when I loop through the outer while loop, if I call the inner select statement, it terminates the outer loop after that run, even if it has more rows in the sql statement. So is this impossible? Can I call a select statement while I'm looping through the sqlite3_step results on the same table? Here's some psuedo-code) to explain what I'm doing:

Code:
sqlite3_exec(database, "BEGIN", 0, 0, 0); // Begin Transaction

    if (init_all_statement == nil)
    {
        const char *sql = "SELECT id, fullname FROM contact";

        if (sqlite3_prepare_v2(database, sql, -1, &init_all_statement, NULL) != SQLITE_OK) {
            NSAssert1(0, @"Error Test.m: failed with message '%s'.", sqlite3_errmsg(database));
        }
    }

    while (sqlite3_step(init_all_statement) == SQLITE_ROW)
    {
        ...

        if (blah) 
        {
            if (get_duplicate_rows == nil)
            {
                const char *sql = "SELECT id, fullname FROM contact where fullname = ?";

                if (sqlite3_prepare_v2(database, sql, -1, &get_duplicate_rows, NULL) != SQLITE_OK) {
                    NSAssert1(0, @"Error Test.m: failed with message '%s'.", sqlite3_errmsg(database));
                }
            }

            sqlite3_bind_text(get_duplicate_rows, 1, [contact_fullname UTF8String], -1, SQLITE_TRANSIENT);

            while (sqlite3_step(get_duplicate_rows) == SQLITE_ROW)
            {
                ...
            }
            sqlite3_reset(get_one_row);
        }

    }
__________________
Check out my apps:

Contacts Journal

Contacts Journal Lite

Contacts Journal - iPad Edition

Contact Notes

Also visit my Tumblr blog about iPhone development.
zulfishah is offline   Reply With Quote
Old 01-14-2010, 02:24 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Quote:
Originally Posted by zulfishah View Post
Code:
            sqlite3_reset(get_one_row);
Is this a copy/paste typo introduced when you were posting to the forum? What is this "get_one_row" statement you're resetting here?

(Also, I see your apps are listed as 3.0 apps; have you considered switching to Core Data?)
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery 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: 340
11 members and 329 guests
2Apps1Day, akacaj, Domele, michelle, NetGuru, NSString, SLIC, Sloshmonster, soohyun, Techgirl-52, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,114
Posts: 402,886
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

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