Skip to content

Commit

Permalink
Merge pull request #350 from arvanus/newVolatileSQLEditor
Browse files Browse the repository at this point in the history
New volatile sql editor
  • Loading branch information
arvanus authored Nov 12, 2023
2 parents 7bae230 + 4375da4 commit f82f05c
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ env:

on:
push:
branches: [ "master", "dev" ]
branches: [ "**" ]
pull_request:
branches: [ "master", "dev" ]
branches: [ "**" ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(flamerobin)
cmake_minimum_required(VERSION 3.0)

# Don't allow in-source builds. Keeps things nice and tidy
if( "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}" )
Expand Down
20 changes: 19 additions & 1 deletion docs/fr_whatsnew.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@
http://www.flamerobin.org/bugs.php or https://github.com/mariuz/flamerobin/issues</font><br>
<br><br>
<!-- *********************** section starts here ************************ -->
<font size=+2>Changes in FlameRobin 0.9.9 and 0.9.10</font><br>
<font size=+2>Changes in FlameRobin 0.9.10</font><br>
<br><br>
<font size=+1 color="#AA0000"><B>New features</B></font><br>
- New "Volatile" SQL Editor, allows you to use CREATE DATABASE, CONNECT and DISCONNECT in your script, increasing the flexibility to do maintenance across several databases. To use this feature you need to go to <strong>Database->Open new Volatile SQL Editor<strong>. Use with attention<br>
<br>
<font size=+1 color="#AA0000"><B>Enhancements and Bug fixes</B></font><br>
<br>
- New collation tree view<br>
- Many other small fixes, see commit history for more details :)<br>
<br>
For more info please read commit history log<br>
<br>
<br>
<br>
<br>
<br>
<!-- ***************************** section ends here ******************* -->
<!-- *********************** section starts here ************************ -->
<font size=+2>Changes in FlameRobin 0.9.9</font><br>
<br><br>
<font size=+1 color="#AA0000"><B>Enhancements and Bug fixes</B></font><br>
<br>
Expand Down
11 changes: 11 additions & 0 deletions src/frutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ bool getService(Server* s, IBPP::Service& svc, ProgressIndicator* p,
return true;
}

wxString unquote(const wxString& input, const wxString& quoteChar)
{
wxString result = input;

if (result.StartsWith(quoteChar) && result.EndsWith(quoteChar) && result.length() >= 2) {
result = result.Mid(1, result.length() - 2);
}

return result;
}

wxString getClientLibrary()
{
/*Todo: Implement FB library per conexion */
Expand Down
2 changes: 2 additions & 0 deletions src/frutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ bool connectDatabase(Database *db, wxWindow* parent,
bool getService(Server* s, IBPP::Service& svc, ProgressIndicator* p,
bool sysdba);

wxString unquote(const wxString& input, const wxString& quoteChar = "\"");

wxString getClientLibrary();

#endif // FRUTILS_H
1 change: 1 addition & 0 deletions src/gui/CommandIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ enum {
Menu_URLBugReport,
Menu_NewObject,
Menu_DatabaseRegistrationInfo,
Menu_NewVolatileSQLEditor,
Menu_RegisterDatabase,
Menu_CreateDatabase,
Menu_ManageUsers,
Expand Down
90 changes: 85 additions & 5 deletions src/gui/ExecuteSqlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,18 @@ ExecuteSqlFrame::ExecuteSqlFrame(wxWindow* WXUNUSED(parent), int id,
wxString title,
DatabasePtr db, const wxPoint& pos, const wxSize& size, long style)
: BaseFrame(wxTheApp->GetTopWindow(), id, title, pos, size, style),
Observer(), databaseM(db.get())
Observer(), databasePtrM(db) //changed for volatile SQL Editor, as we only have a fake server and database
{
wxASSERT(db);
//Need this 2 PtrM lines especifically to keep a reference for both original objects in volatile SQL Editor else the serverptr is released as soon as exists MainFrame event call
databaseM = databasePtrM.get();
serverPtrM = databasePtrM->getServer();

loadingM = true;
updateEditorCaretPosM = true;
updateFrameTitleM = true;
if (db->getIsVolative())
prepareVolatileDatabase();

transactionIsolationLevelM = static_cast<IBPP::TIL>(config().get("transactionIsolationLevel", 0));
transactionLockResolutionM = config().get("transactionLockResolution", true) ? IBPP::lrWait : IBPP::lrNoWait;
Expand Down Expand Up @@ -575,11 +580,11 @@ ExecuteSqlFrame::ExecuteSqlFrame(wxWindow* WXUNUSED(parent), int id,
do_layout();

// observe database object to close on disconnect / destruction
databaseM->attachObserver(this, false);
if (!db->getIsVolative()) databaseM->attachObserver(this, false);

executedStatementsM.clear();
inTransaction(false); // enable/disable controls
setKeywords(); // set words for autocomplete feature
if (!db->getIsVolative()) setKeywords(); // set words for autocomplete feature

historyPositionM = StatementHistory::get(databaseM).size();

Expand Down Expand Up @@ -804,7 +809,8 @@ void ExecuteSqlFrame::set_properties()
int statusbar_widths[] = { -2, 100, 60, -1 };
statusbar_1->SetStatusWidths(4, statusbar_widths);

statusbar_1->SetStatusText(databaseM->getConnectionInfoString(), 0);
if ( ! databaseM->getIsVolative() )
statusbar_1->SetStatusText(databaseM->getConnectionInfoString(), 0);
statusbar_1->SetStatusText("Rows fetched", 1);
statusbar_1->SetStatusText("Cursor position", 2);
statusbar_1->SetStatusText("Transaction status", 3);
Expand Down Expand Up @@ -879,7 +885,11 @@ void ExecuteSqlFrame::doBeforeDestroy()
if (grid_data->IsCellEditControlEnabled())
grid_data->EnableCellEditControl(false);
// make sure that further calls to update() will not call Close() again
if (databaseM->getIsVolative() && databaseM->isConnected())
databaseM->disconnect();
databaseM = 0;
databasePtrM = 0;
serverPtrM = 0;
}

void ExecuteSqlFrame::showProperties(wxString objectName)
Expand Down Expand Up @@ -2106,6 +2116,39 @@ void ExecuteSqlFrame::clearLogBeforeExecution()
styled_text_ctrl_stats->ClearAll();
}

void ExecuteSqlFrame::prepareVolatileDatabase(wxString hostname, wxString port, wxString path, wxString user, wxString password, wxString role, wxString charset)
{
/*DatabasePtr dbM = std::make_shared<Database>();
ServerPtr serverPtrM = std::make_shared<Server>();
dbM->setServer(serverPtrM);
databaseM = dbM.get();*/
//databaseM = new Database();
//databaseM = std::make_shared<Database>();
//databaseM->setId(UINT_MAX-30);
//this->serverM = new Server();
//serverPtrM = ServerPtr(serverM);
ServerPtr serverPtrM = databaseM->getServer();
if (!serverPtrM->getHostname().compare(hostname) || !serverPtrM->getPort().compare(port) || !databaseM->getPath().compare(path) || !databaseM->getUsername().compare(user) || !databaseM->getRawPassword().compare(password) || !databaseM->getRole().compare(role) || !databaseM->getDatabaseCharset().compare(charset))
{
databaseM->disconnect();
transactionM = 0;
}
else
return;

serverPtrM->setHostname(hostname);
serverPtrM->setPort(port);

databaseM->setPath(path);
databaseM->setName_("VOLATILECONNECTION");
databaseM->setUsername(user);
databaseM->setRawPassword(password);
databaseM->setRole(role);
databaseM->setConnectionCharset(charset);
//databaseM->setServer(serverPtrM);

}

void ExecuteSqlFrame::prepareAndExecute(bool prepareOnly)
{
bool hasSelection = styled_text_ctrl_sql->GetSelectionStart()
Expand Down Expand Up @@ -2330,7 +2373,45 @@ bool ExecuteSqlFrame::execute(wxString sql, const wxString& terminator,
log(_("Empty statement detected, bailing out..."));
return true;
}


SqlStatement stm(sql, databaseM, terminator);

if ((stm.getAction() == actCONNECT) || (stm.getAction() == actCREATE_DATABASE))
{
if (!databaseM->getIsVolative())
{
log(_("Cannot use 'connect' or 'create' statement in a regular SQL Script"), ttError);
splitScreen();
return false;
}
wxString connHostM, connDatabasePortM, connPathM, connUsernameM, connPasswordM, connRoleM, connCharsetM; int createPageSizeM, createDialecM;
stm.getCONNECTION(connHostM, connDatabasePortM, connPathM, connUsernameM, connPasswordM, connRoleM, connCharsetM);
prepareVolatileDatabase(connHostM, connDatabasePortM, connPathM, connUsernameM, connPasswordM, connRoleM, connCharsetM);
if (stm.getAction() == actCREATE_DATABASE) {
createPageSizeM = stm.getCreatePageSize();
createDialecM = stm.getCreateDialect();
log(wxString::Format("Creating database: %s, port: %s, database: %s, user: %s, password: %s, role: %s, charset: %s, page size: %d, dialect %d", connHostM, connDatabasePortM, connPathM, connUsernameM, connPasswordM, connRoleM, connCharsetM, createPageSizeM, createDialecM), ttSql);
databaseM->create(createPageSizeM, createDialecM);
}
log(wxString::Format("Connecting to host: %s, port: %s, database: %s, user: %s, password: %s, role: %s, charset: %s", connHostM, connDatabasePortM, connPathM, connUsernameM, connPasswordM, connRoleM, connCharsetM), ttSql);
databaseM->connect(databaseM->getRawPassword());
return databaseM->isConnected();

}
else
if (stm.getAction() == actDISCONNECT)
{
if (!databaseM->getIsVolative())
{
log(_("Cannot use 'disconnect' statement in a regular SQL Script"), ttError);
splitScreen();
return false;
}
databaseM->disconnect();
transactionM = 0;
return true;
}
if (styled_text_ctrl_sql->AutoCompActive())
styled_text_ctrl_sql->AutoCompCancel(); // remove the list if needed
notebook_1->SetSelection(0);
Expand Down Expand Up @@ -2513,7 +2594,6 @@ bool ExecuteSqlFrame::execute(wxString sql, const wxString& terminator,
{
}
}
SqlStatement stm(sql, databaseM, terminator);
if (stm.isDDL())
type = IBPP::stDDL;
executedStatementsM.push_back(stm);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/ExecuteSqlFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ class ExecuteSqlFrame: public BaseFrame, public Observer
typedef enum { ttNormal, ttSql, ttError } TextType;
void log(wxString s, TextType type = ttNormal); // write messages to textbox
void clearLogBeforeExecution();
void prepareVolatileDatabase(wxString server = "", wxString port = "3050", wxString db = "", wxString user = "", wxString password = "", wxString role = "", wxString charset = "NONE");

void splitScreen();
Database* databaseM;
DatabasePtr databasePtrM;
ServerPtr serverPtrM;

StatementHistory::Position historyPositionM;
wxString localBuffer;
Expand Down
16 changes: 16 additions & 0 deletions src/gui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ void MainFrame::buildMainMenu()
menuBarM = new wxMenuBar();

databaseMenuM = new wxMenu();
databaseMenuM->Append(Cmds::Menu_NewVolatileSQLEditor, _("Open new Volatile &SQL Editor..."));
databaseMenuM->Append(Cmds::Menu_RegisterDatabase, _("R&egister existing database..."));
databaseMenuM->Append(Cmds::Menu_CreateDatabase, _("Create &new database..."));
databaseMenuM->Append(Cmds::Menu_RestoreIntoNew, _("Restore bac&kup into new database..."));
Expand Down Expand Up @@ -374,6 +375,7 @@ EVT_MENU(Cmds::Menu_URLFeatureRequest, MainFrame::OnMenuURLFeatureRequest)
EVT_MENU(Cmds::Menu_URLBugReport, MainFrame::OnMenuURLBugReport)
EVT_MENU(wxID_PREFERENCES, MainFrame::OnMenuConfigure)

EVT_MENU(Cmds::Menu_NewVolatileSQLEditor, MainFrame::OnMenuNewVolatileSQLEditor)
EVT_MENU(Cmds::Menu_RegisterDatabase, MainFrame::OnMenuRegisterDatabase)
EVT_UPDATE_UI(Cmds::Menu_RegisterDatabase, MainFrame::OnMenuUpdateIfServerSelected)
EVT_MENU(Cmds::Menu_CreateDatabase, MainFrame::OnMenuCreateDatabase)
Expand Down Expand Up @@ -965,6 +967,20 @@ void MainFrame::OnMenuBrowseData(wxCommandEvent& WXUNUSED(event))
treeMainM->getSelectedMetadataItem(), this);
}

void MainFrame::OnMenuNewVolatileSQLEditor(wxCommandEvent& WXUNUSED(event))
{
DatabasePtr db;
ServerPtr serverPtrM;

db = std::make_shared<Database>();
serverPtrM = std::make_shared<Server>();
db->setServer(serverPtrM);
db->setId(UINT_MAX-30);
db->setIsVolatile(true);

ExecuteSqlFrame* eff = new ExecuteSqlFrame(this, -1, _("Omni SQL Editor"), db);
eff->Show();
}
void MainFrame::OnMenuRegisterDatabase(wxCommandEvent& WXUNUSED(event))
{
ServerPtr s = getServer(treeMainM->getSelectedMetadataItem());
Expand Down
1 change: 1 addition & 0 deletions src/gui/MainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MainFrame: public BaseFrame, private URIHandler,
void OnMenuURLFeatureRequest(wxCommandEvent& event);
void OnMenuURLBugReport(wxCommandEvent& event);
void OnMenuConfigure(wxCommandEvent& event);
void OnMenuNewVolatileSQLEditor(wxCommandEvent& event);
void OnMenuRegisterDatabase(wxCommandEvent& event);
void OnMenuCloneDatabase(wxCommandEvent& event);
void OnMenuDatabaseRegistrationInfo(wxCommandEvent& event);
Expand Down
14 changes: 12 additions & 2 deletions src/metadata/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ bool DatabaseAuthenticationMode::getUseEncryptedPassword() const
// Database class
Database::Database()
: MetadataItem(ntDatabase), metadataLoaderM(0), connectedM(false),
connectionCredentialsM(0), dialectM(3), idM(0)
connectionCredentialsM(0), dialectM(3), idM(0), volatileM(false)
{
defaultTimezoneM.name = "";
defaultTimezoneM.id = 0;
Expand Down Expand Up @@ -394,6 +394,11 @@ void Database::getDatabaseTriggers(std::vector<Trigger *>& list)
std::back_inserter(list), std::mem_fn(&DBTriggerPtr::get));
}

bool Database::getIsVolative()
{
return volatileM;
}

CharacterSetPtr Database::getCharsetById(int id)
{
// if it contains both charset and collation as 2 bytes
Expand Down Expand Up @@ -1888,6 +1893,11 @@ IBPP::Database& Database::getIBPPDatabase()
return databaseM;
}

void Database::setIsVolatile(const bool isVolatile)
{
volatileM = isVolatile;
}

void Database::setPath(const wxString& value)
{
pathM = value;
Expand Down Expand Up @@ -2197,7 +2207,7 @@ void Database::getConnectedUsers(wxArrayString& users) const
{
wxString name((*it).first);
if ((*it).second > 1)
name += wxString::Format(" (%d)", (*it).second);
name += wxString::Format(" (%zu)", (*it).second);
users.Add(name);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/metadata/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class Database: public MetadataItem,
MetadataLoader* metadataLoaderM;

bool connectedM;
bool volatileM;
wxString databaseCharsetM;
wxString connectionUserM;
wxString connectionRoleM;
Expand Down Expand Up @@ -322,6 +323,7 @@ class Database: public MetadataItem,
//! gets the database triggers (FB2.1+)
void getDatabaseTriggers(std::vector<Trigger *>& list);

bool getIsVolative();
wxString getPath() const;
wxString getClientLibrary() const;
int getSqlDialect() const;
Expand All @@ -335,6 +337,7 @@ class Database: public MetadataItem,
DatabaseAuthenticationMode& getAuthenticationMode();
wxString getRole() const;
IBPP::Database& getIBPPDatabase();
void setIsVolatile(const bool isVolatile);
void setPath(const wxString& value);
void setClientLibrary(const wxString& value);
void setConnectionCharset(const wxString& value);
Expand Down
Loading

0 comments on commit f82f05c

Please sign in to comment.