Permalink
Browse files

Fixed IN/OUT keywords on functions signature (issue #163)

Major changes on SQL code generation/export. Introduced a token to
help export process to identify the end of each DDL command.

Minor improvements on role editing form.

Fixed a bug on ModelExportForm that was truncating commands wrongly.
  • Loading branch information...
1 parent bc3fe52 commit e8cb41a41e1efaceb6182b457254c44b2d2a1c7c @rkhaotix rkhaotix committed Mar 15, 2013
Showing with 600 additions and 356 deletions.
  1. +1 −3 libparsers/src/schemaparser.cpp
  2. +9 −8 libpgmodeler/src/function.cpp
  3. +1 −0 libpgmodeler/src/function.h
  4. +5 −5 libpgmodeler/src/role.cpp
  5. +3 −3 libpgmodeler/src/role.h
  6. +3 −2 libpgmodeler_ui/src/mainwindow.cpp
  7. +4 −4 libpgmodeler_ui/src/modelexportform.cpp
  8. +3 −0 libpgmodeler_ui/src/modelobjectswidget.cpp
  9. +23 −22 libpgmodeler_ui/src/operationlistwidget.cpp
  10. +2 −2 libpgmodeler_ui/src/operationlistwidget.h
  11. +19 −2 libpgmodeler_ui/src/rolewidget.cpp
  12. +47 −41 libpgmodeler_ui/ui/rolewidget.ui
  13. +2 −1 libutil/src/parsersattributes.h
  14. +29 −29 samples/sample2.dbm
  15. +7 −4 schemas/sql/8.0/aggregate.sch
  16. +2 −2 schemas/sql/8.0/comment.sch
  17. +6 −2 schemas/sql/8.0/database.sch
  18. +6 −2 schemas/sql/8.0/function.sch
  19. +2 −2 schemas/sql/8.0/idxelement.sch
  20. +6 −3 schemas/sql/8.0/index.sch
  21. +6 −3 schemas/sql/8.0/language.sch
  22. +6 −3 schemas/sql/8.0/opclass.sch
  23. +7 −4 schemas/sql/8.0/operator.sch
  24. +9 −4 schemas/sql/8.0/parameter.sch
  25. +7 −4 schemas/sql/8.0/role.sch
  26. +6 −2 schemas/sql/8.0/sequence.sch
  27. +6 −2 schemas/sql/8.0/usertype.sch
  28. +6 −2 schemas/sql/8.1/aggregate.sch
  29. +6 −2 schemas/sql/8.1/function.sch
  30. +2 −2 schemas/sql/8.1/idxelement.sch
  31. +6 −2 schemas/sql/8.1/index.sch
  32. +6 −3 schemas/sql/8.1/opclass.sch
  33. +6 −2 schemas/sql/8.1/operator.sch
  34. +6 −2 schemas/sql/8.1/sequence.sch
  35. +6 −2 schemas/sql/8.1/usertype.sch
  36. +6 −2 schemas/sql/8.2/function.sch
  37. +2 −2 schemas/sql/8.2/idxelement.sch
  38. +6 −2 schemas/sql/8.2/index.sch
  39. +6 −2 schemas/sql/8.2/opclass.sch
  40. +6 −3 schemas/sql/8.2/operator.sch
  41. +6 −2 schemas/sql/8.2/usertype.sch
  42. +6 −2 schemas/sql/8.3/usertype.sch
  43. +6 −2 schemas/sql/8.4/cast.sch
  44. +5 −2 schemas/sql/8.4/database.sch
  45. +2 −2 schemas/sql/8.4/element.sch
  46. +6 −3 schemas/sql/8.4/grant.sch
  47. +12 −6 schemas/sql/8.4/parameter.sch
  48. +6 −2 schemas/sql/8.4/usertype.sch
  49. +6 −3 schemas/sql/9.0/grant.sch
  50. +6 −2 schemas/sql/9.0/trigger.sch
  51. +6 −3 schemas/sql/9.1/grant.sch
  52. +6 −2 schemas/sql/9.1/trigger.sch
  53. +5 −2 schemas/sql/common/aggregate.sch
  54. +5 −2 schemas/sql/common/cast.sch
  55. +2 −2 schemas/sql/common/column.sch
  56. +2 −2 schemas/sql/common/comment.sch
  57. +6 −2 schemas/sql/common/constraint.sch
  58. +5 −3 schemas/sql/common/conversion.sch
  59. +6 −2 schemas/sql/common/database.sch
  60. +4 −2 schemas/sql/common/dbmodel.sch
  61. +6 −2 schemas/sql/common/domain.sch
  62. +2 −2 schemas/sql/common/element.sch
  63. +6 −3 schemas/sql/common/function.sch
  64. +6 −3 schemas/sql/common/grant.sch
  65. +2 −2 schemas/sql/common/idxelement.sch
  66. +5 −3 schemas/sql/common/index.sch
  67. +5 −2 schemas/sql/common/language.sch
  68. +5 −2 schemas/sql/common/opclass.sch
  69. +6 −2 schemas/sql/common/operator.sch
  70. +6 −3 schemas/sql/common/opfamily.sch
  71. +2 −2 schemas/sql/common/owner.sch
  72. +15 −4 schemas/sql/common/parameter.sch
  73. +2 −2 schemas/sql/common/relationship.sch
  74. +6 −2 schemas/sql/common/role.sch
  75. +6 −2 schemas/sql/common/rule.sch
  76. +6 −3 schemas/sql/common/schema.sch
  77. +6 −2 schemas/sql/common/sequence.sch
  78. +11 −3 schemas/sql/common/table.sch
  79. +6 −2 schemas/sql/common/tablespace.sch
  80. +6 −2 schemas/sql/common/trigger.sch
  81. +6 −2 schemas/sql/common/usertype.sch
  82. +6 −2 schemas/sql/common/view.sch
  83. +2 −2 schemas/xml/aggregate.sch
  84. +2 −2 schemas/xml/basetype.sch
  85. +2 −2 schemas/xml/cast.sch
  86. +2 −2 schemas/xml/column.sch
  87. +2 −2 schemas/xml/comment.sch
  88. +2 −3 schemas/xml/constraint.sch
  89. +2 −2 schemas/xml/conversion.sch
  90. +2 −2 schemas/xml/database.sch
  91. +2 −2 schemas/xml/dbmodel.sch
  92. +2 −2 schemas/xml/domain.sch
  93. +2 −2 schemas/xml/element.sch
  94. +2 −2 schemas/xml/function.sch
  95. +2 −2 schemas/xml/grant.sch
  96. +2 −2 schemas/xml/idxelement.sch
  97. +2 −2 schemas/xml/index.sch
  98. +2 −2 schemas/xml/label.sch
  99. +2 −2 schemas/xml/language.sch
  100. +2 −2 schemas/xml/opclass.sch
  101. +2 −2 schemas/xml/operator.sch
  102. +2 −2 schemas/xml/opfamily.sch
  103. +2 −2 schemas/xml/parameter.sch
  104. +2 −2 schemas/xml/position.sch
  105. +2 −2 schemas/xml/reference.sch
  106. +2 −2 schemas/xml/relationship.sch
  107. +2 −2 schemas/xml/role.sch
  108. +2 −2 schemas/xml/rule.sch
  109. +2 −2 schemas/xml/schema.sch
  110. +2 −2 schemas/xml/sequence.sch
  111. +2 −2 schemas/xml/table.sch
  112. +2 −2 schemas/xml/tablespace.sch
  113. +2 −2 schemas/xml/textbox.sch
  114. +2 −2 schemas/xml/trigger.sch
  115. +2 −2 schemas/xml/usertype.sch
  116. +2 −2 schemas/xml/view.sch
@@ -484,15 +484,13 @@ QString SchemaParser::convertCharsToXMLEntities(QString buf)
QRegExp("(\")(([\r\n\t])+|(\\ )+|(/>)+|(>)+)") //Regexp to find the attribute end ("\n|\r|\t/>)
};
- int pos=0, pos1=0, prev_pos=0, count=0;
+ int pos=0, pos1=0, count=0;
QString str_aux;
lin+="\n";
do
{
- prev_pos=pos1;
-
//Try to extract the values using regular expressions
pos=regexp_vect[0].indexIn(lin, pos);
pos+=regexp_vect[0].matchedLength();
@@ -60,6 +60,11 @@ void Parameter::operator = (const Parameter &param)
QString Parameter::getCodeDefinition(unsigned def_type)
{
+ return(this->getCodeDefinition(def_type, false));
+}
+
+QString Parameter::getCodeDefinition(unsigned def_type, bool reduced_form)
+{
if(def_type==SchemaParser::SQL_DEFINITION)
attributes[ParsersAttributes::NAME]=BaseObject::formatName(obj_name);
else
@@ -70,7 +75,7 @@ QString Parameter::getCodeDefinition(unsigned def_type)
attributes[ParsersAttributes::DEFAULT_VALUE]=default_value;
attributes[ParsersAttributes::TYPE]=type.getCodeDefinition(def_type);
- return(BaseObject::__getCodeDefinition(def_type));
+ return(BaseObject::getCodeDefinition(def_type, reduced_form));
}
unsigned Function::function_id=40000;
@@ -453,20 +458,16 @@ QString Function::getSignature(void)
void Function::createSignature(bool format)
{
- Parameter param;
QString str_param;
unsigned i, count;
count=parameters.size();
for(i=0; i < count; i++)
- {
- param=parameters[i];
- str_param+=(*param.getType());
+ str_param+=parameters[i].getCodeDefinition(SchemaParser::SQL_DEFINITION, true).trimmed();
- if(i < (count-1)) str_param+=",";
- }
+ str_param.remove(str_param.length()-1, 1);
- //Signature format NAME(PARAM1_TYPE,PARAM2_TYPE,...,PARAMn_TYPE)
+ //Signature format NAME(IN|OUT PARAM1_TYPE,IN|OUT PARAM2_TYPE,...,IN|OUT PARAMn_TYPE)
signature=this->getName(format) + QString("(") + str_param + QString(")");
}
@@ -49,6 +49,7 @@ class Parameter: public Column {
//! \brief Returns the SQL / XML code definition for the parameter
QString getCodeDefinition(unsigned def_type);
+ QString getCodeDefinition(unsigned def_type, bool reduced_form);
void operator = (const Parameter &param);
};
View
@@ -24,7 +24,7 @@ Role::Role(void)
{
obj_type=OBJ_ROLE;
object_id=Role::role_id++;
- sysid=100;
+ sysid=-1;
for(unsigned i=0; i < 6; i++)
options[i]=false;
@@ -47,10 +47,10 @@ Role::Role(void)
attributes[ParsersAttributes::GROUP]="";
}
-void Role::setSysid(unsigned sysid)
+void Role::setSysid(int sysid)
{
//Raises an error if the id is less then 100 (sysid < 100 are system reserved)
- if(sysid < 100)
+ if(sysid >=0 && sysid < 100)
throw Exception(ERR_ASG_INV_ID_USER,__PRETTY_FUNCTION__,__FILE__,__LINE__);
this->sysid=sysid;
@@ -261,7 +261,7 @@ bool Role::isRoleExists(unsigned role_type, Role *role)
return(found);
}
-unsigned Role::getSysid(void)
+int Role::getSysid(void)
{
return(sysid);
}
@@ -351,7 +351,7 @@ QString Role::getCodeDefinition(unsigned def_type)
if(conn_limit >= 0)
attributes[ParsersAttributes::CONN_LIMIT]=QString("%1").arg(conn_limit);
- attributes[ParsersAttributes::SYSID]=QString("%1").arg(sysid);
+ attributes[ParsersAttributes::SYSID]=(sysid >=0 ? QString("%1").arg(sysid) : "");
return(BaseObject::__getCodeDefinition(def_type));
}
View
@@ -33,7 +33,7 @@ class Role: public BaseObject {
static unsigned role_id;
//! \brief Role id
- unsigned sysid;
+ int sysid;
/*! \brief Options for the role (SUPERUSER, CREATEDB, CREATEROLE,
INHERIT, LOGIN, ENCRYPTED) */
@@ -77,7 +77,7 @@ class Role: public BaseObject {
Role(void);
//! \brief Sets the role id
- void setSysid(unsigned uid);
+ void setSysid(int uid);
//! \brief Sets one option for the role (Via OP_??? constants)
void setOption(unsigned op_type, bool value);
@@ -123,7 +123,7 @@ class Role: public BaseObject {
QString getPassword(void);
//! \brief Returns the role id on the system
- unsigned getSysid(void);
+ int getSysid(void);
//! \brief Returns the SQL / XML definition for the role
QString getCodeDefinition(unsigned def_type);
@@ -125,6 +125,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
export_form=new ModelExportForm(this);
restoration_form=new ModelRestorationForm(this);
+
oper_list_wgt=new OperationListWidget;
model_objs_wgt=new ModelObjectsWidget;
overview_wgt=new ModelOverviewWidget;
@@ -691,7 +692,7 @@ void MainWindow::setCurrentModel(void)
updateToolsState();
- oper_list_wgt->setModelWidget(current_model);
+ oper_list_wgt->setModel(current_model);
model_objs_wgt->setModel(current_model);
if(current_model)
@@ -844,7 +845,7 @@ void MainWindow::closeModel(int model_id)
current_model=NULL;
this->showFullScreen(false);
model_objs_wgt->setModel(static_cast<DatabaseModel *>(NULL));
- oper_list_wgt->setModelWidget(static_cast<ModelWidget *>(NULL));
+ oper_list_wgt->setModel(static_cast<ModelWidget *>(NULL));
updateToolsState(true);
}
else
@@ -264,14 +264,14 @@ void ModelExportForm::exportModel(void)
try
{
sql_cmd.clear();
- sql_cmd=sql_cmd.trimmed();
- //Extract the characters until the end of buffer o a semicolon
+ //Extract the characters until the end of buffer or until the end of ddl-end token
while(i < count)
{
- if(sql_buf.at(i)==';' && sql_buf.at(i+1)=='\n')
+ if(sql_cmd.indexOf(ParsersAttributes::DDL_END_TOKEN) >= 0)
{
- sql_cmd+=';';
+ sql_cmd.remove(ParsersAttributes::DDL_END_TOKEN);
+ sql_cmd.simplified();
break;
}
else
@@ -32,8 +32,11 @@ ModelObjectsWidget::ModelObjectsWidget(bool simplified_view, QWidget *parent, Qt
QString str_aux;
setupUi(this);
+
model_wgt=NULL;
db_model=NULL;
+ this->setModel(db_model);
+
this->simplified_view=simplified_view;
this->save_tree_state=!simplified_view;
@@ -24,7 +24,8 @@ extern TaskProgressWidget *task_prog_wgt;
OperationListWidget::OperationListWidget(QWidget *parent, Qt::WindowFlags f) : QDockWidget(parent, f)
{
setupUi(this);
- modelo_wgt=NULL;
+ setModel(NULL);
+
operations_tw->headerItem()->setHidden(true);
connect(undo_tb,SIGNAL(clicked()),this,SLOT(undoOperation(void)));
connect(redo_tb,SIGNAL(clicked()),this,SLOT(redoOperation(void)));
@@ -49,7 +50,7 @@ void OperationListWidget::selectItem(QTreeWidgetItem *item, int)
void OperationListWidget::updateOperationList(void)
{
- if(!modelo_wgt)
+ if(!model_wgt)
{
operations_tw->clear();
dockWidgetContents->setEnabled(false);
@@ -66,21 +67,21 @@ void OperationListWidget::updateOperationList(void)
bool value=false;
dockWidgetContents->setEnabled(true);
- op_count_lbl->setText(QString("%1").arg(modelo_wgt->op_list->getCurrentSize()));
- current_pos_lbl->setText(QString("%1").arg(modelo_wgt->op_list->getCurrentIndex()));
- redo_tb->setEnabled(modelo_wgt->op_list->isRedoAvailable());
- undo_tb->setEnabled(modelo_wgt->op_list->isUndoAvailable());
+ op_count_lbl->setText(QString("%1").arg(model_wgt->op_list->getCurrentSize()));
+ current_pos_lbl->setText(QString("%1").arg(model_wgt->op_list->getCurrentIndex()));
+ redo_tb->setEnabled(model_wgt->op_list->isRedoAvailable());
+ undo_tb->setEnabled(model_wgt->op_list->isUndoAvailable());
- count=modelo_wgt->op_list->getCurrentSize();
+ count=model_wgt->op_list->getCurrentSize();
operations_tw->clear();
rem_operations_tb->setEnabled(count > 0);
for(i=0; i < count; i++)
{
- modelo_wgt->op_list->getOperationData(i,op_type,obj_name,obj_type);
+ model_wgt->op_list->getOperationData(i,op_type,obj_name,obj_type);
- value=(i==static_cast<unsigned>(modelo_wgt->op_list->getCurrentIndex()-1));
+ value=(i==static_cast<unsigned>(model_wgt->op_list->getCurrentIndex()-1));
font.setBold(value);
font.setItalic(value);
@@ -138,34 +139,34 @@ void OperationListWidget::updateOperationList(void)
emit s_operationListUpdated();
}
-void OperationListWidget::setModelWidget(ModelWidget *model)
+void OperationListWidget::setModel(ModelWidget *model)
{
operations_tw->clear();
- this->modelo_wgt=model;
+ this->model_wgt=model;
updateOperationList();
}
void OperationListWidget::undoOperation(void)
{
try
{
- connect(modelo_wgt->op_list, SIGNAL(s_operationExecuted(int,QString,unsigned)), task_prog_wgt, SLOT(updateProgress(int,QString,unsigned)));
+ connect(model_wgt->op_list, SIGNAL(s_operationExecuted(int,QString,unsigned)), task_prog_wgt, SLOT(updateProgress(int,QString,unsigned)));
task_prog_wgt->setWindowTitle(trUtf8("Undoing operations..."));
task_prog_wgt->show();
- modelo_wgt->op_list->undoOperation();
+ model_wgt->op_list->undoOperation();
task_prog_wgt->close();
- disconnect(modelo_wgt->op_list, NULL, task_prog_wgt, NULL);
+ disconnect(model_wgt->op_list, NULL, task_prog_wgt, NULL);
notifyUpdateOnModel();
- modelo_wgt->scene->clearSelection();
+ model_wgt->scene->clearSelection();
}
catch(Exception &e)
{
task_prog_wgt->close();
- disconnect(modelo_wgt->op_list, NULL, task_prog_wgt, NULL);
+ disconnect(model_wgt->op_list, NULL, task_prog_wgt, NULL);
throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
}
}
@@ -174,23 +175,23 @@ void OperationListWidget::redoOperation(void)
{
try
{
- connect(modelo_wgt->op_list, SIGNAL(s_operationExecuted(int,QString,unsigned)), task_prog_wgt, SLOT(updateProgress(int,QString,unsigned)));
+ connect(model_wgt->op_list, SIGNAL(s_operationExecuted(int,QString,unsigned)), task_prog_wgt, SLOT(updateProgress(int,QString,unsigned)));
task_prog_wgt->setWindowTitle(trUtf8("Redoing operations..."));
task_prog_wgt->show();
- modelo_wgt->op_list->redoOperation();
+ model_wgt->op_list->redoOperation();
task_prog_wgt->close();
- disconnect(modelo_wgt->op_list, NULL, task_prog_wgt, NULL);
+ disconnect(model_wgt->op_list, NULL, task_prog_wgt, NULL);
notifyUpdateOnModel();
- modelo_wgt->scene->clearSelection();
+ model_wgt->scene->clearSelection();
}
catch(Exception &e)
{
task_prog_wgt->close();
- disconnect(modelo_wgt->op_list, NULL, task_prog_wgt, NULL);
+ disconnect(model_wgt->op_list, NULL, task_prog_wgt, NULL);
throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__, &e);
}
}
@@ -206,7 +207,7 @@ void OperationListWidget::removeOperations(void)
if(msg_box.result()==QDialog::Accepted)
{
- modelo_wgt->op_list->removeOperations();
+ model_wgt->op_list->removeOperations();
updateOperationList();
rem_operations_tb->setEnabled(false);
}
@@ -34,7 +34,7 @@ class OperationListWidget: public QDockWidget, public Ui::OperationListWidget {
private:
Q_OBJECT
- ModelWidget *modelo_wgt;
+ ModelWidget *model_wgt;
//! \brief Updates the operation list and emits the signal s_operationListUpdated to the connected objects
void notifyUpdateOnModel(void);
@@ -44,7 +44,7 @@ class OperationListWidget: public QDockWidget, public Ui::OperationListWidget {
public slots:
void updateOperationList(void);
- void setModelWidget(ModelWidget *model);
+ void setModel(ModelWidget *model);
void undoOperation(void);
void redoOperation(void);
void removeOperations(void);
@@ -24,11 +24,20 @@ RoleWidget::RoleWidget(QWidget *parent): BaseObjectWidget(parent, OBJ_ROLE)
{
ObjectTableWidget *obj_tab=NULL;
QGridLayout *grid=NULL;
+ QFrame *frame=NULL;
unsigned i;
Ui_RoleWidget::setupUi(this);
configureFormLayout(role_grid, OBJ_ROLE);
+
+ frame=generateInformationFrame(trUtf8("Assigning <strong><em>-1</em></strong> to <strong><em>SysID</em></strong> let PostgreSQL defines the role's id.<br/>\
+ Assigning <strong><em>-1</em></strong> to <strong><em>Connections</em></strong> creates a role without connection limit.<br/>\
+ Unchecking <strong><em>Validity</em></strong> creates an role that never expires."));
+ role_grid->addWidget(frame, role_grid->count()+1, 0, 1, 5);
+ frame->setParent(this);
+
+ connect(validity_chk, SIGNAL(toggled(bool)), validity_dte, SLOT(setEnabled(bool)));
connect(parent_form->apply_ok_btn,SIGNAL(clicked(bool)), this, SLOT(applyConfiguration(void)));
connect(members_twg, SIGNAL(currentChanged(int)), this, SLOT(configureRoleSelection(void)));
@@ -65,7 +74,8 @@ RoleWidget::RoleWidget(QWidget *parent): BaseObjectWidget(parent, OBJ_ROLE)
members_twg->widget(i)->setLayout(grid);
}
- parent_form->setMinimumSize(500, 530);
+
+ parent_form->setMinimumSize(550, 600);
}
void RoleWidget::configureRoleSelection(void)
@@ -124,7 +134,10 @@ void RoleWidget::setAttributes(DatabaseModel *model, OperationList *op_list, Rol
sysid_sb->setValue(role->getSysid());
conn_limit_sb->setValue(role->getConnectionLimit());
passwd_edt->setText(role->getPassword());
+
+ validity_chk->setChecked(!role->getValidity().isEmpty());
validity_dte->setDateTime(QDateTime::fromString(role->getValidity(),"yyyy-MM-dd hh:mm"));
+
superusr_chk->setChecked(role->getOption(Role::OP_SUPERUSER));
create_db_chk->setChecked(role->getOption(Role::OP_CREATEDB));
create_user_chk->setChecked(role->getOption(Role::OP_CREATEROLE));
@@ -261,7 +274,11 @@ void RoleWidget::applyConfiguration(void)
role->setSysid(sysid_sb->value());
role->setConnectionLimit(conn_limit_sb->value());
role->setPassword(passwd_edt->text());
- role->setValidity(validity_dte->dateTime().toString("yyyy-MM-dd hh:mm"));
+
+ if(validity_chk->isChecked())
+ role->setValidity(validity_dte->dateTime().toString("yyyy-MM-dd hh:mm"));
+ else
+ role->setValidity("");
role->setOption(Role::OP_SUPERUSER, superusr_chk->isChecked());
role->setOption(Role::OP_CREATEDB, create_db_chk->isChecked());
Oops, something went wrong.

0 comments on commit e8cb41a

Please sign in to comment.