mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
add a getRow function to retrieve rowdata by rowid
This commit is contained in:
@@ -428,6 +428,27 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBBrowserDB::getRow(const QString& sTableName, int rowid, QList<QByteArray>& rowdata)
|
||||
{
|
||||
QString sQuery = QString("SELECT * from %1 WHERE rowid=%2;").arg(sTableName).arg(rowid);
|
||||
QByteArray utf8Query = sQuery.toUtf8();
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
int status = sqlite3_prepare_v2(_db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
if(SQLITE_OK == status)
|
||||
{
|
||||
// even this is a while loop, the statement should always only return 1 row
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
{
|
||||
for (int i = 0; i < sqlite3_column_count(stmt); ++i)
|
||||
rowdata.append(QByteArray(static_cast<const char*>(sqlite3_column_blob(stmt, i)), sqlite3_column_bytes(stmt, i)));
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return status == SQLITE_OK;
|
||||
}
|
||||
|
||||
int DBBrowserDB::addRecord(const QString& sTableName)
|
||||
{
|
||||
char *errmsg;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <QStringList>
|
||||
#include <QMultiMap>
|
||||
#include <QByteArray>
|
||||
|
||||
class MainWindow;
|
||||
class sqlite3;
|
||||
@@ -64,6 +65,16 @@ public:
|
||||
bool executeSQL ( const QString & statement, bool dirtyDB=true, bool logsql=true);
|
||||
bool executeMultiSQL(const QString& statement, bool dirty = true, bool log = false);
|
||||
|
||||
/**
|
||||
* @brief getRow Executes a sqlite statement to get the rowdata(columns)
|
||||
* for the given rowid.
|
||||
* @param sTableName Table to query.
|
||||
* @param rowid The rowid to fetch.
|
||||
* @param rowdata A list of QByteArray containing the row data.
|
||||
* @return true if statement execution was ok, else false.
|
||||
*/
|
||||
bool getRow(const QString& sTableName, int rowid, QList<QByteArray>& rowdata);
|
||||
|
||||
void updateSchema();
|
||||
int addRecord(const QString& sTableName);
|
||||
bool deleteRecord(const QString& table, int rowid);
|
||||
|
||||
Reference in New Issue
Block a user