int main (void) { Connection con(use_exceptions); try { ostrstream strbuf; unsigned int i=0; con.real_connect (MY_DATABASE,MY_HOST,MY_USER,MY_PASSWORD,3306,(int)0,60,NULL); Query query = con.query(); query << MY_QUERY; ResUse res = query.use(); Row row; strbuf << "delete from " << MY_TABLE << " where " << MY_FIELD << " in ("; // for UPDATE just replace the above DELETE FROM with UPDATE statement for(;row=res.fetch_row();i++) strbuf << row[0] << ","; if (!i) return 0; string output(strbuf.str()); output.erase(output.size()-1,1); output += ")"; query.exec((const string&)output); // cout << output << endl; return 0; } catch (BadQuery er) { cerr << "Error: " << er.error << " " << con.errnum() << endl; return -1; } }
void ShotResult::readRemark(unsigned int shotno) { Query query = m_con.query(); ResUse res; string strquery = "select idx, shotnum, writer, remark,wdate from REMARKT where shotnum=%0"; query << strquery; query.parse(); res = query.use(shotno); Row row; QTableWidgetItem *pItem = 0; QDateTime wdate; mtw_Shotremark->setRowCount(0); int index = 0; mmapIndex.clear(); while (row = res.fetch_row()) { index = mtw_Shotremark->rowCount(); mtw_Shotremark->insertRow(index); mtw_Shotremark->setRowHeight(index,20); mmapIndex[index]= row["idx"]; pItem = new QTableWidgetItem(row["writer"].get_string().c_str()); pItem->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); mtw_Shotremark->setItem(index, WRITER, pItem); pItem = new QTableWidgetItem(row["remark"].get_string().c_str()); pItem->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter); mtw_Shotremark->setItem(index, REMARK, pItem); wdate = QDateTime::fromString(row["wdate"].get_string().c_str(),"yyyy-MM-dd hh:mm:ss"); pItem = new QTableWidgetItem(wdate.toString("yy-MM-dd hh:mm:ss").toStdString().c_str()); pItem->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter); mtw_Shotremark->setItem(index, WDATE, pItem); }; mtw_Shotremark->update(); }
void ShotResult::readSession(unsigned int shotno) { ResUse res; Query query = m_con.query(); query << "select type,tfcurrent,plsmacurrent,ipwidth,edensity,etemp,airpressure,echpow from SHOTSUMMARY where shotnum=%0"; query.parse(); res = query.use(shotno); Row row; string strtype; while (row = res.fetch_row()) { strtype = row["type"].get_string(); double dtfcurrent = row["tfcurrent"]/1000.0; double dplmacurrent = row["plsmacurrent"]/1000.0; double dipwidth = row["ipwidth"]*1000.0; double dedensity = row["edensity"]; double detemp = row["etemp"]; double dairp = row["airpressure"]; double dechp = row["echpow"]; QString qstrtfcur = QString("%1").arg(dtfcurrent, 0, 'f', 1); QString qstrairp = QString("%1").arg(dairp, 0, 'e', 1); mleTf ->setText(qstrtfcur); mlePr ->setText(qstrairp); QString qstrplmacur, qstreden, qstretemp, qstrechp,qstripwidth; if (strtype.compare("TS")==0) { qstreden = "--"; qstretemp = "--"; qstrechp = "--"; qstrplmacur = "--"; qstripwidth = "--"; } else { if(dedensity<0.1) { qstreden = "--"; qstretemp = "--"; if( dplmacurrent<10.0) { qstrplmacur = "--"; qstripwidth = "--"; } else { qstrplmacur = QString("%1").arg(dplmacurrent, 0, 'f', 1); qstripwidth = QString("%1").arg(dipwidth, 0, 'f', 1); }; } else { qstrplmacur = QString("%1").arg(dplmacurrent, 0, 'f', 1); qstreden = QString("%1").arg(dedensity, 0, 'f', 1); qstretemp = QString("%1").arg(detemp, 0, 'f', 1); qstripwidth = QString("%1").arg(dipwidth, 0, 'f', 1); }; qstrechp = QString("%1").arg(dechp, 0, 'f', 1); }; mleIp ->setText(qstrplmacur); mleIpPulse ->setText(qstripwidth); mleNe ->setText(qstreden); mleTe ->setText(qstretemp); mleEchP ->setText(qstrechp); }; }