Sqlite database not working



  • i am facing some issue on updating mydata base. If have anyone idea regarding this please hepl me.

    here is my code
    #include "login.h"
    #include "ui_login.h"

    login::login(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::login)
    {
    ui->setupUi(this);

    }

    login::~login()
    {
    delete ui;
    }

    void login::on_pushButton_clicked()
    {

    PRINT<<"Connecting ....";

    QSqlDatabase myDB= QSqlDatabase::addDatabase("QSQLITE");
    myDB.setDatabaseName("/home/embdestech/Desktop/tsk/testdatabase.db");
    //db.setDatabaseName("/testdatabase.db");

    if(myDB.open())//opening database
    {
    PRINT <<"Database Opened";
    QSqlQuery qry;

    if(qry.exec("CREATE TABLE karthick(name VARCHAR[20],addr VARCHAR[20]);"))
    {
    PRINT <<"karthick Table Created...";
    }

    if(qry.exec("INSERT INTO karthick(name,addr) VALUES('hgdhjs','jfgd');"))
    {
    PRINT <<"values inserted sucessfully...";
    }
    else
    {
    PRINT <<"user Error .." << qry.lastError().text();
    PRINT <<"Closed";
    myDB.close();

        }
    

    myDB.close();

    }
    }



  • Hi and welcome to devnet,

    1. do you see any error??
    2. is PRINT a macro?
    3. was the karthick table created?

    you have to provide more information


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    To add to @mcosta, you don't do anything if the database failed to open, you should also at least log a message there.



  • Thanks for your suggestion , Now database its working.


  • Lifetime Qt Champion

    What was the problem ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.