QString strDBName
= "D:\path to .db file where the .exe is data.db";
db.setDatabaseName(strDBName);
bool dbOpen = db.open(strDBName, NULL);
QString strDBName = "D:\path to .db file where the .exe is data.db";
db.setDatabaseName(strDBName);
bool dbOpen = db.open(strDBName, NULL);
To copy to clipboard, switch view to plain text mode
query.exec("SELECT Column1, Column2, Column3, Column4, Column5, Column6, FROM tblTable WHERE (Column4='EMPTY')"); //
qDebug() << query.lastError().text(); //if error executing SQL statement occurs, get error
//Selected rows based on condition
while(query.next())
{
qDebug() << "inside while loop";
int iRow = query.value(0).toInt();
int iColumn = query.value(1).toInt();
qDebug() << "Row = " << iRow << "Column = " << iColumn;
}
query.exec("SELECT Column1, Column2, Column3, Column4, Column5, Column6, FROM tblTable WHERE (Column4='EMPTY')"); //
qDebug() << query.lastError().text(); //if error executing SQL statement occurs, get error
//Selected rows based on condition
while(query.next())
{
qDebug() << "inside while loop";
int iRow = query.value(0).toInt();
int iColumn = query.value(1).toInt();
qDebug() << "Row = " << iRow << "Column = " << iColumn;
}
To copy to clipboard, switch view to plain text mode
I've got this code, and unfortunately it's not producing any results. The first qDebug with lastError(), prints " ". According to the documentation (Returns error information about the last error (if any) that occurred with this query.), not sure if the empty brackets indeed correspond to the fact that no error occured or whether we're supposed to get no output at all if no error occured but I'm assuming that no error occured.
The second qDebug statement inside the 'while' loop nevergets executed so not sure why the program never enters the 'while' loop.
I've tried PRAGMA:
query.exec("PRAGMA database_list");
//qDebug() << query.lastError().text(); //if error executing SQL statement occurs, get error
//List of currently available databases
while(query.next())
{
int iDatabaseConnection = query.value(2).toInt();
QString sDatabaseSecondColumn
= query.
value(2).
toString();
QString sDatabaseFileName
= query.
value(2).
toString();
qDebug() << "Database connection " << iDatabaseConnection << "Database file name = " << sDatabaseFileName << "Second column = " << sDatabaseSecondColumn;
}
query.exec("PRAGMA database_list");
//qDebug() << query.lastError().text(); //if error executing SQL statement occurs, get error
//List of currently available databases
while(query.next())
{
int iDatabaseConnection = query.value(2).toInt();
QString sDatabaseSecondColumn = query.value(2).toString();
QString sDatabaseFileName = query.value(2).toString();
qDebug() << "Database connection " << iDatabaseConnection << "Database file name = " << sDatabaseFileName << "Second column = " << sDatabaseSecondColumn;
}
To copy to clipboard, switch view to plain text mode
and the result was:
Database connection 0 Database file name = "D:\path to .db file where the .exe is data.db" Second column = "D:\path to .db file where the .exe is data.db"
So the PRAGMA query enters the 'while' loop but the other does not.
Bookmarks