我有一张这样的表:
__fastcall UploadRouteThread::UploadRouteThread(String host, TIdPort port, AnsiString xmlString)
: TThread(false)
{
this->FreeOnTerminate = true;
this->OnTerminate = OnTerminateHandler;
this->xmlString = xmlString;
tcpClient = new TIdTCPClient();
tcpClient->Host = host;
tcpClient->Port = port;
tcpClient->UseNagle = true;
tcpClient->OnWork = OnWorkHandler;
}
__fastcall UploadRouteThread::~UploadRouteThread()
{
delete tcpClient;
}
void __fastcall UploadRouteThread::OnTerminateHandler(TObject *Sender)
{
TabbedwithNavigationForm->UploadButton->Text = "Upload";
TabbedwithNavigationForm->UploadButton->Enabled = false;
TabbedwithNavigationForm->ProgressBar->Visible = false;
if (FatalException)
ShowMessage("Data not uploaded.");
else
ShowMessage("Data uploaded.");
TabbedwithNavigationForm->OptionButton->Enabled = true;
TabbedwithNavigationForm->RetrieveRoutesButton->Enabled = true;
TabbedwithNavigationForm->TrackButton->Enabled = true;
TabbedwithNavigationForm->MediaButton->Enabled = true;
}
void __fastcall UploadRouteThread::OnWorkHandler(TObject *ASender, TWorkMode AWorkMode, __int64 AWorkCount)
{
if (Terminated)
Sysutils::Abort();
sent = (double(AWorkCount) * 100.0) / xmlString.Length();
// consider using TThread::Queue() instead so that you don't block
// the upload waiting for the UI to be updated...
TThread::Synchronize(this, &UpdateProgressBarInternal);
}
void __fastcall UploadRouteThread::Execute()
{
tcpClient->Connect();
try
{
NextPacketSize nps;
nps.PacketID = BasicPacket::DATA_UPLOAD;
nps.size = xmlString.Length();
tcpClient->IOHandler->Write(RawToBytes(&nps, sizeof(nps)));
tcpClient->BeginWork(wmWrite, xmlString.Length());
tcpClient->IOHandler->Write(RawToBytes(xmlString.c_str(), xmlString.Length()));
tcpClient->EndWork(wmWrite);
/* alternatively:
TIdMemoryBufferStream *strm = new TIdMemoryBufferStream(xmlString.c_str(), xmlString.Length());
try
{
// optional
tcpClient->IOHandler->SendBufferSize = 256;
// this calls (Begin|End)Work() internally...
tcpClient->IOHandler->Write(strm, 0, false);
}
__finally
{
delete strm;
}
*/
}
__finally
{
tcpClient->Disconnect();
}
}
void __fastcall UploadRouteThread::UpdateProgressBarInternal()
{
if (!TabbedwithNavigationForm->ProgressBar->Visible)
{
TabbedwithNavigationForm->ProgressBar->Visible = true;
TabbedwithNavigationForm->ProgressBar->Max = 100;
}
TabbedwithNavigationForm->ProgressBar->Value = sent;
}
在上表中// Mytable
+----+--------------------+---------+
| Id | QuestionOrAnswer | related |
+----+--------------------+---------+
| 1 | question1 | 0 |
| 2 | answer1 | 1 |
| 3 | answer2 | 1 |
| 4 | question2 | 0 |
| 5 | question3 | 0 |
| 6 | answer4 | 5 |
| 7 | answer4 | 4 |
| 8 | answer4 | 5 |
+----+--------------------+---------+
表示"问题"其他任何数字意味着"回答"。此外,0
列中每个问题的ID号都有自己的答案。现在我想知道,我如何选择问题加上所有自己的答案?像这样:
问题1:
related
问题2:
// Mytable
+----+--------------------+---------+
| Id | QuestionOrAnswer | related |
+----+--------------------+---------+
| 1 | question1 | 0 |
| 2 | answer1 | 1 |
| 3 | answer2 | 1 |
+----+--------------------+---------+
问题3:
// Mytable
+----+--------------------+---------+
| Id | QuestionOrAnswer | related |
+----+--------------------+---------+
| 4 | question2 | 0 |
| 7 | answer4 | 4 |
+----+--------------------+---------+
等等......我怎么能这样做?
答案 0 :(得分:1)
试试这个:
select * from Mytable where id = 1 or related = 1