Welcome to the Toad Data Modeling Community

 

Archive for the ‘Customize’ Category

Macros - User Forms

Friday, December 4th, 2009

Hello,
Today I’m bringing some basic information on user forms that you can use in BETA.
The documentation is not complete. We keep working on it for next commercial release. Thanks.

FORM
To create a form, use the object System that is registered in every script.
The method you need is called CreateForm and has four optional parameters:
Example:
var form = System.CreateForm(‘FormName’, ‘Form Caption’, 200, 150);

1. First Parameter – Name of form (it mustn’t contain spaces and other invalid/not permitted characters).
2. Second Parameter – Caption that will be displayed in the heading of the form.
3. Third Parameter – Width of the form.
4. Fourth Parameter – Height of the form.

Functions of Form

AddControl(ControlName: widestring, ControlType: Integer): IDispatch;
- ControlName – Name under which the control is accessible.
- ControlType – Number of control type that should be created.

See the following:
- 1 - Edit Box
- 2 - Check Box
- 3 - Memo
- 4 - Panel
- 5 - Label
- 6 - Group Box
- 7 - Radio Button
- 8 - Combo Box
- 9 - List Box
- 10 - Button

This function adds control on the form.

ShowModal()
This function displays the form.

Procedures of Form

AddUserVariable(AName: widestring, DefaultValue)
- AName – Name under which a variable is accessible in events of forms.
- DefaultValue – Default value. It can be of types integer, widestring or boolean.

This procedure adds a variable on the form. The variable is then accessible in events via calling the Instance.VariableName. The variable is accessible across events. If you change a content of the variable in one event, the changed status will be accessible in another event.

RegisterObject(AName: widestring, AObject: IDispatch)
- AName – Name of object via which it will be accessible in events.
- Aobject – Object that is registered.

Use this procedure to register objects in events.

Properties of Form

Caption – Heading of the form.
CloseAfterExecute – True – When you click Execute, the code will be executed and the form closed. False – The form will not close after execution. False is set up by default.
ExecuteMethodName – Name of method that should be executed when you press the Execute button.
ExecuteScriptName – Name of script for calling out the method when you click the Execute button.

Note: If you don’t want to use the button Execute, do not set up the properties ExecuteMethodName and ExecuteScriptName. The button will not be visible on the form then.

EVENTS
To assign events, assign the component of particular event to properties of names NameEventScriptName, NameEventMethodName with reference to particular service method.

Example:
Button.OnClickScriptName = ‘MyScript’;
Button.OnClickMethodName = ‘DoOnClick’;

CONTROL
Control is an ancestor from which all controls, including the form, inherit.

Properties of Control
Align – Alignment of control. Possible values to use:
0 No alignment
1 Alignment - Top
2 Alignment - Bottom
3 Alignment - Left
4 Alignment - Right
5 Alignment – Justify

AnchorTop, AnchorBottom, AnchorLeft, AnchorRight – Determines the position of control. Default place – top left-hand corner.
Parent – Control on which a control is placed. Default position of all controls is on the form and this property is not set up.

Note: Description of value Align 0..5:
alNone - The control remains where it was placed. This is the default value.
alTop - The control moves to the top of its parent and resizes to fill the width of its parent. The height of the control is not affected.
alBottom - The control moves to the bottom of its parent and resizes to fill the width of its parent. The height of the control is not affected.
alLeft - The control moves to the left side of its parent and resizes to fill the height of its parent. The width of the control is not affected.
alRight - The control moves to the right side of its parent and resizes to fill the height of its parent. The width of the control is not affected.
alClient - The control resizes to fill the client area of its parent. If another control already occupies part of the client area, the control resizes to fit within the remaining client area.

BUTTON
Event
OnClick – Occurs when you click the button.

CHECKBOX
Event
OnClick – Occurs when the check in checkbox is changed.

COMBO-BOX
Event
OnSelect - Occurs when combo box is selected.

EDIT
Event
OnChangeText – Occurs when text in edit box is changed.

MEMO
Event
OnChangeText – Occurs when text in memo is changed.

RADIO BUTTON
Event
OnClick – Occurs when the button is selected.

More details will be available in Reference Guide. This document will be updated for next commercial release of Toad Data Modeler. For now, please do not hesitate to write us your questions via Modeling community forum. We are looking forward to hearing from you!

Have a nice day.

Regards,

Vladka + TDM Team

Macros and User Forms - Use Case

Thursday, December 3rd, 2009

Hello,
Today I will show you on a simple example how to create your own macro and define a user form.

Use Case:
You want to create a macro that will add a particular prefix to all attributes in your model.
Solution: You will create a macro ‘Add Prefix’. The macro will be available via right-click menu on the Workspace. You want to create a user form where you will define the prefix and decide if you want to apply the change in Caption of attributes too.

1. Open Script Explorer.
2. Right-click the Macros item and select Add New Macro.
3. Right-click the new item and select Properties.
4. On tab General, define properties of the macro.

Important! – Name of macro mustn’t contain spaces and other forbidden characters. The name must start with a character (not number). Then you can use characters, numbers or possibly ‘_’.
The rules don’t refer to caption. Caption can be any title you want.

5. On tab Visibility, select where you want to apply the macro – Physical Model.
6. On tab Menu, define whether you want to display the macro in:
- Macro menu,
- pop-up menu,
- both places.
Parameter Path specifies position in main menu or pop-up menu. Feel free to define e.g. “Test\My Items”.

In this example, you decide to display it only in pop-up menu.
Path box is empty as ‘Macros‘ item is set as default.

7. On tab Object Types, select in which object pop-up menu you want to display it. Select Workspace.

8. Confirm OK.
9. Double-click the macro to open Script Editor. Modify the default code.

10. Click Commit and Save.

Result: Right-click the Workspace | Macros | Add Prefix to open the user form.

Next time I will provide you with some details on user forms - functions, procedures, events etc.

Regards,
Vladka + TDM Team

Macros and User Forms - Introduction

Wednesday, December 2nd, 2009

Hello TDM users,

As you already know, new BETA version 3.5.3.1 has been released today. This BETA brings a lot of new features and enhancements, including enhancements relating to macros - visual components for macros (user forms).
Let me give you a brief insight into this great enhancement. In the following text, I will compare the possibility of using macros in older TDM BETA version with what you can achieve now using the visual components.

Toad Data Modeler supports macros. You can create a macro in Package Explorer or Script Explorer and modify its properties to display the macro either in main menu or pop-up menu (of particular object or on the Workspace etc.).
Previous TDM versions allowed you to define such macros via a script written in Script Editor. To execute the script directly, you simply selected the macro in the particular menu.

This method is shown in the following movie:
http://modeling.inside.quest.com/entry.jspa?externalID=3283&categoryID=273

Current BETA version is bringing visual components for macros (User Forms). So, now when you select a macro in particular menu, a user form can display.

Examples of User Forms:
Right-click the Workspace displays the Macros item. Two user macros are available there:

Mark Procedures as Generate macro opens the following user form:

Select the procedures for which you want to clear the Generate box. Click Close to execute the macro.

Add Prefix macro opens the following user form:

Define a prefix for attributes. Click Execute to execute the macro.

So, as you can see, you can execute the macro directly when you click it OR you can display user forms where you can further modify the settings for execution. You can create such user forms on your own.

User Forms - Introductory Information:
- You can create and use user forms to interact with Toad Data Modeler during script and macro execution. You can enter input parameters or see some output information.
- Function Main only creates and displays the user form. Other functionalities must be implemented/added via form events or its controls. So, a form is not a dialog.

Next time I will give you an example on how to create a macro and user form.

Have a nice day.

Take care,

Vladka

User Packages in Library And Much More

Wednesday, September 30th, 2009

Hello all,

I wonder if you know what great additional sources our Library on the Modeling community offers to you.

Product Videos - Here you can watch either movies showing new features and enhancements [New] or tutorial movies showing how to work with Toad Data Modeler [Getting Started].  Special movies for experts are also available - see the Expert Mode section.
http://modeling.inside.quest.com/kbcategory.jspa?categoryID=116

Best Practices section contains a lot of helpful tips and tricks and some tutorials to new features.
http://modeling.inside.quest.com/kbcategory.jspa?categoryID=159

Documentation with Release Notes, User Guide, Trial Version Information and other important documents to Toad Data Modeler.
http://modeling.inside.quest.com/kbcategory.jspa?categoryID=29

Utilities section with sample models, user scripts, user packages, XSL user templates!

I’m happy to inform you that two nice user packages have been added there:
http://modeling.inside.quest.com/kbcategory.jspa?categoryID=34

Here’s the description:
1. Reverse All Related Tables
This package works for Oracle db and allows you to load also tables that relate to the selected tables (e.g. tables of a different schema that are related to the selected tables will be loaded during RE). Moreover, you can also define the level (depth) for loading the tables.

2. Extra Objects - DDL Script Generation
These are packages for all supported databases (except for MS Access). The packages create a new object ExtraObject (see the new item in Model Explorer) where you can write any text you want. It will be generated in DDL/SQL script then. Moreover, you can define where in the script you want to generate it - via the Order of Generated Objects feature (Model menu).

The packages are valid for Toad Data Modeler 3.4.15 and BETA 3.5.1. Please do not use the packages in older TDM versions.

I encourage you to visit the Library section and get the information you need, use the additional sources (user scripts and packages) that can facilitate your work significantly.
If you have any requirements, please do not hesitate to write us via the Modeling community forum. The possibility to make user packages and customize TDM to perfectly meet your needs is one of the greatest TDM features. Do not hesitate to take advantage of it. Our team is ready to help!

Enjoy the new packages!

Regards,

Vladka + TDM Team

Customization: how to add new Table Type option to MySQL models

Monday, September 21st, 2009

Hi,

today you will find out how to add new Table Type (Engine) option to MySQL models in Toad Data Modeler. By default, the following Table Types are available:

  • Default
  • MEMORY
  • MyISAM
  • MERGE
  • BDB
  • InnoDB
  • NDBCluster
  • ARCHIVE
  • CSV
  • FEDERATED

What if we want to use Partner-Developed storage engines, e.g. BrightHouse? Is it possible to customize Toad Data Modeler and use this engine? Of course ;-) To add the BrightHouse option to MySQL 5.1 model, do the following:

1. Turn on the Expert mode. Click Settings | Options and in section General, check the Expert Mode checkbox.
2. Open a model for MySQL 5.1. Add a new entity to the model and edit the entity. Then right click the Entity Properties form and select the Customize Form item.

3. The form will re-load in a customizable mode. Click the Table Type combo box.

4. Double click the (IDispatch) item in Component Inspector to open list of values and add there the BRIGHTHOUSE option.

5. Close the Edit mode by clicking the red cross icon on top right corner of the largest form (standard icon for closing a dialog).

6. Save the changes. Right click the form immediately after closing the Edit mode and select Save Form option.

7. Now you can edit any entity and choose the BRIGHTHOUSE option from the Table Type combo box.

8. See SQL preview:

That’s all.

Have a great day,

Vaclav

XSLT Reports - Part 2

Tuesday, February 17th, 2009

Hi,

In part two of the XSLT Reports series, I will explain you how to define items that will be displayed in GUI. You will learn how to define default Description, file name, suffix and also how to define parameters and other settings.

See below a new XSL template created for one of our community members.

And this way your definitions will be displayed in Toad Data Modeler.

Let’s continue with the XSLT structure.
In the stylesheet element, you can see definition of standard XSLT namespace plus two additional namespace definitions. The first additional namespace is xmlns:tdm="http://www.quest.com/toad-data-modeler", used for TDM related items, the second additional namespace is xmlns:msxsl="urn:schemas-microsoft-com:xslt", used only when JavaScript function needs to be executed during XSL Transformation.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tdm="http://www.quest.com/toad-data-modeler"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">

The Stylesheet element is followed by several TDM related elements.

<tdm:description>Output contains Relationship name, parent entity and child entity names and parent and child attribute names. You can change ListSeparator as well as AttributeSeparator parameters. ListSeparator separates CSV values, AttributeSeparator separates attribute names (relationship created using PK of multiple columns.) </tdm:description>
<tdm:caption>Relationships (CSV)</tdm:caption>
<tdm:default-filename>relationships</tdm:default-filename>
<tdm:default-suffix>csv</tdm:default-suffix>
<tdm:db-platforms>
<tdm:db-platform>all</tdm:db-platform>
</tdm:db-platforms>
  • tdm:description - use this element to describe your XSLT. The content will appear in GUI, see the screenshot above.
  • tdm:caption - allows you to name your XSLT. Whatever you write into this element, it will appear in combo-box.
  • tdm:default-filename - gives you the possibility to specify a default name for output.
  • tdm:default-suffix - hmmm. It is not very hard to guess what this stands for, isn’t it?
  • tdm:default-filename - gives you the possibility to specify a default name for output.
  • tdm:db-platforms - here you can see db-related restriction.
    The following definition means that the template is valid for all models created for all target databases.

    <tdm:db-platforms>
    <tdm:db-platform>all</tdm:db-platform>
    </tdm:db-platforms>
    

    This way you can define restriction and say to TDM that the XSLT should be available only for Oracle models.

    <tdm:db-platforms>
    <tdm:db-platform>OR9</tdm:db-platform>
    <tdm:db-platform>OR10</tdm:db-platform>
    <tdm:db-platform>OR11</tdm:db-platform>
    </tdm:db-platforms>
    

    What happens if you create a model for MS SQL Server and open the XSL Transformation dialog? Templates for Oracle model will not be loaded and will not appear in the combo-box.

Now see section 4 in the screenshots. Top-level parameters defined using standard XSLT instructions will appear in GUI. This way you can define parameters before you transform source to ouptut.

<xsl:param name="ListSeparator" select="," />
<xsl:param name="AttributeSeparator" select=";" />

That’s all for now. If you want to use the XSLT template, have a look at the following page:
http://modeling.inside.quest.com/entry.jspa?externalID=2575&categoryID=407

Have a nice day,

Vaclav

XSLT Reports - Part 1

Monday, February 9th, 2009

Hi,

I am going to write several articles related to generation of customized outputs from Toad Data Modeler. I hope you will find them useful and informative - and maybe you will get some inspiration for making customized templates. In the series you will find out:

  • How to generate simplified XML files
  • Where to get XSD file that describes structure of simplified XML
  • How to create new XSLT file and where to put it
  • How to define default file name and default suffix for outputs
  • How to define Name and Description of your templates
  • How to create parameters that will appear in GUI
  • and finally an example of XSLT file that generates XSD from an Oracle model

At the end of this article you will find out that there is an easy way how to e.g. reverse engineer a database system and generate XSD schema for all reversed tables.

Let’s start with basic information and explanations. The current version of Toad Data Modeler allows you to generate detailed report via standard Model | Report… feature. However, there is also another possibility how to generate reports or other outputs. Click Model | Reports / XSL Transformation…. to see the other possibility. A dialog with predefined report types will open.

We can see there that using the XSL transformations we can generate HTML, CSV or XML files. What if we want to generate XSD, SVG or for example XAML code? Is it possible? - Sure! The XSL transformation allows us to work with data stored in our models without the necessity to study internal structure, scripting etc. If you are familiar with XML, xPath and XSLT, then it will be very easy for you to iterate tables, columns and other data and generate output you need to generate.

How it works: for every XSL transformation you need a source (XML file), a template (XSLT file) and a way how to do the transformation. Output type can be specified in the XSLT file.

In Toad Data Modeler, there is GUI that allows you to locate XSLT templates. But..where is the source? Where is XML? Good questions :) - On the XSL Transformation dialog, click the More button. The dialog will become twice large than it was and you will see there buttons Save XSD files as… and Show XSD File. Click the Show XSD File button. If XSD files are associated with some third party application (e.g. Visual Studio), then the file will open in the associated application. XSD file describes structure of “simplified XML”. In other words, it describes structure of our source. OK, how to generate a real XML file for testing purposes etc.? In the XSL Transformation dialog, select the Complete XML (XML) item from the first combo-box.

Then click Transform. This way you can geneate XML file. We call it “simplified XML”, because, as you probably know, all files created in Toad Data Modeler are in XML format. Save your model as *.TXP file and edit the file in notepad. You will see XML file structure. What’s the difference between simplified XML and standard TXP file? - In the amount and form of information. For example, in simplified XML you will find data types named logically, in TXP the same information is represented by GUID code. Also, simplified XML doesn’t contain information related to workspaces, generators and other data required by Toad Data Modeler application. That’s why you can get oriented in simplified XML much faster.

In next article I will explain how to create a new XSL Template and describe structure of XSL Templates used in Toad Data Modeler. Now I’d like to show you that using one relatively simple XSL template we can generate XSD for Oracle models. Download the “XML Schema (XSD) - Elements” template from the following location:
http://modeling.inside.quest.com/servlet/KbServlet/download/2574-102-4883/xsd-elements.zip

and put it to the same folder where system XSL templates are stored. Open the XSL Transformation dialog and see value in XSL File Location.

Then open any Oracle model or reverse engineer your existing Oracle database structure, click Model | Report / XSL Transformation… item and see a new item in the first combo-box. Click More, define parameters and then click Transform to generate the output and see the result.

The output can be visualized also in Visual Studio (considering column names are unique).

Regards,

Vaclav

Script to Remove Comments after Conversion

Wednesday, February 4th, 2009

Hi,

As you probably know, Toad Data Modeler allows you to convert a model from one database system to another. You can reverse engineer a physically existing Oracle database structure and convert your model to PostgreSQL or MS SQL Server model etc. Tables, relationships, columns and data types will be converted automatically together with logical information. Other database specific items like Triggers, Stored Procedures, Views etc. can be converted too, however, if you select such object types they will be automatically commented out in your newly created model. Why? Because you can write SQL code for Views or Triggers etc. that will work in Oracle, but won’t work in MS SQL Server. And you can face similar problems after converting Oracle 9 model to Oracle 11 model.

How can we easily remove comments (I mean automatically added comments) from the newly created model? - Via scripting!

See below a script that removes comments from newly created Oracle 11g model (converted from Oracle 10g model.)

function main()
{
var app = System.GetInterface('Application');
var Model = app.Models.GetObject(0);
//... parameter in GetObject determines with which model the script should work.
//0 = first model listed in the Application View, 1 = second model listed in the Application View etc.
var i, j, k;
var Entity, Trigger, View, Procedure, Function, CheckConstraint, Attribute, Domain, Default;

Model.Lock();

//Triggers, CheckConstraints
for (i=0; i<Model.Entities.Count; i++)
{
Entity = Model.Entities.GetObject(i);
for (j=0; j<Entity.Triggers.Count; j++)
{
Trigger = Entity.Triggers.GetObject(j);
Trigger.SQL = RemoveCommentChars(Trigger.SQL);
}
for (j=0; j<Entity.CheckConstraints.Count; j++)
{
CheckConstraint = Entity.CheckConstraints.GetObject(j);
CheckConstraint.SQL = RemoveCommentChars(CheckConstraint.SQL);
}
for (j=0; j<Entity.Attributes.Count; j++)
{
Attribute = Entity.Attributes.GetObject(j);
for (k=0; k<Attribute.CheckConstraints.Count; k++)
{
CheckConstraint = Attribute.CheckConstraints.GetObject(k);
CheckConstraint.SQL = RemoveCommentChars(CheckConstraint.SQL);
}
}
}

//Domain CheckConstraints
for (i=0; i<Model.Domains.Count; i++)
{
Domain = Model.Domains.GetObject(i);
for (j=0; j<Domain.CheckConstraints.Count; j++)
{
CheckConstraint = Domain.CheckConstraints.GetObject(j);
CheckConstraint.SQL = RemoveCommentChars(CheckConstraint.SQL);
}
}

//Defaults
for (i=0; i<Model.Defaults.Count; i++)
{
Default = Model.Defaults.GetObject(i);
Default.Value = RemoveCommentChars(Default.Value);
}

//Views
for (i=0; i<Model.Views.Count; i++)
{
View = Model.Views.GetObject(i);
View.SQL = RemoveCommentChars(View.SQL);
}

//Procedures
for (i=0; i<Model.Procedures.Count; i++)
{
Procedure = Model.Procedures.GetObject(i);
Procedure.SQL = RemoveCommentChars(Procedure.SQL);
}

//Functions
for (i=0; i<Model.Functions.Count; i++)
{
Function = Model.Functions.GetObject(i);
Function.SQL = RemoveCommentChars(Function.SQL);
}

Model.UnLock();
}

function RemoveCommentChars( strValue )
{
return strValue.replace(/^--/g,"").replace(/\n--/g,"\n");
}

How to run the script in Toad Data Modeler? Do the following, please:

  • Enable Expert Mode - click Settings | Options and in section General, enable the Expert Mode checkbox.
  • Click Tools | Scripting Window to open a form from where the script will be executed.
  • Copy and paste the script to the main area.
  • Click the Execute button (green arrow icon).

Regards,

Vaclav & TDM team

How To Use Combo Boxes in Customized Forms

Thursday, July 31st, 2008

Hi All,

In this article, I will explain how to use DataComboBox, DataStaticDataComboBox and ComboBox components for form customization.

If you wish to follow all steps one by one, please download the ComboBoxExamples package and copy it to the same folder where the “My Package.txg” file is. Possible path: Documents and Settings\{user name}\My Documents\Toad Data Modeler\Packages\{Guid}\ .
Then enable Expert mode via Settings | Options | General item and select the Expert Mode checkbox. Finally click the Expert Mode item and clear the Save the definitions to ‘My Package’ package checkbox and restart Toad Data Modeler.

Let’s say we have a simple model with three entities, one stored procedure and one synonym.

In order to modify the form, we have to edit the existing synonym, right-click the form and select Customize Form as

As you can see, there are four new items on the form.

  • Entities (DataComboBox) - this item allows you to select entity from a list of entities and assign its value to the system ‘Object’ combo box. We can pass objects to other objects of Dispatch type.
  • DBLink (DataStaticComboBox) - this item will work as a replacement for the ‘Dblink’ field. We can pass values to other objects of String type.
  • Last combo box on the form contains items that can be used for verification. We can define combo box with defined values, don’t store the values anywhere but use values for events, in this case for verification.

Select the ComboBoxesExample package.

Modified form in Edit mode will open.

DataComboBox
Click the DataComboBox item.

In Component Inspector, see properties:

  • DataSource = Synonym
  • DataList = Entities (here we can select lists of objects)
  • DisplayPropertyName = Name (here we can select any property of Entity object)
  • DataField = Entity (property of type Dispatch)

DataComboBox should be used whenever you need to select an item from a list of existing objects and fill property of Dispatch type.

DataStaticComboBox
Click the DataStaticComboBox item.

In Component Inspector, see properties

  • DataSource = Synonym
  • DataField = Dblink (property of type String)
  • Items = defined list. Click the IDispatch item and press F2. Then click the three dots button to open appropriate dialog where you can manually specify the values.

DataStaticComboBox should be used whenever you need to select an item from predefined list fill property of String type.

ComboBox and Events
Click the last combo box on the form.

In Component Inspector, see properties:

  • Items = defined list of items. Click the IDispatch item and press F2. Then click the ‘…’ button to open appropriate dialog where you can specify values manually.

The simple ComboBox component should be used in combination with defined Events. Click the Verification button and see its name in Component Inspector.

The name is BtnExample. It is important to know the name becase event name must be formed as a combination of component name and event name. In our case, we will need a script that will contain BtnExampleOnClick function. Using this event we will be able to verify if object or entity has been assigned to the synonym. If we select ‘All’ from the last combo box and no object will be assigned, a message box with text “Nothing assigned ” will appear. Otherwise “Object assigned” or “Entity assigned” text will be displayed. Note: Remember to press Apply after changing values in Entity(DataComboBox).

Let’s see the definition of this script.

function BtnExampleOnClick()
{
var text = 'Nothing assigned ';
var Model = Synonym.Root();
var OrigSynonym = Model.Synonyms.GetObjectById( Synonym.Id );
// We need to read original object. 'Synonym' is only a temporary
// object (created when a form is edited) that that doesn't have
// all properties loaded/filled.
if (CBMSGDlg.Text == 'All')
{
if (OrigSynonym.Object!=null) text = 'Object is assigned';
}
else
{
if (OrigSynonym.Entity!=null) text = 'Entity is assigned';
}
System.ShowMessageDialog(1000,'Synonym Verification',text,3,4+8);
/* Opens new dialog

param1 - index of dialog for each dialog must be unique index
to implement the "Don't show again" function
param2 - Form name
param3 - Text of message
param4 - Type of dialog you can choose
Warning - 1
Error - 2
Information - 3
Confirmation - 4
Custom - 5
param5 - Buttons you can choose
1 - Yes
2 - No
4 - Ok
8 - Cancel
16 - Abort
32 - Retry
64 - Ignore
128 - All
256 - No to All
512 - Yes to All
1024 - Help
*/
}

MessageDialog
On line 17, you can see how to display MessageDialog via scripting.

Result:

That’s all. For more information about how to create a new package, how to create new scripts etc. please see out Toad Data Modeler Manual, section Customization | Customization Sample.

Regards,

Vaclav

How to Estimate Database Size

Thursday, July 17th, 2008

Hi,

in this article you will find out how to take advantage of internal scripting to estimate database size. I will show you how to enable Expert Mode and how to write and execute a script that will iterate through all entities and process some entitity properties.

As you probably know, in both Physical and Logical models you can specify Size on the Entity Properties dialog. In my example, I will use the Videorental sample - physical model for Oracle 10g.

Step 1: Open Sample Model
Click File | Open Samples… and select the Videorental model.

Step 2: Define Sizes for several entities
Edit several entities and define SIZE.

Step 3: Enable Expert Mode
a) Click Settings | Options and select tab General.
b) Enable the Expert Mode checkbox.

Step 4: Open Scripting Window
a) Click Tools | Scripting Window.
b) Click View | Show Registered Objects.

On the left side, you can see a list of currently opened models. Only the Videorental sample is available in my example. Let’s select the Videorental item and click the Right Arrow button to move it to the box on the right.

Step 5: Change Name in Script
Click the Name in Script item and rename it to ‘Model’.

Step 6: Define the Function main() content

Define function main() this way:

function main()
{
var e, Entity, dbSize;
dbSize = 0;
Model.Lock();
for (e=0; e<Model.Entities.Count; e++)
{
Entity = Model.Entities.GetObject(e);
Entity.Lock();
dbSize += Entity.Size;
Entity.UnLock();
}
Model.UnLock();
Log.Information("Estimated database size is: "+dbSize + "MB");
}

Script explanation:

  • function main() is the only executable function. You can write sevelar functions but only function main() will be executed after clicking on the green Execute Script icon.
  • On line 3, you can find definition of three variables. Variable ‘e’ will be used for iteration, to ‘Entity’ I will assign particular entity (object) and dbSize will represent the final estimated size of my database.
  • On line 6, you can see ‘for’ loop where the number of entities is accessed via Model.Entities.Count. Where to find out how to access the number of entities? - In Reference Guide. Click Help | Reference and see PERModel class. PER = Physical Entity Relationship.

Model has Entities. Entities is a List. Click the List link to see properties of the List class.

List class has the Count property. The Reference Guide document contains all accessible objects, its functions, properties and some other valuable data. Back to our script….

  • On line 10, the value of SIZE property of particular iterated entity is added to the current value of the dbSize variable. Again, how will you find out that Entity.Size can be used for getting the value of SIZE property? Open the Reference Guide and select the PEREntity class. You will find there the ’size’ property.

Note: If you want to access property specific for Oracle 10g database, select PEREntityOR10 class etc.

  • The rest of the script is, I believe, self-explanatory.

Step 7: Execute Script
Click the Execute Script icon (green arrow) and see the result.

Of course, you can modify the script e.g. to filter entities by Schema and output subtotals and so on.

I look forward to your feedback. :)

Regards,

Vaclav