if(query.exec(
"SELECT * FROM parkinfo WHERE longitudedu="+Parkdata.gpsdatas.longitude.du+" AND longitudefen="+Parkdata.gpsdatas.longitude.fen+" AND EW="+Parkdata.gpsdatas.EW+" AND latitudedu="+Parkdata.gpsdatas.latitude.du+" AND latitudefen="+Parkdata.gpsdatas.latitude.fen+" AND NS="+Parkdata.gpsdatas.NS+""))
{
query.exec(
"update parkinfo set numbers="+Parkdata.num+" where longitudedu="+Parkdata.gpsdatas.longitude.du+" AND longitudefen="+Parkdata.gpsdatas.longitude.fen+" AND EW="+Parkdata.gpsdatas.EW+" AND latitudedu="+Parkdata.gpsdatas.latitude.du+" AND latitudefen="+Parkdata.gpsdatas.latitude.fen+" AND NS="+Parkdata.gpsdatas.NS+"");
}
else
{
query.exec(
"INSERT INTO parkinfo VALUES( NULL , "+Parkdata. gpsdatas.longitude.du+" , "+Parkdata.gpsdatas.longitude.fen+" , "+Parkdata.gpsdatas.EW+", "+Parkdata.gpsdatas.latitude.du+" ,"+Parkdata.gpsdatas.latitude.fen+" ,"+Parkdata.gpsdatas.NS+","+Parkdata.num+" )");
}
这3句 提示这样的错误:
error: invalid operands of types ‘const char*’ and ‘const char [20]’ to binary ‘operator+’
错误原因是类型const char*’ and ‘const char [20]’对“+”而言,并不会作连接操作
使用占位符:
query.prepare("SELECT * FROM get_parks WHERE longitudedu=? AND longitudefen=? AND EW=? AND latitudedu=? AND latitudefen=? AND NS=?");
query.addBindValue(Parkdata.gpsdatas.longitude.du);
query.addBindValue(Parkdata.gpsdatas.longitude.fen);
query.addBindValue(Parkdata.gpsdatas.EW);
query.addBindValue(Parkdata.gpsdatas.latitude.du);
query.addBindValue(Parkdata.gpsdatas.latitude.fen);
query.addBindValue(Parkdata.gpsdatas.NS);
query.exec();
// query.exec("select * from get_parks");
int i=0;
while(query.next())
{
i++;
qDebug()<<"iiiiiiiiiim"<<i;
}
if(i==1)
{
query.prepare("update get_parks set numbers=? where longitudedu=? AND longitudefen=? AND EW=? AND latitudedu=? AND AND latitudefen=? AND NS=?");
query.addBindValue(Parkdata.num);
query.addBindValue(Parkdata.gpsdatas.longitude.du);
query.addBindValue(Parkdata.gpsdatas.longitude.fen);
query.addBindValue(Parkdata.gpsdatas.EW);
query.addBindValue(Parkdata.gpsdatas.latitude.du);
query.addBindValue(Parkdata.gpsdatas.latitude.fen);
query.addBindValue(Parkdata.gpsdatas.NS);
query.exec();
qDebug()<<"db8 not opem";
}
else if(i==0)
{
query.prepare("Insert into get_parks values(NULL,?,?,?,?,?,?,?)");
query.addBindValue(Parkdata.gpsdatas.longitude.du);
query.addBindValue(Parkdata.gpsdatas.longitude.fen);
query.addBindValue(Parkdata.gpsdatas.EW);
query.addBindValue(Parkdata.gpsdatas.latitude.du);
query.addBindValue(Parkdata.gpsdatas.latitude.fen);
query.addBindValue(Parkdata.gpsdatas.NS);
query.addBindValue(Parkdata.num);
query.exec();
qDebug()<<"dbccc not opem";
}