2010-05-18 112 views
0

我試圖對sqlite做查詢。我想檢索與配置文件ID(我有該配置文件的ID)無關的服務器的服務器ID。表serpro表示表之間的n:n關係。Sqlite故障做查詢

這是我的查詢(顯然這是錯誤的):

Select server._id, server.server 
from server where server._id != (SELECT server._id FROM server 
INNER JOIN serpro ON server._id = serpro._ids 
INNER JOIN profile ON profile._id = serpro._idp 
where profile._id=" + idProfile; 

而這些都是在創建表的語句:

create table server (_id integer primary key autoincrement,ip string not null, port string not null, server string not null); 

create table profile (_id integer primary key autoincrement, profile string not null); 

create table serpro (_ids integer not null, _idp integer not null, PRIMARY KEY (_ids, _idp), CONSTRAINT fk_idsps FOREIGN KEY (_ids) REFERENCES server(_id) ON DELETE CASCADE, CONSTRAINT fk_idspp FOREIGN KEY (_idp) REFERENCES server(_id) ON DELETE CASCADE); 

謝謝您的幫助!

+0

您收到了什麼錯誤消息? – jabbie 2010-05-18 14:57:36

+0

您的查詢構建容易受到SQL注入的影響。 – 2010-05-18 14:58:39

回答

1

只是做一個粗略的看看它,我會說你忘記關閉子查詢。添加a)到您的查詢結尾

"Select server._id, server.server from server where server._id != " + 
    " (SELECT server._id FROM server INNER JOIN serpro ON server._id = serpro._ids " + 
    " INNER JOIN profile ON profile._id = serpro._idp " + 
    " where profile._id=" + idProfile + ")"; 
+0

你說得對。謝謝 ! – fxi 2010-05-18 15:33:17