Skip to content

Commit

Permalink
User Collation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdochoa committed Oct 17, 2023
1 parent dfb0eb9 commit 2c9ff80
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 124 deletions.
21 changes: 21 additions & 0 deletions html-templates/COLLATION.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<head>
<title>Collation</title>
</head>
<body>
{%header:Summary%}
<br>
<br>
<font size=+2>{%object_name%}</font>
<br>{%object_description%} [<a
href="fr://edit_description?parent_window={%parent_window%}&amp;object_handle={%object_handle%}&amp;object_type=COLLATION&amp;object_name={%object_name%}">edit</a>]
<br><br>
<table cellspacing=1 cellpadding=3 border=0 width="98%" bgcolor="black">
<tr><td bgcolor="navy"><font color=white><b>Collation info</b></font></td>
</tr>
<tr><td bgcolor="#DDDDFF"><font size=-1>
<pre>{%object_ddl%}
</pre></font></td></tr>
</table>
</body>
</html>
53 changes: 53 additions & 0 deletions html-templates/COLLATIONprivileges.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<html>
<head>
<title>Privileges</title>
</head>
<body>
{%header:Privileges%}
<br><br>
<font size=+2>Privileges on {%object_name%}</font>
<br><br>
<table cellspacing=1 cellpadding=2 border=0 bgcolor=black>
<tbody>
<tr bgcolor="navy">
<td><b><font color="white">Grantee</font></b></td>
<td><b><font color="white">USAGE</font></b></td>
</tr>
{%foreach:privilege::
<tr bgcolor="{%alternate:#DDDDFF:#CCCCFF%}">
<td nowrap valign="top">{%privilegeinfo:grantee_name%}</td>
<td nowrap valign="top" align="center">{%foreach:privilegeitem:<br>:USAGE:<a href="info://Granted by {%privilegeiteminfo:grantor%}">
<img src="{%template_root%}{%ifeq:{%privilegeiteminfo:grant_option%}:true:ok2.png:ok.png%}"></a><font size="-1">{%privilegeiteminfo:columns%}</font>%}
{%ifeq:{%privilegeitemcount:USAGE%}:0:<img src="{%template_root%}redx.png">%}
</td>
</tr>%}
</tbody>
</table>
<br>
<br>
<a href="fr://manage_privileges?parent_window={%parent_window%}&amp;object_handle={%object_handle%}">Grant
and revoke privileges</a>
<br>
<br>
<table border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td colspan="2" bgcolor="#CCCCFF"><B>Icons</B></td>
</tr>
<tr bgcolor="#DDDDDD">
<td width="20"><img src="{%template_root%}redx.png"></td>
<td>privilege not granted</td>
</tr>
<tr bgcolor="#DDDDDD">
<td width="20"><img src="{%template_root%}ok.png"></td>
<td>privilege granted</td>
</tr>
<tr bgcolor="#DDDDDD">
<td width="20"><img src="{%template_root%}ok2.png"></td>
<td>privilege granted with grant option</td>
</tr>
<tr bgcolor="silver">
<td colspan=2><font size=-1>Hover over icons to see the grantor</font></td>
</tr>
</table>
</body>
</html>
2 changes: 1 addition & 1 deletion html-templates/EXCEPTION.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<br>
<font size=+2>{%object_name%}</font><br>
{%object_description%} [<a
href="fr://edit_description?parent_window={%parent_window%}&amp;object_handle={%object_handle%}&amp;object_type=TRIGGER&amp;object_name={%object_name%}">edit</a>]
href="fr://edit_description?parent_window={%parent_window%}&amp;object_handle={%object_handle%}&amp;object_type=EXCEPTION&amp;object_name={%object_name%}">edit</a>]
<br><br>
<table cellspacing=1 cellpadding=3 border=0 width="98%" bgcolor="black">
<tr>
Expand Down
35 changes: 35 additions & 0 deletions src/core/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,38 @@ wxString wrapText(const wxString& text, size_t maxWidth, size_t indent)
return wrappedText;
}


wxString IBPPtype2string(Database* db, IBPP::SDT t, int subtype, int size,
int scale)
{
if (scale > 0)
return wxString::Format("NUMERIC(%d,%d)", size == 4 ? 9 : 18, scale);
if (t == IBPP::sdString)
{
int bpc = db->getCharsetById(subtype)->getBytesPerChar();
if (subtype == 1) // charset OCTETS
return wxString::Format("OCTETS(%d)", bpc ? size / bpc : size);
return wxString::Format("STRING(%d)", bpc ? size / bpc : size);
}
switch (t)
{
case IBPP::sdArray: return "ARRAY";
case IBPP::sdBlob: return wxString::Format("BLOB SUB_TYPE %d", subtype);
case IBPP::sdDate: return "DATE";
case IBPP::sdTime: return "TIME";
case IBPP::sdTimestamp: return "TIMESTAMP";
case IBPP::sdSmallint: return "SMALLINT";
case IBPP::sdInteger: return "INTEGER";
case IBPP::sdLargeint: return "BIGINT";
case IBPP::sdFloat: return "FLOAT";
case IBPP::sdDouble: return "DOUBLE PRECISION";
case IBPP::sdBoolean: return "BOOLEAN";
case IBPP::sdTimeTz: return "TIME WITH TIMEZONE";
case IBPP::sdTimestampTz: return "TIMESTAMP WITH TIMEZONE";
case IBPP::sdInt128: return "INT128";
case IBPP::sdDec16: return "DECFLOAT(16)";
case IBPP::sdDec34: return "DECFLOAT(34)";
default: return "UNKNOWN";
}
}

5 changes: 5 additions & 0 deletions src/core/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#include <string>

#include "metadata/CharacterSet.h"
#include "metadata/database.h"

std::string wx2std(const wxString& input, wxMBConv* conv = wxConvCurrent);

Expand Down Expand Up @@ -60,4 +62,7 @@ wxString loadEntireFile(const wxFileName& filename);
// Code adapted from wxWidgets' wxTextWrapper function.
wxString wrapText(const wxString& text, size_t maxWidth, size_t indent);


wxString IBPPtype2string(Database* db, IBPP::SDT t, int subtype, int size, int scale);

#endif // FR_STRINGUTILS_H
1 change: 1 addition & 0 deletions src/gui/CommandIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ enum {
Menu_ToggleDisconnected,

// create new ... (stuff)
Menu_CreateCollation,
Menu_CreateDBTrigger,
Menu_CreateDDLTrigger,
Menu_CreateDMLTrigger,
Expand Down
35 changes: 35 additions & 0 deletions src/gui/ContextMenuMetadataItemVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "config/Config.h"
#include "gui/CommandIds.h"
#include "gui/ContextMenuMetadataItemVisitor.h"
#include "metadata/CharacterSet.h"
#include "metadata/Collation.h"
#include "metadata/column.h"
#include "metadata/domain.h"
#include "metadata/database.h"
Expand Down Expand Up @@ -481,6 +483,39 @@ void MainObjectMenuMetadataItemVisitor::visitViews(Views& views)
addRefreshItem();
}

void MainObjectMenuMetadataItemVisitor::visitCharacterSet(CharacterSet& charset)
{
addAlterItem(charset);
addSeparator();
addPropertiesItem();
}

void MainObjectMenuMetadataItemVisitor::visitCharacterSets(CharacterSets& charsets)
{
addRefreshItem();
}

void MainObjectMenuMetadataItemVisitor::visitCollation(Collation& collation)
{
addAlterItem(collation);
addSeparator();
addPropertiesItem();
}

void MainObjectMenuMetadataItemVisitor::visitCollations(Collations& collations)
{
addRefreshItem();
}

void MainObjectMenuMetadataItemVisitor::visitUserCollations(UserCollations& coolations)
{
addCreateItem();
addSeparator();
addGenerateCodeMenu(coolations);
addSeparator();
addRefreshItem();
}

void MainObjectMenuMetadataItemVisitor::visitIndex(Index& index)
{
//menuM->Append(Cmds::Menu_ShowStatisticsValue, _("Show &statistics"));
Expand Down
6 changes: 6 additions & 0 deletions src/gui/ContextMenuMetadataItemVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ class MainObjectMenuMetadataItemVisitor : public MetadataItemVisitor
virtual void visitUsers(Users& users);
virtual void visitView(View& view);
virtual void visitViews(Views& views);
virtual void visitCharacterSet(CharacterSet& charset);
virtual void visitCharacterSets(CharacterSets& charsets);
virtual void visitCollation(Collation& collation);
virtual void visitCollations(Collations& collations);
virtual void visitUserCollations(UserCollations& coolations);

protected:
wxMenu* menuM;
virtual void addCreateItem();
Expand Down
35 changes: 0 additions & 35 deletions src/gui/ExecuteSqlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2237,41 +2237,6 @@ void ExecuteSqlFrame::OnMenuUpdateWhenExecutePossible(wxUpdateUIEvent& event)
event.Enable(!closeWhenTransactionDoneM);
}

wxString IBPPtype2string(Database *db, IBPP::SDT t, int subtype, int size,
int scale)
{
if (scale > 0)
return wxString::Format("NUMERIC(%d,%d)", size==4 ? 9:18, scale);
if (t == IBPP::sdString)
{
//CharacterSet cs = db->getCharacterSets()->findById(subtype)->getBytesPerChar();
//int bpc = cs.getBytesPerChar();
int bpc = db->getCharacterSets()->findById(subtype)->getBytesPerChar();
return wxString::Format("STRING(%d)", bpc ? size/bpc : size);
}
switch (t)
{
case IBPP::sdArray: return "ARRAY";
case IBPP::sdBlob: return wxString::Format(
"BLOB SUB_TYPE %d", subtype);
case IBPP::sdDate: return "DATE";
case IBPP::sdTime: return "TIME";
case IBPP::sdTimestamp: return "TIMESTAMP";
case IBPP::sdSmallint: return "SMALLINT";
case IBPP::sdInteger: return "INTEGER";
case IBPP::sdLargeint: return "BIGINT";
case IBPP::sdFloat: return "FLOAT";
case IBPP::sdDouble: return "DOUBLE PRECISION";
case IBPP::sdBoolean: return "BOOLEAN";
case IBPP::sdTimeTz: return "TIME WITH TIMEZONE";
case IBPP::sdTimestampTz: return "TIMESTAMP WITH TIMEZONE";
case IBPP::sdInt128: return "INT128";
case IBPP::sdDec16: return "DECFLOAT(16)";
case IBPP::sdDec34: return "DECFLOAT(34)";
default: return "UNKNOWN";
}
}

void ExecuteSqlFrame::compareCounts(IBPP::DatabaseCounts& one,
IBPP::DatabaseCounts& two)
{
Expand Down
8 changes: 8 additions & 0 deletions src/gui/HtmlHeaderMetadataItemVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ void HtmlHeaderMetadataItemVisitor::visitView(View& /*view*/)
addDDL();
}

void HtmlHeaderMetadataItemVisitor::visitCollation(Collation& /*collation*/)
{
emptyTitles();
addSummary();
addDependencies();
addDDL();
}

void HtmlHeaderMetadataItemVisitor::defaultAction()
{
emptyTitles();
Expand Down
1 change: 1 addition & 0 deletions src/gui/HtmlHeaderMetadataItemVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class HtmlHeaderMetadataItemVisitor: public MetadataItemVisitor
virtual void visitGTTable(GTTable& table);
virtual void visitUDF(UDF & function);
virtual void visitView(View& view);
virtual void visitCollation(Collation& collation);
protected:
virtual void defaultAction();
private:
Expand Down
31 changes: 1 addition & 30 deletions src/gui/InsertParametersDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,37 +117,8 @@ namespace InsertParametersOptions
}


wxString IBPPtype2string(Database *db, IBPP::SDT t, int subtype, int size,
int scale)
{
if (scale > 0)
return wxString::Format("NUMERIC(%d,%d)", size==4 ? 9:18, scale);
if (t == IBPP::sdString)
{
int bpc = db->getCharsetById(subtype).getBytesPerChar();
if (subtype == 1) // charset OCTETS
return wxString::Format("OCTETS(%d)", bpc ? size / bpc : size);
return wxString::Format("STRING(%d)", bpc ? size/bpc : size);
}
switch (t)
{
case IBPP::sdArray: return "ARRAY";
case IBPP::sdBlob: return wxString::Format(
"BLOB SUB_TYPE %d", subtype);
case IBPP::sdDate: return "DATE";
case IBPP::sdTime: return "TIME";
case IBPP::sdTimestamp: return "TIMESTAMP";
case IBPP::sdSmallint: return "SMALLINT";
case IBPP::sdInteger: return "INTEGER";
case IBPP::sdLargeint: return "BIGINT";
case IBPP::sdFloat: return "FLOAT";
case IBPP::sdDouble: return "DOUBLE PRECISION";
case IBPP::sdBoolean: return "BOOLEAN";
default: return "UNKNOWN";
}
}

};

using namespace InsertParametersOptions;
/*
Generator *findAutoincGenerator2(std::vector<Trigger *>& triggers, Column *c)
Expand Down
10 changes: 9 additions & 1 deletion src/gui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ void MainFrame::buildMainMenu()

objectMenuM = new wxMenu();
wxMenu* newMenu = new wxMenu();
newMenu->Append(Cmds::Menu_CreateCollation, _("&Collation"));
newMenu->Append(Cmds::Menu_CreateDBTrigger, _("D&B Trigger"));
newMenu->Append(Cmds::Menu_CreateDDLTrigger, _("DD&L Trigger"));
newMenu->Append(Cmds::Menu_CreateDMLTrigger, _("DML Tr&igger"));
newMenu->Append(Cmds::Menu_CreateDomain, _("&Domain"));
newMenu->Append(Cmds::Menu_CreateException, _("&Exception"));
newMenu->Append(Cmds::Menu_CreateFunction, _("&Function"));
newMenu->Append(Cmds::Menu_CreateGenerator, _("&Generator"));
newMenu->Append(Cmds::Menu_CreateGTTTable, _("Global Temporary"));
newMenu->Append(Cmds::Menu_CreateGTTTable, _("Global &Temporary"));
newMenu->Append(Cmds::Menu_CreateIndex, _("&Index"));
newMenu->Append(Cmds::Menu_CreatePackage, _("P&ackage"));
newMenu->Append(Cmds::Menu_CreateProcedure, _("&Procedure"));
Expand Down Expand Up @@ -466,6 +467,7 @@ EVT_UPDATE_UI(Cmds::Menu_StartupDatabase, MainFrame::OnMenuUpdateIfDatabaseNotCo
EVT_BUTTON(MainFrame::ID_button_prev, MainFrame::OnButtonPrevClick)
EVT_BUTTON(MainFrame::ID_button_next, MainFrame::OnButtonNextClick)

EVT_MENU(Cmds::Menu_CreateCollation, MainFrame::OnMenuCreateCollation)
EVT_MENU(Cmds::Menu_CreateDBTrigger, MainFrame::OnMenuCreateDBTrigger)
EVT_MENU(Cmds::Menu_CreateDDLTrigger, MainFrame::OnMenuCreateDDLTrigger)
EVT_MENU(Cmds::Menu_CreateDMLTrigger, MainFrame::OnMenuCreateDMLTrigger)
Expand Down Expand Up @@ -1520,6 +1522,12 @@ void MainFrame::showCreateTemplate(const wxString& statement)
showSql(this, wxEmptyString, db, statement);
}

void MainFrame::OnMenuCreateCollation(wxCommandEvent& event)
{
showCreateTemplate(
MetadataItemCreateStatementVisitor::getCreateCollationStatment());
}

void MainFrame::OnMenuAddColumn(wxCommandEvent& WXUNUSED(event))
{
Table* t = dynamic_cast<Table*>(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 @@ -109,6 +109,7 @@ class MainFrame: public BaseFrame, private URIHandler,

// create new object
void showCreateTemplate(const wxString& statement);
void OnMenuCreateCollation(wxCommandEvent& event);
void OnMenuCreateDBTrigger(wxCommandEvent& event);
void OnMenuCreateDDLTrigger(wxCommandEvent& event);
void OnMenuCreateDMLTrigger(wxCommandEvent& event);
Expand Down
4 changes: 1 addition & 3 deletions src/gui/controls/DataGridRows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,9 +2123,7 @@ bool DataGridRows::initialize(const IBPP::Statement& statement)

case IBPP::sdString:
{
//CharacterSet cs = databaseM->getCharsetById(statement->ColumnSubtype(col));
//int bpc = cs.getBytesPerChar();
int bpc = databaseM->getCharacterSets()->findById(statement->ColumnSubtype(col))->getBytesPerChar();
int bpc = databaseM->getCharsetById(statement->ColumnSubtype(col))->getBytesPerChar();
int size = statement->ColumnSize(col);
if (bpc)
size /= bpc;
Expand Down
Loading

0 comments on commit 2c9ff80

Please sign in to comment.