Subscribe ( )

iPhone Programming Tutorials

 

Forum

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

You must be logged in to post Login Register

Search 

Select with many parameter

User Post

6:42 pm
September 11, 2008


motsach

Noob

posts 2

1

Hi all!

    I read the serial of “iPhone Programming Tutorial” and have some question (I am a beginer in Object-C and SQLite).

In this tutorial, you only do select statement with one parameter such as:

const char *sql = “SELECT text FROM todo WHERE pk=?”;

if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK)

{

     //  Error report…

}

//  Pass parameter into select statement

sqlite3_bind_int(init_statement, 1, primarykey);

// Do select statement…

—————————————————————————————

How can I do select statement with more than one parameter?

Thanks you!

Bookworm Smile

PS: I'm new member in iPhone programming and Object-C. Can you show me where I have to start? Please share for me any document if you have. Thanks!

8:19 am
September 12, 2008


Admin

brandontreb

posts 87

2

Bookworm,

I showed how to do this in my 3rd release of the sqlite tutorial using an update statement.  But here it is with a select.

const char *sql = “SELECT text FROM todo WHERE pk=? AND foo=?”;

if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK)

{

     //  Error report…

}

sqlite3_bind_int(init_statement, 1, primarykey);

sqlite3_bind_int(init_statement, 2, bar);


As you can see the question marks are read from left to right.  So as you add subsequent parameters, you just add more question marks and bind them in order.

If you are totally new, I would suggest my Hello World tutorial.

Let me know if you need more help.

6:08 pm
September 14, 2008


motsach

Noob

posts 2

3

Hi Brandon,

       Thanks for your help. It's very useful!

Good luck!

Bookworm

5:21 pm
February 3, 2009


Inscrutable

Noob

posts 1

4

Hello Brandon,

Do we always need to search using the primary key? I come from a web and MySQL background, so all this binding stuff is a bit odd to me. Like if I have an app that is, for instance, an address book, i cannot know the pk to look for if i want to search for a particular contact.  Also, can you shed any light on how I would operate with more than one table. IE, how would I initialize them separately, and query them either separately or with a JOIN.


Thanks in advance


About the iCodeBlog forum

Currently Online:

4 Guests

Maximum Online: 44

Forums:

Groups: 2

Forums: 6

Topics: 330

Posts: 776

Members:

There are 742 members

There are 1 guests


Brandon has made 87 posts

Top Posters:

bobcubsfan - 54

crazyiez - 30

VertigoSol - 26

Uhu - 17

AdeC - 17

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)