Subscribe ( )

iPhone Programming Tutorials


 

Forum

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 88

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.

If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra

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

Search 

About the iCodeBlog forum

Most Users Ever Online:

44


Currently Online:

6 Guests

Forum Stats:

Groups: 2

Forums: 6

Topics: 419

Posts: 893

Membership:

There are 934 Members

There has been 1 Guest

There are 2 Admins

There is 1 Moderator

Top Posters:

bobcubsfan – 54

crazyiez – 30

Uhu – 17

AdeC – 17

Nick – 15

jitesh61 – 12

Administrators: Brandon (88 Posts), Collin (0 Posts)

Moderators: VertigoSol (26 Posts)



©   

  • Posted by on 6 Aug 2008 in Uncategorized
  •   |  
  •   |  
  •   |  
  • Comments Off

Comments are closed.