Sqlite unrecognized token while inserting of hex values
Hello every one i have a small doubt i am inserting some hex value into sqlite db but i am getting a unrecognized token error while inserting value like 000c, 03f4 , 038b but when i am inserting values like 0017 , 0023 , 0384 etc there is no error the data is saved properly to the db... as per my analysis only when there is some alphabet in the hex value i am getting a unrecognized token error.
when there is only numbers in the value it is inserted into the data base.
this is the part of code where i am saving the data into db.
Code:
if(temperatureHexdata.count()>=200)
{
temperatureHexdata.
append(QTime::currentTime().
toString("hh:mm:ss"));
m_query.exec("begin transaction Trans");
QString newsQuery
= "insert into allhexdata";
newsQuery += " values (";
for(int q = 0; q < temperatureHexdata.count() && q<200;q++)
{
newsQuery
+= QString("%1").
arg(temperatureHexdata
[q
]) + ", ";
}
newsQuery
+= "'" + QString("%1").
arg(temperatureHexdata
[200]) + "', ";
newsQuery.remove(newsQuery.length() - 2, 2);
newsQuery += ")";
//qDebug() << temperatureHexdata;
qDebug() << "Query=" << newsQuery;
if(!m_query.exec(newsQuery))
{
qDebug() << m_query.lastError().text();
}
m_query.exec("commit transaction Trans");
temperatureHexdata.clear();
}
pls tell me if i am doing something wrong. ..
thank you
Re: Sqlite unrecognized token while inserting of hex values
What type of data can you put in that column?
If the db column only accepts integers, that might be your problem.
Re: Sqlite unrecognized token while inserting of hex values
Hello sir this is how i am creating the columns for the table. It is varchar so it should't be a problem no sir..
Code:
for( int i=0 ; i<200 ; ++i )
{
HexData
+= QString("Thermo%1 varchar(250) ").
arg(i
) + (i
==199 ?
"" : ",");
}
QString dbt
= QString("create table if not exists allhexdata( %1, Time_InterVal varchar(16));").
arg(HexData
);
query.exec(dbt);
thank you
Re: Sqlite unrecognized token while inserting of hex values
The problem is, that in here
Code:
for(int q = 0; q < temperatureHexdata.count() && q<200;q++)
{
newsQuery
+= QString("%1").
arg(temperatureHexdata
[q
]) + ", ";
}
you missed to place the single quotation marks ('). Thus all input are threaten as integers. Use
Or consider using prepare() and bindValue() to avoid such mistakes.
Re: Sqlite unrecognized token while inserting of hex values
Hello Lykurg sir thank you so much.. that solved the problem..
i wanted to know why is it treated as a integer if we don't use the single quotation mark.
regards
Re: Sqlite unrecognized token while inserting of hex values
Quote:
Originally Posted by
rex
i wanted to know why is it treated as a integer if we don't use the single quotation mark.
Well that's the common SQL syntax: No quotation -> number, quotation -> string. And that is undependent from the type of the field. You also can add an integer to an INT field with
Code:
INSERT INTO `foo` (`id`) VALUES ('123');
So to avoid problems always use quotation marks.
Re: Sqlite unrecognized token while inserting of hex values
ok sir thank you again. .. I understood it now.. :)
regards