<?xml version="1.0" encoding="UTF-8" ?>
<!--
  ~ Copyright (c) DbVis Software AB. All Rights Reserved.
  -->

<!DOCTYPE DatabaseProfile SYSTEM "dbvis-defs.dtd">

<DatabaseProfile
        desc="Profile for MariaDB"
        minver="9.5"
        extends="mysql-base">

   <!--
      Regarding the MariaDB compatibility with MYSQL version this profile is much
      based on the fact that MariaDB version numbers follow the MySQL's numbering
      scheme up to version 5.5. Thus, MariaDB 5.5 offers all of the MySQL 5.5 features.
      There exists a gap in MySQL versions between 5.1 and 5.5, while MariaDB
      issued 5.2 and 5.3 point releases (https://en.wikipedia.org/wiki/MariaDB).
      This means that the conditions used in the original profile involving versions
      older than 5.1 still remains in the base profile as these are valid for
      both versions.
   -->

   <!-- =================================================================== -->
   <!-- Definition of initialization commands -->
   <!-- =================================================================== -->

   <InitCommands extends="true">
      <!-- In MariaDB 10.3 and later, the SQL mode Oracle configures the server to understand a large subset of Oracle's PL/SQL language instead of MariaDB's 
         traditional syntax for stored routines -->
      <If test="#util.isDatabaseVersionGTE(10,3)">
         <Command id="mysqlbase.getOracleSqlMode">
            <SQL>
               <![CDATA[SELECT @@SESSION.sql_mode LIKE '%ORACLE%']]>
            </SQL>
            <Output index="1" name="IS_ORACLE_SQLMODE"/>
         </Command>
      </If>
   </InitCommands>

   <!-- =================================================================== -->
   <!-- Definition of the commands -->
   <!-- =================================================================== -->

   <Commands extends="true">
      <Command id="mysqlbase.getUsers">
         <SQL>
            <!-- UTF8 support https://mariadb.com/kb/en/library/unicode/ -->
            <If test="#util.isDatabaseVersionGTE(5,5)">
               <![CDATA[
select CONCAT('''', User, '''', _utf8'@', '''', Host, '''') as UserName, mysql.user.*
from mysql.user where user != '' order by UserName
                ]]>
            </If>
            <Else>
               <![CDATA[
select CONCAT('''', User, '''@''', Host, '''') as UserName, mysql.user.*
from mysql.user where user != '' order by UserName
               ]]>
            </Else>
         </SQL>
      </Command>

      <Command id="mariadb.getSequence">
         <SQL>
            SELECT * FROM ${catalog}.${sequence};
         </SQL>
      </Command>
   </Commands>

   <!-- =================================================================== -->
   <!-- Definition of the object actions that are used by the tree and views -->
   <!-- =================================================================== -->

   <ObjectsActionDef extends="true">
      <ActionGroup type="Procedures">
         <!-- CREATE PROCEDURE Has different syntax when in Oracle mode -->
         <Action id="mysqlbase-procedures-create" label="Create Procedure" reload="true" icon="add"
                 doclink="/doclink/create-procedure" drop-on-condition="#IS_ORACLE_SQLMODE eq 1"/>

         <If test="#IS_ORACLE_SQLMODE eq 1">
            <Action id="mariadb-procedures-create" label="Create Procedure" reload="true" icon="add"
                    doclink="/doclink/create-procedure">
               <Message type="info">
                  SQL Mode 'Oracle' is enabled. Procedure
                  syntax need to comply with required syntax
               </Message>
               <Input label="Procedure Name" name="procedureName" style="text"/>
               <Input label="Parameters" style="separator"/>

               <Input name="parameters" style="grid">
                  <Arg name="output" value=" ${name} ${direction} ${type}"/>
                  <Arg name="newline" value=", "/>

                  <Input name="name" label="Name" style="text">
                     <Default>parm</Default>
                  </Input>
                  <Input name="direction" label="Direction" style="list">
                     <Values>IN|INOUT|OUT</Values>
                     <Default>IN</Default>
                  </Input>
                  <Input name="type" label="Type" style="text">
                     <Default>VARCHAR2</Default>
                  </Input>
               </Input>
               <Input label="SQL Mode" style="separator"/>
               <Input name="sqlmode" style="wrapped-text-editor">
                  <Default>
                     <Command>
                        <SQL>
                           <![CDATA[SELECT @@SESSION.sql_mode]]>
                        </SQL>
                     </Command>
                  </Default>
               </Input>
               <!--
                  The following variables are used to alter and reset the SQL mode
                  if the user creates the object in a SQL other than the session
                  SQL mode.
                  NOTE: This block is found in several actions in the
                  mysql, mysql-base and mariadb XML files. If modifying
                  it, apply the same change in all copies of the block.
                -->
               <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
               <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
               <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
               <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
               <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

               <SetVar name="_parameters" value='#parameters.trim().equals("") ? "()" : "(" + #parameters + ")"'/>
               <!-- <Input label="Source" style="separator"/> <Input name="source" style="text-editor"> <Default> <![CDATA[ BEGIN DECLARE v CHAR(10) DEFAULT
                  'Hello'; SELECT CONCAT(v, ', ', current_user, '!'); END; ]]> </Default> </Input> -->
               <Command exectype="script">
                  <SQL>
                     <![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
@delimiter %%%;
CREATE PROCEDURE ${QB}${procedureName}${QE}
${_parameters}
AS
BEGIN
  select '${procedureName} called';
END;
%%%
@delimiter ;%%%
${_resetSqlmodeCommand}
                  ]]>
                  </SQL>
               </Command>
               <Confirm>
                  Create procedure ${procedureName}?
               </Confirm>
               <Result>
                  Procedure ${procedureName} created!
               </Result>
            </Action>
         </If>

      </ActionGroup>

      <ActionGroup type="Functions">
         <!-- CREATE PROCEDURE Has different syntax when in Oracle mode -->

         <Action id="mysqlbase-functions-create" label="Create Function" reload="true" icon="add"
                 doclink="/doclink/create-function" drop-on-condition="#IS_ORACLE_SQLMODE eq 1"/>

         <If test="#IS_ORACLE_SQLMODE eq 1">
            <Action id="mariadb-functions-create" label="Create Function" reload="true" icon="add"
                    doclink="/doclink/create-function">
               <Message type="info">
                  SQL Mode 'Oracle' is enabled. Function
                  syntax need to comply with required syntax
               </Message>

               <Input label="Function Name" name="functionName" style="text"/>
               <Input label="Return Data Type" name="returns" style="text">
                  <Default>VARCHAR(20)</Default>
               </Input>

               <Input label="Deterministic" name="deterministic" style="radio">
                  <Values>NOT DETERMINISTIC|DETERMINISTIC</Values>
                  <Default>NOT DETERMINISTIC</Default>
               </Input>

               <Input label="Parameters" style="separator"/>

               <Input name="parameters" style="grid">
                  <Arg name="output" value="${name} ${type}"/>
                  <Arg name="newline" value=", "/>

                  <Input name="name" label="Name" style="text">
                     <Default>parm</Default>
                  </Input>
                  <Input name="type" label="Type" style="text">
                     <Default>VARCHAR(20)</Default>
                  </Input>
               </Input>
               <Input label="SQL Mode" style="separator"/>
               <Input name="sqlmode" style="wrapped-text-editor">
                  <Default>
                     <Command>
                        <SQL>
                           <![CDATA[SELECT @@SESSION.sql_mode]]>
                        </SQL>
                     </Command>
                  </Default>
               </Input><!--
                  The following variables are used to alter and reset the SQL mode
                  if the user creates the object in a SQL other than the session
                  SQL mode.
                  NOTE: This block is found in several actions in the
                  mysql, mysql-base and mariadb XML files. If modifying
                  it, apply the same change in all copies of the block.
                -->
               <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
               <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
               <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
               <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
               <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

               <SetVar name="_parameters" value='#parameters.trim().equals("") ? "()" : "(" + #parameters + ")"'/>
               <!-- <Input label="Source" style="separator"/> <Input name="source" style="text-editor"> <Default> <![CDATA[ RETURN CONCAT('Hello, ', current_user,
                  '!'); ]]> </Default> </Input> -->
               <Command exectype="script">
                  <SQL>
                     <![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
@delimiter %%%;
CREATE FUNCTION ${QB}${functionName}${QE}
${_parameters}
RETURN ${returns}
${deterministic}
  IS
    BEGIN
      RETURN 'Hello world';
    END;
%%%
@delimiter ;%%%
${_resetSqlmodeCommand}
                  ]]>
                  </SQL>
               </Command>
               <Confirm>
                  Create function ${functionName}?
               </Confirm>
               <Result>
                  Function ${functionName} created!
               </Result>
            </Action>
         </If>
      </ActionGroup>

      <ActionGroup type="Sequences">
         <Action id="mariadb-sequences-create" label="Create Sequence" reload="true" icon="add">

            <Input label="Sequence Name" name="sequenceName" style="text"/>
            <Input label="Start With" name="startWith" style="text">
               <Default>1</Default>
            </Input>
            <Input label="Increment By" name="increment" style="text">
               <Default>1</Default>
            </Input>
            <Input label="Cached Values" name="cache" style="text">
               <Default>1000</Default>
            </Input>

            <Command>
               <SQL>
                  <![CDATA[create sequence `${catalog}`.${QB}${sequenceName}${QE} start with ${startWith} increment by ${increment} nomaxvalue nominvalue cache ${cache}]]></SQL>
            </Command>
            <Result>
               Sequence ${catalog}.${sequenceName} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Sequence">
         <Action id="mariadb-sequence-drop" label="Drop Sequence" reload="true" icon="remove">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Sequence" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Command>
               <SQL><![CDATA[drop sequence `${catalog}`.`${objectname}`]]></SQL>
            </Command>
            <Confirm>
               Really drop sequence ${catalog}.${objectname}?
            </Confirm>
            <Result>
               Sequence ${catalog}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="mariadb-sequence-rename" label="Rename Sequence" reload="true" icon="rename">
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Sequence" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>
            <Input label="New Sequence Name" name="newSequence" style="text"/>
            <Command>
               <SQL>
                  <![CDATA[ALTER TABLE `${catalog}`.`${objectname}` rename to `${catalog}`.${QB}${newSequence}${QE}]]></SQL>
            </Command>
            <Confirm>
               Confirm rename of sequence ${objectname} to ${newSequence}?
            </Confirm>
            <Result>
               Sequence ${objectname} renamed to ${newSequence}!
            </Result>
         </Action>

         <Separator/>

         <Action id="mariadb-sequence-script" label="Script Sequence" icon="scriptObject" class="sqlBuilder"
                 classargs="script-dialog,CREATE,DROP"/>
      </ActionGroup>

      <ActionGroup type="Packages">
         <Action id="mariadb-packages-create" label="Create Package" reload="true" icon="add"
                 doclink="/doclink/create-code-object">

            <Input label="Package Name" name="packageName" style="text"/>
            <Input label="SQL Mode" style="separator"/>
            <Input name="sqlmode" style="wrapped-text-editor">
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT @@SESSION.sql_mode]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <Input label="Source" style="separator"/>
            <Input name="source" style="text-editor"/>

            <!--
               The following variables are used to alter and reset the SQL mode
               if the user creates the object in a SQL other than the session
               SQL mode.
               NOTE: This block is found in several actions in the
               mysql, mysql-base and mariadb XML files. If modifying
               it, apply the same change in all copies of the block.
             -->
            <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
            <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
            <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
            <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
            <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

            <Command exectype="script">
               <SQL><![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
@delimiter %%%;
CREATE PACKAGE ${QB}${packageName}${QE}
AS
  ${source}
END;
%%%
@delimiter ;%%%
${_resetSqlmodeCommand}
               ]]>
               </SQL>
            </Command>
            <Confirm>
               Create package ${packageName}?
            </Confirm>
            <Result>
               Package ${packageName} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="Package">
         <Action id="mariadb-package-create" label="Create Package Body" reload="true" icon="add"
                 doclink="/doclink/create-code-object">

            <Input label="Package Body Name" name="packageName" style="text">
               <Default>${objectname}</Default>
            </Input>
            <Input label="SQL Mode" style="separator"/>
            <Input name="sqlmode" style="wrapped-text-editor">
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT @@SESSION.sql_mode]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <Input label="Source" style="separator"/>
            <Input name="source" style="text-editor"/>

            <!--
               The following variables are used to alter and reset the SQL mode
               if the user creates the object in a SQL other than the session
               SQL mode.
               NOTE: This block is found in several actions in the
               mysql, mysql-base and mariadb XML files. If modifying
               it, apply the same change in all copies of the block.
             -->
            <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
            <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
            <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
            <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
            <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

            <Command exectype="script">
               <SQL><![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
@delimiter %%%;
CREATE PACKAGE BODY ${QB}${packageName}${QE}
AS
  ${source}
END;
%%%
@delimiter ;%%%
${_resetSqlmodeCommand}
               ]]>
               </SQL>
            </Command>
            <Confirm>
               Create package ${packageName}?
            </Confirm>
            <Result>
               Package ${packageName} created!
            </Result>
         </Action>

         <Action id="mariadb-package-drop" label="Drop Package and Package Body" reload="true" icon="remove">
            <Message>SQL Mode may be altered and restored when executing this
               action
            </Message>
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Package" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>

            <!--
               The following variables are used to alter and reset the SQL mode
               if the user creates the object in a SQL other than the session
               SQL mode.
               NOTE: This block is found in several actions in the
               mysql, mysql-base and mariadb XML files. If modifying
               it, apply the same change in all copies of the block.
             -->
            <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
            <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
            <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
            <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
            <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

            <Command exectype="script">
               <SQL><![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
drop package `${catalog}`.`${objectname}`;
${_resetSqlmodeCommand}
               ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop package and body ${catalog}.${objectname}?
            </Confirm>
            <Result>
               Package and body ${catalog}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="mariadb-package-export" label="Export Package" icon="export"
                 class="packageExport"
                 doclink="/doclink/export-code-object"/>
      </ActionGroup>

      <ActionGroup type="PackageBodies">
         <Action id="mariadb-packagebodies-create" label="Create Package Body" reload="true" icon="add"
                 doclink="/doclink/create-code-object">

            <Input label="Package Body Name" name="packageName" style="text"/>
            <Input label="SQL Mode" style="separator"/>
            <Input name="sqlmode" style="wrapped-text-editor">
               <Default>
                  <Command>
                     <SQL>
                        <![CDATA[SELECT @@SESSION.sql_mode]]>
                     </SQL>
                  </Command>
               </Default>
            </Input>
            <Input label="Source" style="separator"/>
            <Input name="source" style="text-editor"/>

            <!--
               The following variables are used to alter and reset the SQL mode
               if the user creates the object in a SQL other than the session
               SQL mode.
               NOTE: This block is found in several actions in the
               mysql, mysql-base and mariadb XML files. If modifying
               it, apply the same change in all copies of the block.
             -->
            <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
            <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
            <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
            <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
            <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

            <Command exectype="script">
               <SQL><![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
@delimiter %%%;
CREATE PACKAGE BODY ${QB}${packageName}${QE}
AS
  ${source}
END;
%%%
@delimiter ;%%%
${_resetSqlmodeCommand}
               ]]>
               </SQL>
            </Command>
            <Confirm>
               Create package ${packageName}?
            </Confirm>
            <Result>
               Package ${packageName} created!
            </Result>
         </Action>
      </ActionGroup>

      <ActionGroup type="PackageBody">
         <Action id="mariadb-packagebody-drop" label="Drop Package Body" reload="true" icon="remove">
            <Message>SQL Mode may be altered and restored when executing this
               action
            </Message>
            <Input label="Database" style="text" editable="false">
               <Default>${catalog}</Default>
            </Input>
            <Input label="Package Body" style="text" editable="false">
               <Default>${objectname}</Default>
            </Input>

            <!--
               The following variables are used to alter and reset the SQL mode
               if the user creates the object in a SQL other than the session
               SQL mode.
               NOTE: This block is found in several actions in the
               mysql, mysql-base and mariadb XML files. If modifying
               it, apply the same change in all copies of the block.
             -->
            <SetVar name="_sqlmodeSame" value='#sqlmode.trim().equals(#SESSIONSQLMODE.trim())'/>
            <SetVar name="_stopOnErrorCommand" value="#_sqlmodeSame == false ? '@stop on error;\n' : ''"/>
            <SetVar name="_continueOnErrorCommand" value="#_sqlmodeSame == false ? '@continue on error;\n' : ''"/>
            <SetVar name="_sqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #sqlmode + '\'\n;' : ''"/>
            <SetVar name="_resetSqlmodeCommand" value="#_sqlmodeSame == false ? 'SET SESSION sql_mode = \'' + #SESSIONSQLMODE + '\'\n;' : ''"/>

            <Command exectype="script">
               <SQL><![CDATA[
${_stopOnErrorCommand}${_sqlmodeCommand}${_continueOnErrorCommand}
drop package body `${catalog}`.`${objectname}`;
${_resetSqlmodeCommand}
               ]]>
               </SQL>
            </Command>
            <Confirm>
               Really drop package and body ${catalog}.${objectname}?
            </Confirm>
            <Result>
               Package and body ${catalog}.${objectname} dropped!
            </Result>
         </Action>

         <Action id="mariadb-packagebody-export" label="Export Package Body" icon="export"
                 class="packageExport"
                 doclink="/doclink/export-code-object"/>
      </ActionGroup>

   </ObjectsActionDef>

   <!-- =================================================================== -->
   <!-- Definition of the database objects tree structure -->
   <!-- =================================================================== -->

   <ObjectsTreeDef extends="true">
      <GroupNode type="Databases" label="Databases">
         <DataNode type="Catalog" label="${getCatalogs.TABLE_CAT}">
            <GroupNode type="Sequences" label="Sequences" drop-on-condition="#util.isDatabaseVersionLT(10,3)">
               <DataNode type="Sequence" label="${mysqlbase.getTableNames.TABLE_NAME}" isLeaf="true">
                  <SetVar name="objectname" value="${mysqlbase.getTableNames.TABLE_NAME}"/>
                  <Command idref="mysqlbase.getTableNames">
                     <Input name="catalog" value="${catalog}"/>
                     <Input name="type" value="IN ('SEQUENCE')"/>
                     <Filter index="TABLE_NAME" label="Name"/>
                  </Command>
               </DataNode>
            </GroupNode>

            <GroupNode type="Packages" label="Packages">
               <DataNode type="Package" label="${mysqlbase.getProcedures.ROUTINE_NAME}" isLeaf="false">
                  <SetVar name="objectname" value="${mysqlbase.getProcedures.ROUTINE_NAME}"/>
                  <SetVar name="packagename" value="${mysqlbase.getProcedures.ROUTINE_NAME}"/>
                  <SetVar name="packagesqlmode" value="${mysqlbase.getProcedures.SQL_MODE}"/>
                  <Command idref="mysqlbase.getProcedures">
                     <Input name="catalog" value="${catalog}"/>
                     <Input name="name" value="%"/>
                     <Input name="type" value="PACKAGE"/>
                  </Command>

                  <DataNode type="PackageBody" label="${mysqlbase.getProcedures.ROUTINE_NAME}" isLeaf="true">
                     <SetVar name="objectname" value="${mysqlbase.getProcedures.ROUTINE_NAME}"/>
                     <Command idref="mysqlbase.getProcedures">
                        <Input name="catalog" value="${catalog}"/>
                        <Input name="name" value="${packagename}"/>
                        <Input name="type" value="PACKAGE BODY"/>
                     </Command>
                  </DataNode>
               </DataNode>
            </GroupNode>

            <GroupNode type="PackageBodies" label="Package Bodies">
               <DataNode type="PackageBody" label="${mysqlbase.getProcedures.ROUTINE_NAME}" isLeaf="true">
                  <SetVar name="objectname" value="${mysqlbase.getProcedures.ROUTINE_NAME}"/>
                  <SetVar name="packagebodyname" value="${mysqlbase.getProcedures.ROUTINE_NAME}"/>
                  <SetVar name="packagesqlmode" value="${mysqlbase.getProcedures.SQL_MODE}"/>
                  <Command idref="mysqlbase.getProcedures">
                     <Input name="catalog" value="${catalog}"/>
                     <Input name="name" value="%"/>
                     <Input name="type" value="PACKAGE BODY"/>
                  </Command>
               </DataNode>
            </GroupNode>

            <GroupNode label="Events" type="Events" drop-on-condition="#util.isDatabaseVersionLT(10,4)"/>

         </DataNode>
      </GroupNode>
   </ObjectsTreeDef>

   <!-- =================================================================== -->
   <!-- Definition of the database objects views -->
   <!-- =================================================================== -->

   <ObjectsViewDef extends="true">
      <ObjectView type="Sequences">
         <DataView id="mariadb-sequences-sequences" icon="Sequences" label="Sequences" viewer="grid">
            <Input name="menuItem" value="Open in New Tab...">
               <Input name="action" value="open-object-in-new-tab-command ${catalog||TABLE_SCHEMA}${object||SEQUENCE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Open in Floating Tab...">
               <Input name="action" value="open-object-in-floating-tab-command ${catalog||TABLE_SCHEMA}${object||SEQUENCE_NAME}"/>
            </Input>
            <Input name="menuItem" value="Script: DROP SEQUENCE">
               <Input name="command" value="drop sequence ${catalog||TABLE_SCHEMA}${object||SEQUENCE_NAME}"/>
            </Input>

            <Command idref="mysqlbase.getTables">
               <Input name="catalog" value="${catalog}"/>
               <Input name="type" value="IN ('SEQUENCE')"/>
               <ProcessDataSet action="renamecolumn" index="1" value="SEQUENCE_NAME"/>
            </Command>
         </DataView>
      </ObjectView>

      <ObjectView type="Sequence">
         <DataView id="mysqlbase-sequence-info" icon="Info" label="Info" viewer="form" order-before="0">
            <Command idref="mariadb.getSequence">
               <Input name="catalog" value="${catalog}"/>
               <Input name="sequence" value="${objectname}"/>
               <ProcessDataSet action="addcolumn" index="Name" value="${objectname}"/>
               <ProcessDataSet action="movecolumn" index="Name" value="first"/>
            </Command>
         </DataView>

         <DataView id="mariadb-sequence-ddl" icon="Source" label="DDL" viewer="ddl">
            <Input name="objectType" value="Sequence"/>
            <Input name="formatSQL" value="true"/>
         </DataView>

      </ObjectView>

      <ObjectView type="Packages">
         <DataView id="mariadb-packages-packages" icon="Packages" label="Packages" viewer="grid">
            <Command idref="mysqlbase.getProcedures">
               <Input name="catalog" value="${catalog}"/>
               <Input name="name" value="%"/>
               <Input name="type" value="PACKAGE"/>
            </Command>
            <Input name="menuItem" value="Script: DROP PACKAGE">
               <Input name="command" value="drop package ${object||catalog}.${object||ROUTINE_NAME}"/>
            </Input>
         </DataView>
      </ObjectView>

      <ObjectView type="Package">
         <DataView classargs="PACKAGE" id="mariadb-package-packagespecificationeditor" icon="SourceEditor"
                   label="Package Specification Editor" viewer="procedure-editor"
                   doclink="/doclink/edit-code-object"/>
      </ObjectView>

      <ObjectView type="PackageBodies">
         <DataView id="mariadb-packagebodies-packagebodies" icon="PackageBodies" label="Package Bodies" viewer="grid">
            <Command idref="mysqlbase.getProcedures">
               <Input name="catalog" value="${catalog}"/>
               <Input name="name" value="%"/>
               <Input name="type" value="PACKAGE BODY"/>
            </Command>
            <Input name="menuItem" value="Script: DROP PACKAGE BODY">
               <Input name="command" value="drop package body ${object||catalog}.${object||ROUTINE_NAME}"/>
            </Input>
         </DataView>
      </ObjectView>

      <ObjectView type="PackageBody">
         <DataView classargs="PACKAGE BODY" id="mariadb-packagebody-packagebodyeditor" icon="SourceEditor" label="Package Body Editor"
                   viewer="procedure-editor"
                   doclink="/doclink/edit-code-object"/>
      </ObjectView>
   </ObjectsViewDef>

</DatabaseProfile>
