2

I am using this code to create a database. But I am getting "false" in debug. I tried a lot but its not working. What is the error in this?

 QSqlQuery query;
qDebug() << query.exec("CREATE TABLE glucose (id INTEGER PRIMARY KEY AUTOINCREMENT, value INTEGER, date TEXT, time TEXT, duration TEXT, note TEXT");

   qDebug() << query.prepare("INSERT INTO glucose(id, value, date, time, duration, note)""VALUES(?, ?, ?, ?, ?, ?)");

   query.bindValue(1,edit_glucose->text().toInt());

   query.bindValue(2,datetime->date());

  query.bindValue(3,datetime->time());

  query.bindValue(4,"a");

   query.bindValue(5,edit_note->toPlainText());
   qDebug() << query.exec();

3 Answers 3

5

you forget to close your CREATE TABLE query with ")"

Sign up to request clarification or add additional context in comments.

Comments

2

QSqlQuery has the method lastError(), returns error information :)

1 Comment

yes I have used that : qDebug()<< query.lastError(); But its showing error : binary '<<' no operator found which can takes a left hand operand of type Qdebug(there is no acceptable conversion).
1

You are passing in the INSERT query the id field. You must remove it.

The query should be:

Debug() << query.prepare("INSERT INTO glucose(value, date, time, duration, note) 
                                      VALUES(?, ?, ?, ?, ?)");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.