/* actually do the log entry */ static void dosqlog(void) { str sql; str mq, mr, md; unsigned int i, ni; if(!sqlseq) return; /* nothing happened */ str_init(&sql); str_init(&mq); str_init(&mr); str_init(&mflags); addflag("greylist", "greylist", 1); addflag("sump", "sump", 0); addflag("dblhelo", "dblhelo", 0); addflag("dblfrom", "dblfrom", 1); addflag("badrcpt", "badrcpt", 1); addflag("badbatv", "badbatv", 1); addflag("rcptrule", "badabuse", 1); str_copys(&sql, "update mail set flags='"); str_cat(&sql, &mflags); sqlquote(&qsender, &mq); str_cats(&sql, "',mailfrom='"); str_cat(&sql, &mq); /* envelope domain */ i = str_findfirst(&qsender, '@'); if(i < qsender.len) { str_init(&md); str_copyb(&md, qsender.s+i+1, qsender.len-i-1); sqlquote(&md, &mq); str_cats(&sql, "',envdomain='"); str_cat(&sql, &mq); } str_cats(&sql, "' where serial="); str_cat(&sql, &sqlseqstr); sqlquery(&sql, 0); /* now add the recipients */ for(i = 0; i < qrecips.len ; i = ni+1) { ni = str_findnext(&qrecips, 0, i); str_copyb(&mr, qrecips.s+i, ni-i); sqlquote(&mr, &mq); str_copys(&sql,"insert into mailrcpt(serial,rcptto) values("); str_cat(&sql, &sqlseqstr); str_cats(&sql, ",'"); str_cat(&sql, &mq); str_cats(&sql, "')"); sqlquery(&sql, 0); } }
static const response* get_seq(void) { str sql; str_init(&sql); /* do IPv6 differently */ if(strchr(remote_ip, ':')) { if(!str_copy5s(&sql, "INSERT INTO mail SET serial=NULL,mailtime=NULL,server6=INET_PTO6('", local_ip, "'),sourceip6=INET_PTO6('", remote_ip, "')")) return &resp_internal; } else { if(!str_copy5s(&sql, "INSERT INTO mail SET serial=NULL,mailtime=NULL,server=INET_ATON('", local_ip, "'),sourceip=INET_ATON('", remote_ip, "')")) return &resp_internal; } if(!sqlquery(&sql, &sqlseq) || !str_init(&sqlseqstr) || !str_catu(&sqlseqstr, sqlseq)) return &resp_internal; msg2("assigned seq ",sqlseqstr.s); session_setnum("sqlseq", (unsigned long)sqlseq); return 0; }
int things_list(struct http_request *req) { int rc; char *zErrMsg = 0; char *query = "SELECT * FROM found ORDER BY last DESC"; template_t tmpl; attrlist_t attributes; struct timespec when; buf = kore_buf_create(mb); if(!thing) thing = hashmap_new(); // load template from assets template_load (asset_things_list_html, asset_len_things_list_html, &tmpl); // initialise attribute list attributes = attrinit(); if( ! parse_datetime(&when, "now", NULL) ) kore_log(LOG_ERR,"parse-datetime error"); else { struct tm *tt; tt = localtime (&when.tv_sec); mktime(tt); strftime(line, ml, "Dowse :: %d %m %Y - %H:%M:%S", tt); attrcat(attributes, "title", line); } sqlquery(query, things_list_cb, attributes); template_apply(&tmpl, attributes, buf); http_response(req, 200, buf->data, buf->offset); template_free(&tmpl); attrfree(attributes); kore_buf_free(buf); return (KORE_RESULT_OK); }
int thing_show(struct http_request *req) { int rc; template_t tmpl; attrlist_t attributes; char *zErrMsg = 0; char *macaddr; http_populate_get(req); // we shouldn't free the result in macaddr if (http_argument_get_string(req, "macaddr", &macaddr)) kore_log(LOG_DEBUG, "thing_show macaddr %s",macaddr); else kore_log(LOG_ERR,"thing_show get argument error"); // prepare query snprintf(line,ml,"SELECT * FROM found WHERE macaddr = '%s'",macaddr); // allocate output buffer buf = kore_buf_create(mb); // load template template_load (asset_thing_show_html, asset_len_thing_show_html, &tmpl); attributes = attrinit(); attrcat(attributes, "title", "Dowse information panel"); // SQL query sqlquery(line, thing_show_cb, attributes); template_apply(&tmpl,attributes,buf); http_response(req, 200, buf->data, buf->offset); template_free(&tmpl); attrfree(attributes); kore_buf_free(buf); return (KORE_RESULT_OK); }
void Sqlite::activate_foreign_keys() { QSqlQuery sqlquery("", dbconn.database(DB_CONNNAME)); QSqlQuery sqltrash("", dbtrash.database(DB_CONNNAME_TRASH)); // DB_ACTIVATE_FOREIGNKEYS is a #define at sqlite.h file sqlquery.prepare(DB_ACTIVATE_FOREIGNKEYS); if (! sqlquery.exec() ){ qDebug() << sqlquery.lastError(); } else { qDebug() << "Glossary Foreign keys activated..."; } sqltrash.prepare(DB_ACTIVATE_FOREIGNKEYS); if (! sqltrash.exec() ){ qDebug() << sqltrash.lastError(); } else { qDebug() << "TrashDB: Foreign keys activated..."; } }
void SqlwriteThread_buffer::run() { QString databaseseq; QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL",databaseseq.setNum(m_index)); database.setHostName(m_hostname); database.setDatabaseName(m_databasename); database.setUserName(m_usrname); database.setPassword(m_psword); if (!database.open()) { database.close(); qDebug()<<trUtf8("数据库打不开")<<endl; return ; } else { qDebug()<<trUtf8("线程内数据已经打开")<<endl; } /* QString i2c; QFile timelog("timelog"+i2c.setNum(m_index)+".txt"); if (!timelog.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) { qDebug()<<trUtf8("LOG日志没有打开")<<endl; return; } timelog.close(); */ QSqlQuery sqlquery(database); // QTime timerecord; // timerecord.start(); qDebug()<<"sqltest thread runing..."; mysqldata *data=g_buffer.data(); mysqldata tempdata; bool flag = true; while(g_rIndex < DATABLOCKSIZE) { mutex.lock(); if(usedBuffer.tryAcquire()) { flag = false; int index=g_rIndex; ++g_rIndex; qDebug()<<QThread::currentThreadId()<<trUtf8("线程读写第") <<index<<trUtf8("块数据,now数据缓存区内存有 ")<<usedBuffer.available()+1<<" blocks!"; mutex.unlock(); //先锁住rindex,如果能获取得到资源,就取走该资源。rndex指向该资源。 tempdata = data[index % 10]; //qDebug()<<"-";// freeBuffer.release(); } else { mutex.unlock(); continue; } int range = tempdata.datavector.size(); for(int i=0;i <= range/SQLLINE ; ++i) //i要改成大数,同range { QString sqlstatement = ""; int statementnum =( (i+1)*SQLLINE > range ) ? range - i*SQLLINE: SQLLINE; sqlstatement="insert into InsertTest(" "id," "taskseq," "protocoltype ," "threadnumintask," "idinthread," "framesize," "DestMac," "SourMac," "TypeorLength," "Data," "Upperlayer) VALUES"; for(int j=0; j < statementnum; j++) { sqlstatement += "("+tempdata.idvector.at(i*SQLLINE + j); sqlstatement += "," + tempdata.taskseqvector.at(i*SQLLINE + j); sqlstatement += ", '" + tempdata.typevector.at(i*SQLLINE + j)+"'"; sqlstatement += "," + tempdata.threadnumvector.at(i*SQLLINE + j); sqlstatement += "," + tempdata.idinthreadvector.at(i*SQLLINE + j); sqlstatement += "," + tempdata.framesizevector.at(i*SQLLINE + j); sqlstatement += ", '" + tempdata.DestMacvector.at(i*SQLLINE + j)+"'"; sqlstatement += ", '" + tempdata.SourMacvector.at(i*SQLLINE + j)+"'"; sqlstatement += ", '" + tempdata.TypeorLengthvector.at(i*SQLLINE + j)+"'"; sqlstatement += ", '" + tempdata.datavector.at(i*SQLLINE + j)+"'"; sqlstatement += ", '" + tempdata.uplayervector.at(i*SQLLINE + j)+"')"; if( j == statementnum -1) sqlstatement += ";"; else sqlstatement += ","; } if( statementnum != 0 ) { if(!sqlquery.exec(sqlstatement)) { qDebug()<<"block--"<<i<<"\t\n"<<sqlquery.lastError().databaseText(); qDebug()<<trUtf8("发生语句错误")<<sqlstatement; return; } } else { break; } } } // timelog.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); // QTextStream logout(&timelog); // logout << "Insert "<<m_range<<" Lines to SQL need time : " << timerecord.elapsed() << "(ms)\n"; // timelog.close(); database.close(); qDebug()<<m_index<<"_thread run over!"<<endl; }
void QLineItem::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; //QBasicGraphicsItem::compile(db, nSceneId, count, index); QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO line(nItemNumber ,nSceneId ,eLineClass ,eLineType ,nLineWidth ," "nLineColor ,eLineArrow ,nAlpha , eLinePointType ,nZvalue,nCollidindId," "nStartX ,nStartY ,nWidth ,nHeight )" "VALUES (:nItemNumber ,:nSceneId ,:eLineClass ,:eLineType ,:nLineWidth ," ":nLineColor ,:eLineArrow ,:nAlpha , :eLinePointType,:nZvalue,:nCollidindId," ":nStartX ,:nStartY ,:nWidth ,:nHeight)"); sqlquery.bindValue(":nItemNumber",QVariant(count));// 表 id sqlquery.bindValue(":nSceneId",QVariant(nSceneId));// 所在场景 id sqlquery.bindValue(":eLineClass",QVariant(1)); //1 代表类型为直线 sqlquery.bindValue(":eLineType",QVariant(nLineType+1));// 线形 sqlquery.bindValue(":nLineWidth",QVariant(getLineWidth()));// 线宽 sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(getLineColor()))); //颜色 sqlquery.bindValue(":eLineArrow",QVariant(m_eLineEndArrowType+1));// 箭头 sqlquery.bindValue(":nAlpha",QVariant(getAlpha()));// 透明度 sqlquery.bindValue(":eLinePointType",QVariant(m_eLineEndArrowType+1)); //端点类型 sqlquery.bindValue(":nZvalue",QVariant(zValue()));//层次 sqlquery.bindValue(":nCollidindId",QVariant(index));//碰撞ID QRectF rect = sceneBoundingRect(); if(getLineWidth() == 1) { sqlquery.bindValue(":nStartX",QVariant(rect.x()-1));//x sqlquery.bindValue(":nStartY",QVariant(rect.y()-1));//y sqlquery.bindValue(":nWidth",QVariant(rect.width()+2));//w sqlquery.bindValue(":nHeight",QVariant(rect.height()+2));//h } else { sqlquery.bindValue(":nStartX",QVariant(rect.x()));//x sqlquery.bindValue(":nStartY",QVariant(rect.y()));//y sqlquery.bindValue(":nWidth",QVariant(rect.width()));//w sqlquery.bindValue(":nHeight",QVariant(rect.height()));//h } bool result = false; result = sqlquery.exec(); qDebug() << "insert line table :"<<result; sqlquery.prepare("INSERT INTO point(nItemId,nPosX,nPosY,nOrder,ePointType)" "VALUES (:nItemId ,:nPosX ,:nPosY ,:nOrder ,:ePointType )"); for(int i=0; i<2; i++) { QPointF pt = this->path().pointAtPercent(i); pt = mapToScene(pt); sqlquery.bindValue(":nItemId",QVariant(count));// item表 id sqlquery.bindValue(":nPosX",QVariant((int)pt.x()));// X sqlquery.bindValue(":nPosY",QVariant((int)pt.y())); //Y sqlquery.bindValue(":nOrder",QVariant(i));// 顺序 sqlquery.bindValue(":ePointType",QVariant(1));// 显示点 result = sqlquery.exec(); qDebug() << "insert point table :"<<result; } SamDrawScene *pScene = dynamic_cast<SamDrawScene *>(scene()); if(pScene && pScene->nIsSceneOrWindow == 2) { //是自定义键盘的item //先新建键盘——item关联表 item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO kbAndItem(nKeyBoardId , nItemId ,nId,nItemTableType ) " "VALUES (:nKeyBoardId ,:nItemId ,:nId,:nItemTableType)"); sqlquery.bindValue(":nKeyBoardId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_LINE)); bool result = false; result = sqlquery.exec(); qDebug() << "insert kbAndItem table :"<<result; } if(pScene && pScene->nIsSceneOrWindow != 2) { //窗口或者场景item //先新建键盘——item关联表 //item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO sceneAndItem(nSceneId,nItemId,nId,nItemTableType)" "VALUES(:nSceneId,:nItemId,:nId,:nItemTableType)"); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); //int t = this->GroupType(); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_LINE)); bool result = false; result = sqlquery.exec(); qDebug() << "insert sceneAndItem table :"<<result; } }
void QElipseItem::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; //QBasicGraphicsItem::compile(db, nSceneId, count, index); QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO polygon(nItemId ,nSceneId,ePolygonClass,eLineType ,nLineWidth,nLineColor," "eStyle,nBackColor,nForeColor,nAlpha,nPointX,nPointY,nWidth,nHeight,nRadius,eCornerType," "nZvalue,nCollidindId)" "VALUES (:nItemId,:nSceneId,:ePolygonClass ,:eLineType ,:nLineWidth,:nLineColor,:eStyle," ":nBackColor,:nForeColor,:nAlpha,:nPointX,:nPointY,:nWidth,:nHeight,:nRadius,:eCornerType," ":nZvalue,:nCollidindId)"); sqlquery.bindValue(":nItemId",QVariant(count));// 表 id sqlquery.bindValue(":nSceneId",QVariant(nSceneId));// 所在场景 id sqlquery.bindValue(":ePolygonClass",QVariant(1)); //1 代表类型为圆 sqlquery.bindValue(":eLineType",QVariant(nLineType+1));// 线形 sqlquery.bindValue(":nLineWidth",QVariant(GetLineWidth()));// 线宽 sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(GetLineColor()))); //颜色 sqlquery.bindValue(":eStyle",QVariant(GetPattern()+1));// 样式 sqlquery.bindValue(":nBackColor",QVariant(ColorToInt(GetBackColor()))); //背景色 sqlquery.bindValue(":nForeColor",QVariant(ColorToInt(GetFrontColor()))); //前景色 sqlquery.bindValue(":nAlpha",QVariant(GetAlpha()));// 透明度 QRect rect = this->sceneBoundingRect().toRect(); sqlquery.bindValue(":nStartX",QVariant(rect.x()));//x sqlquery.bindValue(":nStartY",QVariant(rect.y()));//y sqlquery.bindValue(":nWidth",QVariant(rect.width()));//w sqlquery.bindValue(":nHeight",QVariant(rect.height()));//h sqlquery.bindValue(":nZvalue",QVariant(zValue()));//层次 sqlquery.bindValue(":nCollidindId",QVariant(index));//碰撞ID bool result = false; result = sqlquery.exec(); qDebug() << "insert Elipse table :"<<result; SamDrawScene *pScene = dynamic_cast<SamDrawScene *>(scene()); if(pScene && pScene->nIsSceneOrWindow == 2) { //是自定义键盘的item //先新建键盘——item关联表 item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO kbAndItem(nKeyBoardId , nItemId ,nId,nItemTableType ) " "VALUES (:nKeyBoardId ,:nItemId ,:nId,:nItemTableType)"); sqlquery.bindValue(":nKeyBoardId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_ELIPSE)); bool result = false; result = sqlquery.exec(); qDebug() << "insert kbAndItem table :"<<result; } if(pScene && pScene->nIsSceneOrWindow != 2) { //窗口或者场景item //先新建键盘——item关联表 //item表在派生类中创建 //QSqlQuery sqlquery(db); sqlquery.prepare("INSERT INTO sceneAndItem(nSceneId,nItemId,nId,nItemTableType)" "VALUES(:nSceneId,:nItemId,:nId,:nItemTableType)"); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nItemId",QVariant(count)); sqlquery.bindValue(":nId",QVariant(id())); //int t = this->GroupType(); sqlquery.bindValue(":nItemTableType",QVariant((int)SAM_DRAW_OBJECT_ELIPSE)); bool result = false; result = sqlquery.exec(); qDebug() << "insert sceneAndItem table :"<<result; } }
void QRecipeTableItem::compile(QSqlDatabase &db, int nSceneId,int &count,int index) { count++; QVisableItem::compile(db, nSceneId, count,index); int nItemID = count; if(sPro.enableTouch && !sPro.byGroups_T) { //触控受位控制 增一个地址表 count++; } if(sPro.bNotice) { //触控解锁通知到地址 增加一个地址表 count++; } if(sPro.enableVisable && !sPro.byGroups_V) { //显现受位控制 增加一个地址表 count++; } QRectF rect = this->sceneBoundingRect(); QSqlQuery sqlquery(db); bool bReasult = false; bReasult = sqlquery.prepare("INSERT INTO recipeDisplay(nItemId,nSceneId,nStartPosX,nStartPosY,nWidth," "nHeight,nRecipeGroupId,bShowRecipeID,bShowDescrip,eTextAlignType," "nLanguaId,nRowShowNum,nColumShowNum,nHHeadTextColor,nHHeadBackColor," "nHHeadFontSize,sHHeadFontFamily,nVHeadTextColor,nVHeadBackColor," "nVHeadFontSize,sVHeadFontFamily,nDataTextColor,nDataBackColor," "nDataFontSize,nLineColor,nTransparent,nZvalue,nCollidindId,nShowPropId)" "VALUES (:nItemId,:nSceneId,:nStartPosX,:nStartPosY,:nWidth," ":nHeight,:nRecipeGroupId,:bShowRecipeID,:bShowDescrip,:eTextAlignType," ":nLanguaId,:nRowShowNum,:nColumShowNum,:nHHeadTextColor,:nHHeadBackColor," ":nHHeadFontSize,:sHHeadFontFamily,:nVHeadTextColor,:nVHeadBackColor," ":nVHeadFontSize,:sVHeadFontFamily,:nDataTextColor,:nDataBackColor," ":nDataFontSize,:nLineColor,:nTransparent,:nZvalue,:nCollidindId,:nShowPropId)"); sqlquery.bindValue(":nItemId",QVariant(nItemID)); sqlquery.bindValue(":nSceneId",QVariant(nSceneId)); sqlquery.bindValue(":nStartPosX",QVariant(rect.x())); sqlquery.bindValue(":nStartPosY",QVariant(rect.y())); sqlquery.bindValue(":nWidth",QVariant(rect.width())); sqlquery.bindValue(":nHeight",QVariant(rect.height())); sqlquery.bindValue(":nRecipeGroupId",QVariant(m_SaveInfo.nRecipeGroupId)); sqlquery.bindValue(":bShowRecipeID",QVariant(m_SaveInfo.bShowRecipeID)); sqlquery.bindValue(":bShowDescrip",QVariant(m_SaveInfo.bShowDescrip)); int nAlign = 0; if(0 == m_SaveInfo.eTextAlignType)//center { nAlign = 2; } else if(1 == m_SaveInfo.eTextAlignType)//left { nAlign = 1; } else { nAlign = 3; } sqlquery.bindValue(":eTextAlignType",QVariant(nAlign)); sqlquery.bindValue(":nLanguaId",QVariant(m_SaveInfo.nLanguaId)); sqlquery.bindValue(":nRowShowNum",QVariant(m_SaveInfo.nRowShowNum)); sqlquery.bindValue(":nColumShowNum",QVariant(m_SaveInfo.nColumShowNum)); sqlquery.bindValue(":nHHeadTextColor",QVariant(ColorToInt(m_SaveInfo.nHHeadTextColor))); sqlquery.bindValue(":nHHeadBackColor",QVariant(ColorToInt(m_SaveInfo.nHHeadBackColor))); sqlquery.bindValue(":nHHeadFontSize",QVariant(m_SaveInfo.nHHeadFontSize + 5)); sqlquery.bindValue(":sHHeadFontFamily",QVariant(m_SaveInfo.sHHeadFontFamily)); sqlquery.bindValue(":nVHeadTextColor",QVariant(ColorToInt(m_SaveInfo.nVHeadTextColor))); sqlquery.bindValue(":nVHeadBackColor",QVariant(ColorToInt(m_SaveInfo.nVHeadBackColor))); sqlquery.bindValue(":nVHeadFontSize",QVariant(m_SaveInfo.nVHeadFontSize + 5)); sqlquery.bindValue(":sVHeadFontFamily",QVariant(m_SaveInfo.sVHeadFontFamily)); sqlquery.bindValue(":nDataTextColor",QVariant(ColorToInt(m_SaveInfo.nDataTextColor))); sqlquery.bindValue(":nDataBackColor",QVariant(ColorToInt(m_SaveInfo.nDataBackColor))); sqlquery.bindValue(":nDataFontSize",QVariant(m_SaveInfo.nDataFontSize + 5)); sqlquery.bindValue(":nLineColor",QVariant(ColorToInt(m_SaveInfo.nLineColor))); sqlquery.bindValue(":nTransparent",QVariant(ColorToInt(m_SaveInfo.nTransparent))); sqlquery.bindValue(":nZvalue",QVariant(zValue())); sqlquery.bindValue(":nCollidindId",QVariant(index)); sqlquery.bindValue(":nShowPropId",QVariant(-1)); bReasult = sqlquery.exec(); qDebug()<<"INSERT INTO recipeDisplay"<<bReasult; QList<QGraphicsItem *> list = childItems(); QString sName = ""; QVector<qreal> vVLine; //用来存垂直线的数据 QVector<qreal> vHLine; //用来存水平线的数据 vVLine.clear(); vHLine.clear(); vVLine.append(rect.x()); vHLine.append(rect.y()); //vTileTex.clear(); foreach(QGraphicsItem *pItem,list) { QPointF pos = pItem->boundingRect().topLeft()+pItem->scenePos(); sName = pItem->data(GROUP_NAME_KEY).toString(); if(sName.contains("VLine")) //垂直线 { vVLine.append(pos.x()); } if(sName.contains("HLine")) //水平线 { vHLine.append(pos.y()); } }
void DynCircleAttr::compile(QSqlDatabase &db, int nSceneId, int &count, int index)//编译的时候保存item到数据库 { count++; QVisableItem::compile(db, nSceneId, count, index); int itemId = count; if(sPro.enableTouch && !sPro.byGroups_T) { //触控受位控制 增一个地址表 count++; } if(sPro.bNotice) { //触控解锁通知到地址 增加一个地址表 count++; } if(sPro.enableVisable && !sPro.byGroups_V) { //显现受位控制 增加一个地址表 count++; } QSqlQuery sqlquery(db); bool result = sqlquery.prepare("INSERT INTO dynamicRound(nItemId,nSceneId,nAlpha," "nCpXpos,nCpYpos,nRadius,nFillColor,nUseFill,nRimColor," "nRimWidth,nUsePosCtrl,mCpXDataAddr,mCpYDataAddr," "mRadiusDataAddr,nUseSizeCtrl,nAreaLp,nAreaTp,nAreaWidth," "nAreaHeight,nAreaColor,nZvalue,nCollidindId,nShowPropId)" "VALUES(:nItemId,:nSceneId,:nAlpha," ":nCpXpos,:nCpYpos,:nRadius,:nFillColor,:nUseFill,:nRimColor," ":nRimWidth,:nUsePosCtrl,:mCpXDataAddr,:mCpYDataAddr," ":mRadiusDataAddr,:nUseSizeCtrl,:nAreaLp,:nAreaTp,:nAreaWidth," ":nAreaHeight,:nAreaColor,:nZvalue,:nCollidindId,:nShowPropId)"); qDebug() << "sqlquery.prepare" << result; int num = count; int temp; short leftCp; short topCp; short width; short height; short radius; sqlquery.bindValue(":nItemId", QVariant(itemId)); //表id sqlquery.bindValue(":nSceneId", QVariant(nSceneId)); //scene id sqlquery.bindValue(":nAlpha", QVariant(m_nAlpha)); //alpha QRectF rect = sceneBoundingRect();//相对场景的坐标及高宽 width = rect.width(); height = rect.height(); leftCp = rect.left() + width/2; topCp = rect.top() + height/2; radius = width < height ? (width/2) : (height/2); sqlquery.bindValue(":nCpXpos", QVariant(leftCp));//left sqlquery.bindValue(":nCpYpos", QVariant(topCp));//top sqlquery.bindValue(":nRadius", QVariant(radius));//radius temp =ColorToInt(m_nFillColor); sqlquery.bindValue(":nFillColor", QVariant(temp));// if(m_bFillColor) { sqlquery.bindValue(":nUseFill", QVariant(1));// } else { sqlquery.bindValue(":nUseFill", QVariant(0));// } temp =ColorToInt(m_nFrameColor); sqlquery.bindValue(":nRimColor", QVariant(temp));// sqlquery.bindValue(":nRimWidth", QVariant(m_nFrameWidth));// if(m_bPosCtrl)//位置控制开 { sqlquery.bindValue(":nUsePosCtrl", QVariant(1));// num++; sqlquery.bindValue(":mCpXDataAddr", QVariant(num));// num++; sqlquery.bindValue(":mCpYDataAddr", QVariant(num));// } else { sqlquery.bindValue(":nUsePosCtrl", QVariant(0));// sqlquery.bindValue(":mCpXDataAddr", QVariant(0));// sqlquery.bindValue(":mCpYDataAddr", QVariant(0));// } if(m_bSizeCtrl) { sqlquery.bindValue(":nUseSizeCtrl", QVariant(1));// num++; sqlquery.bindValue(":mRadiusDataAddr", QVariant(num));// } else { sqlquery.bindValue(":nUseSizeCtrl", QVariant(0));// sqlquery.bindValue(":mRadiusDataAddr", QVariant(0));// } //sqlquery.bindValue(":nAreaLp", QVariant(m_nBeginX));// //sqlquery.bindValue(":nAreaTp", QVariant(m_nBeginY));// //sqlquery.bindValue(":nAreaWidth", QVariant(m_nWidth));// //sqlquery.bindValue(":nAreaHeight", QVariant(m_nHeight));// sqlquery.bindValue(":nAreaLp", QVariant(rect.left()));// sqlquery.bindValue(":nAreaTp", QVariant(rect.top()));// sqlquery.bindValue(":nAreaWidth", QVariant(rect.width()));// sqlquery.bindValue(":nAreaHeight", QVariant(rect.height()));// temp =ColorToInt(m_nBgColor); sqlquery.bindValue(":nAreaColor", QVariant(temp));// sqlquery.bindValue(":nZvalue", QVariant(zValue()));// sqlquery.bindValue(":nCollidindId", QVariant(index));// sqlquery.bindValue(":nShowPropId", QVariant(0));// bool result1 = false; result1 = sqlquery.exec(); qDebug() << "insert table :" << result1 << endl; int id = count; if(m_bPosCtrl)//位置控制开 { count++; //修改地址编译参数 ADDR_PARAMENTS stParams; stParams.id = count; stParams.itemId = itemId; stParams.eType = OBJ_ITEM; stParams.eRWtype = SCENE_CONTROL_LOOP_R; stParams.addrNum = -1; m_addrH.compile(db, stParams); //m_addrH.compile(db, count, 0, OBJ_ITEM); count++; //修改地址编译参数 //ADDR_PARAMENTS stParams; stParams.id = count; stParams.itemId = itemId; stParams.eType = OBJ_ITEM; stParams.eRWtype = SCENE_CONTROL_LOOP_R; stParams.addrNum = -1; m_addrV.compile(db, stParams); //m_addrV.compile(db, count, 0, OBJ_ITEM); } if(m_bSizeCtrl) { count++; //修改地址编译参数 ADDR_PARAMENTS stParams; stParams.id = count; stParams.itemId = itemId; stParams.eType = OBJ_ITEM; stParams.eRWtype = SCENE_CONTROL_LOOP_R; stParams.addrNum = -1; m_addrCircle.compile(db, stParams); //m_addrCircle.compile(db, count, 0, OBJ_ITEM); } }
unsigned int Sqlite::create_tables() { QSqlQuery sqlquery("", dbconn.database(DB_CONNNAME)); status = TB_CREATED; // Initialize QStringList tables = dbconn.tables(); if (dbconn.tables().contains("project")) { qDebug() << "DB file has _project_ table."; return (TB_EXISTS); } // CREATE_TB_LANGUAGE is a #define at sqlite.h file sqlquery.prepare(CREATE_TB_LANGUAGE); if (! sqlquery.exec() ){ qDebug() << sqlquery.lastError(); return (TB_WITH_ERROR); } qDebug() << "Table _language_ created!"; sqlquery.prepare(CREATE_TB_PROJECT); if (! sqlquery.exec() ){ qDebug() << sqlquery.lastError(); return (TB_WITH_ERROR); } qDebug() << "Table _project_ created!"; // These defines are just for test multiline string defines! sqlquery.prepare(CREATE_TB_TYPE); if (! sqlquery.exec() ){ qDebug() << sqlquery.lastError(); return (TB_WITH_ERROR); } qDebug() << "Table _type_ created!"; sqlquery.prepare(CREATE_TB_TERM); if (! sqlquery.exec() ){ qDebug() << sqlquery.lastError(); return (TB_WITH_ERROR); } qDebug() << "Table _term_ created!"; // ---- ---- Populate some tables ---- ---- /* * Note: this time, we're going to use execBatch() method to * run multiple INSERTs at once * */ sqlquery.prepare("INSERT INTO type (name, shortname, description) VALUES (?, ?, ?);"); QVariantList names; names << "Noun" << "Pronoun" << "Adjective" \ << "Verb" << "Phrasal Verb" << "Adverb" << "Verbal expression" \ << "Article" << "Preposition" \ << "Conjunction" << "Interjection"; sqlquery.addBindValue(names); QVariantList shortnames; shortnames << "n" << "pron" << "adj" \ << "v" << "v ph" << "adv" << "v expr"\ << "prep" << "art" \ << "conj" << "interj"; sqlquery.addBindValue(shortnames); QVariantList descp; descp << "Refers to person, place, thing, quality, etc." \ << "Replaces noun, for example: _He_ took the cookie and ate _it_."\ << "Describes a noun or pronoun, for example: " "a _tall_ girl; an _interesting_ book."\ << "Verb taking a direct object" \ << "Verb with adverb(s) or preposition(s), having special meaning." \ << "Describes a verb, adjective, adverb, or clause, for example: " "come _quickly_; _very_ rare; happening _now_"\ << "Phrase with special meaning functioning as verb, for example: " "put their heads together; come to an end."\ << "Relates noun or pronoun to another element of sentence, for example: " "a picture _of_ John; She walked _from_> my house _to_ yours."\ << "English has two types of articles: definite (the) and indefinite (a, an.)"\ << "Connects words, clauses, and sentences, for example: " "and; but; because; in order that."\ << "Exclamation, for example: Oh no!; Wow!"; // Interjection sqlquery.addBindValue(descp); if (! sqlquery.execBatch() ){ qDebug() << sqlquery.lastError(); return (TB_WITH_ERROR); } qDebug() << "Table _type_ populated!"; return (status); }
void SqlwriteThread::run() { QString databaseseq; QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL",databaseseq.setNum(m_index)); database.setHostName(m_hostname); database.setDatabaseName(m_databasename); database.setUserName(m_usrname); database.setPassword(m_psword); if (!database.open()) { database.close(); qDebug()<<trUtf8("数据库打不开")<<endl; return ; } else { qDebug()<<trUtf8("线程内数据已经打开")<<endl; } QString i2c; QFile timelog("timelog"+i2c.setNum(m_index)+".txt"); if (!timelog.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) { qDebug()<<trUtf8("LOG日志没有打开")<<endl; return; } timelog.close(); QSqlQuery sqlquery(database); // QTime timerecord; // timerecord.start(); qDebug()<<"sqltest thread runing..."; for(int i=0;i <= m_range/SQLLINE ; ++i) //i要改成大数,同range { QString sqlstatement = ""; int statementnum =( (i+1)*SQLLINE > m_range ) ? m_range - i*SQLLINE: SQLLINE; sqlstatement="insert into TestInsert(" "id," "threadnum," "idinthread," "Data) VALUES"; for(int j=0; j < statementnum; j++) { QString inttemp; sqlstatement += "(null,"; //id sqlstatement += inttemp.setNum(m_index); //threadnum sqlstatement += ","+inttemp.setNum( i*SQLLINE + j + m_index*m_range ); //idinthread sqlstatement += ",'dagnoansdongfnalksngnalksndlfkja;ngaldkfalnlkgnaldnfja')"; //framesize if( j == statementnum -1) sqlstatement += ";"; else sqlstatement += ","; } if( statementnum != 0 ) { if(!sqlquery.exec(sqlstatement)) { qDebug()<<"block--"<<i<<"\t\n"<<sqlquery.lastError().databaseText(); qDebug()<<trUtf8("发生语句错误")<<sqlstatement; return; } } else { break; } // qDebug()<<i<<"--Block insert over!"; } // timelog.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); // QTextStream logout(&timelog); // logout << "Insert "<<m_range<<" Lines to SQL need time : " << timerecord.elapsed() << "(ms)\n"; // timelog.close(); database.close(); qDebug()<<m_index<<"_thread run over!"<<endl; }