46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
|
|
#ifndef EXECUTE_SQL_FILE_H
|
||
|
|
#define EXECUTE_SQL_FILE_H
|
||
|
|
|
||
|
|
#include <QDebug>
|
||
|
|
#include <QFile>
|
||
|
|
#include <QSqlDatabase>
|
||
|
|
#include <QSqlError>
|
||
|
|
#include <QSqlQuery>
|
||
|
|
#include <QTextStream>
|
||
|
|
|
||
|
|
class ExecuteSqlFile {
|
||
|
|
private:
|
||
|
|
QSqlDatabase &db_; // Reference to the database handler
|
||
|
|
|
||
|
|
// Tracks if the parser is inside a trigger block
|
||
|
|
bool insideTrigger_ = false;
|
||
|
|
|
||
|
|
// Delimiter for SQL statements
|
||
|
|
QString delimiter_;
|
||
|
|
|
||
|
|
public:
|
||
|
|
// Constructor to initialize the database handler
|
||
|
|
explicit ExecuteSqlFile(QSqlDatabase &db);
|
||
|
|
|
||
|
|
// Executes the SQL commands from the given file
|
||
|
|
bool operator()(const QString &filePath);
|
||
|
|
|
||
|
|
private:
|
||
|
|
// Executes a single SQL statement
|
||
|
|
bool executeStatement(const QString &statement) const;
|
||
|
|
|
||
|
|
// Filter out comments and empty lines
|
||
|
|
bool filterLine(QString &line);
|
||
|
|
|
||
|
|
// Processes the DELIMITER command
|
||
|
|
bool processDelimiterChange(QString &line);
|
||
|
|
|
||
|
|
// Processes a single line of SQL and updates the current state
|
||
|
|
bool processLine(QString &line, QString ¤tStatement);
|
||
|
|
|
||
|
|
// Processes a block of SQL statements, handling triggers separately
|
||
|
|
bool processStatements(QStringList &statements);
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif // EXECUTE_SQL_FILE_H
|