QSqlQuery :: bindValueを使用すると行を返さないQSqlQueryを呼び出しますが、QString::argを使用して値を追加すると行を返します。
具体的には、これは何も返しません。
QSqlQuery q(QSqlDatabase::database( mDbAdapter->dbFilename() ));
q.prepare("select Focus.TextFormId as ID, Focus, TextForm, Gloss from (select TextFormId,group_concat( Transcription , ' ' ) as TextForm, group_concat( Gloss , '-' ) as Gloss from (select TextFormId,AllomorphId,Allomorph.Form as Transcription,LexicalEntryGloss.Form as Gloss from MorphologicalAnalysisMembers,Allomorph,LexicalEntryGloss where TextFormId in ( select TextFormId from MorphologicalAnalysisMembers where AllomorphId in (select _id from Allomorph where LexicalEntryId=:LexicalEntryId and WritingSystem=:TextFormWS) ) and AllomorphId = Allomorph._id and Allomorph.LexicalEntryId = LexicalEntryGloss.LexicalEntryId and LexicalEntryGloss.WritingSystem=:GlossWS order by TextFormId, AllomorphOrder) group by TextFormId ) as Concatenation left join ( select TextFormId, Form as Focus from Allomorph,MorphologicalAnalysisMembers on Allomorph._id=MorphologicalAnalysisMembers.AllomorphId and LexicalEntryId=:LexicalEntryId ) as Focus on Focus.TextFormId = Concatenation.TextFormId;");
q.bindValue(":LexicalEntryId", mLexicalEntryId);
q.bindValue(":GlossWS", mGlossWs.id());
q.bindValue(":TextFormWS", mTextFormWs.id());
if( !q.exec() )
qWarning() << q.lastError().text() << q.executedQuery();
これは適切な結果を返しますが
QSqlQuery q(QSqlDatabase::database( mDbAdapter->dbFilename() ));
q.prepare(
QString("select Focus.TextFormId as ID, Focus, TextForm, Gloss from (select TextFormId,group_concat( Transcription , ' ' ) as TextForm, group_concat( Gloss , '-' ) as Gloss from (select TextFormId,AllomorphId,Allomorph.Form as Transcription,LexicalEntryGloss.Form as Gloss from MorphologicalAnalysisMembers,Allomorph,LexicalEntryGloss where TextFormId in ( select TextFormId from MorphologicalAnalysisMembers where AllomorphId in (select _id from Allomorph where LexicalEntryId=%1 and WritingSystem=%3) ) and AllomorphId = Allomorph._id and Allomorph.LexicalEntryId = LexicalEntryGloss.LexicalEntryId and LexicalEntryGloss.WritingSystem=%2 order by TextFormId, AllomorphOrder) group by TextFormId ) as Concatenation left join ( select TextFormId, Form as Focus from Allomorph,MorphologicalAnalysisMembers on Allomorph._id=MorphologicalAnalysisMembers.AllomorphId and LexicalEntryId=%1 ) as Focus on Focus.TextFormId = Concatenation.TextFormId;")
.arg(mLexicalEntryId).arg(mGlossWs.id()).arg(mTextFormWs.id())
);
if( !q.exec() )
qWarning() << q.lastError().text() << q.executedQuery();
データベース全体を再現するのはかなり難しいでしょうが、よりわかりやすい形式でクエリを次に示します。
select Focus.TextFormId as ID, Focus, TextForm, Gloss from (select TextFormId,group_concat( Transcription , ' ' ) as TextForm, group_concat( Gloss , '-' ) as Gloss
from
(select TextFormId,AllomorphId,Allomorph.Form as Transcription,LexicalEntryGloss.Form as Gloss
from MorphologicalAnalysisMembers,Allomorph,LexicalEntryGloss
where TextFormId in
( select TextFormId from MorphologicalAnalysisMembers where AllomorphId in
(select _id from Allomorph where LexicalEntryId=%1 and WritingSystem=%3) )
and AllomorphId = Allomorph._id
and Allomorph.LexicalEntryId = LexicalEntryGloss.LexicalEntryId
and LexicalEntryGloss.WritingSystem=%2
order by TextFormId, AllomorphOrder)
group by TextFormId ) as Concatenation
left join
( select TextFormId, Form as Focus from Allomorph,MorphologicalAnalysisMembers
on Allomorph._id=MorphologicalAnalysisMembers.AllomorphId and LexicalEntryId=%1 )
as Focus on Focus.TextFormId = Concatenation.TextFormId;
クエリを改善する方法はおそらくあると思いますが、ドキュメントを検索しましたが、QSqlQuery::bindValueに制限があることを示すものは見つかりませんでした。