2009-10-13 51 views
0

我想在我的代碼中寫入查詢。我的查詢是這樣的:iPhone + sqlite3 +不在查詢中

SELECT PlayerID, PlayerName, Type, BattingSkills, BallingSkills 
from Player 
where TeamId = 6 
     and PlayerID not in (163,174) 
order by battingSkills desc 
limit 4 

在我的Xcode我寫的查詢像下面

const char *sql = "SELECT PlayerID, PlayerName, Type, BattingSkills, BallingSkills                 from Player where TeamId = ? LIMIT 11"; 

sqlite3_stmt *selectstmt; 
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) 
{ 
    sqlite3_bind_int(selectstmt, 1, teamId); 
    .................. 
    } 

現在假設我想寫的不是查詢(如我上面的SQL查詢),怎麼會我在xCode中編寫我的代碼來傳遞不在ID中的代碼。

回答

2

這可能工作(值傳遞你teamID做同樣的方式):

const char *sql = "SELECT PlayerID, PlayerName, Type, BattingSkills, BallingSkills from Player where TeamId = ? and playerID not in (?, ?) LIMIT 11"; 
... 
sqlite3_bind_int(selectstmt, 1, teamId); 
sqlite3_bind_int(selectstmt, 2, notID1); 
sqlite3_bind_int(selectstmt, 3, notID2);