mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
add a function to return the create table statement for a given table
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "sqlitedb.h"
|
||||
#include "sqlbrowser_util.h"
|
||||
#include "MainWindow.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
@@ -860,6 +861,31 @@ void DBBrowserDB::logSQL(const QString& statement, int msgtype)
|
||||
}
|
||||
}
|
||||
|
||||
QString DBBrowserDB::getTableSQL(const QString& sTable)
|
||||
{
|
||||
sqlite3_stmt *vm;
|
||||
const char *tail;
|
||||
int err;
|
||||
QString sTableSQL;
|
||||
|
||||
QString statement = QString("SELECT sql FROM sqlite_master WHERE name='%1';").arg(sTable);
|
||||
|
||||
QByteArray utf8Statement = statement.toUtf8();
|
||||
err=sqlite3_prepare(_db, utf8Statement, utf8Statement.length(),
|
||||
&vm, &tail);
|
||||
if (err == SQLITE_OK){
|
||||
logSQL(statement, kLogMsg_App);
|
||||
if( sqlite3_step(vm) == SQLITE_ROW )
|
||||
{
|
||||
return QString::fromUtf8((const char*)sqlite3_column_text(vm, 0));
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
qCritical() << "Unable to get sql for table: " << sTable;
|
||||
}
|
||||
|
||||
return sTableSQL;
|
||||
}
|
||||
|
||||
void DBBrowserDB::updateSchema( )
|
||||
{
|
||||
|
||||
@@ -86,6 +86,14 @@ public:
|
||||
bool dump( const QString & filename);
|
||||
bool reload( const QString & filename, int * lineErr);
|
||||
bool executeSQL ( const QString & statement, bool dirtyDB=true, bool logsql=true);
|
||||
|
||||
/**
|
||||
* @brief getTableSQL Returns the create table statement for the given table.
|
||||
* @param sTable Table name
|
||||
* @return An empty string if the table does not exist
|
||||
* or the create table statement.
|
||||
*/
|
||||
QString getTableSQL(const QString& sTable);
|
||||
void updateSchema() ;
|
||||
bool addRecord();
|
||||
bool deleteRecord(int wrow);
|
||||
|
||||
Reference in New Issue
Block a user