Subscribe ( )

iPhone Programming Tutorials

 

Forum

You must be logged in to post Login Register

Search 

SQL Bind Text

User Post

10:06 am
October 9, 2008


bobcubsfan

iCoder

Los Angeles

posts 42

1

Suppose a database named MLB.sqlite contains two tables. One is list of teams with two fields: teamname and teamid

The other table is a list of players containing two fields: playername and teamid.

Note that teamid exists in both tables.

So the user selects a team and wants a list of the players. The team list is read in from the table in an array and is displayed in TeamView.

Selecting a row yields the teamid, which is stored in an NSString myteamid.

Now, we need to build the array of players.

First, the *sqlStatement:

const char *sqlStatement = “select playername from players where teamid = ?”;

Now, the replacement for the ?. The NSString, myteamid, must be converted as follows:

const char *playerTeamid = [myteamid UTF8String];

Declare the statement.

sqlite3_stmt *compiledStatement;

And finally, “the bind”

sqlite3_bind_text(compiledStatement,1, playerTeamid,-1,NULL);

The second paramater is the first, and only, ?. The -1 says to use the entire string. NULL dumps the variable.


About the iCodeBlog forum

Currently Online:

5 Guests

Maximum Online: 14

Forums:

Groups: 2

Forums: 6

Topics: 128

Posts: 433

Members:

There are 239 members

There are 1 guests


Brandon has made 75 posts

Top Posters:

bobcubsfan - 42

crazyiez - 30

VertigoSol - 17

Uhu - 17

Nick - 15

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)  

Share and Enjoy: