Toad World® Forums

Script to automate generation


#1

Hi,

Now I’ve got 3.1.5 I’d like to add some more automation.
Currently using Oracle 9, will shortly be using Oracle 10 in parallel.

I need to generate separate files for various parts of the DDL, eg tables, views, functions, etc.
I can create OTPs for each file and manually generate but I’d like to add a button to the form that loaded and generated each of a number of specified OTP selections in turn.
It would also need to manipulate the file name and add additional items to the script such as SPOOL command at the start.

I had achieved something like this in the earlier commercial version (but I had to edit TDM system scripts).

Can you give me some idea on how to do;

  1. loading of OTP selection from code
  2. creating a script in a user package that will be run from the form button

TIA
Kind regards
Malcolm


#2

Hi Malcolm,

please accept my apologies for the delay. To your questions:

  1. Loading of stored OTP selections (from XML file) from code is not available in the current version. I added your change request to our system. (CR# 47449). It is almost fixed and should appear in some future version of TDM3.

  2. Please see the Manual (Help | Manual), topic “Customization Sample | Calling existing script from model properties form”.

Regards,

Vaclav


#3

Hi Malcolm!

You can see the use of dynamic Generator setting in the new version of the scripting demo Package here:
http://modeling.inside.quest.com/thread.jspa?threadID=5240&tstart=0

The drawback of this approach is that you cannot use your saved Selected OTP settings, instead you create a completely new setting for each Generation “session” in the script. On the other hand, I believe this is exactly what you want.

At least the separation part of your wish…


#4

Hi Fero,

Thanks for that. it looks very promising.

However I find it hangs at the delete() in ClearSlectedOTP().
I always seem to have 5 items to delete and it hangs on the first delete.

I’ve tried it on new and existing models.

Please advise.
Thanks
Malcolm


#5

Really?! Well, I had a similar experience. As soon as I have assigned Stream.FileName = Generator.GetFSFileName, it has begun to work properly…

Ah, and it hangs a bit later, only you can’t see that because Log is not refreshing…


#6

Alternatively you can try to close all designers and (Model) Explorers and see if it helps…
I wonder what is the problem. It’s working for me…


#7

I’ve tried closing everything (apart from the Model and ModelScripting dialog).
It still hangs.


#8

That sucks…
Do you have the same script as in the new Package? Or do you have your own based on the template?

As an emergency you can try

Generator.CreateNewObjectInternal(118);

instead of

ClearSelectedOTP(Generator.SelectedOTP);

Although this will create a new object and the old object will still remain in the memory…


#9

Do you have the same script as in the new Package? Or do you have your own based on the template?

I took the new package and added my additional code to it.
When that didn’t work I went back using the new package as supplied.
When that didn’t work I conatcted you

Generator.CreateNewObjectInternal(118);

It seems to work with this change.

Now I’ll try to add the rest…

Thanks
Malcolm


#10

I’ve got quite a lot of this working now.
I’ve guessed at most of the strings I need to set selected OTPs but I’m stuck on the following;

  1. Permission to Objects
  2. The sub items eg Entities keys

Please let me know the deatils I need.

Many thanks
Malcolm


#11

To sum it up:

According to my investigation the problem is the wrong specification of the generated file.

Unlike in the former TDM version, the latest version tries to save the generated file to the disk in the Generation method:
In script PERCodeGenerator, method Generate,

DDLScript.SaveToFile();

Now if you specify a wrong file name (non existent Path) and you are on the Generator form, the GetFSFileName method will assign the directory for the FileName property. Which is wrong but still works good enough…
But if you assign an empty File Name directly to the stream FileName property, then the Stream.SaveFile method will try to show a SaveTo dialog and dialog and scripting threads will lock somehow.

So you either have to assign a correct File Name to the Stream or comment out the DDLScript.SaveToFile(); code.

Very mysteriously, in our case is also working not to clean up the Selected OTP object structure. Perhaps it will turn out that both things are wrongly implemented (the File Name and the cleaning also) and only put together it will show up


#12

And the new wish:

  1. Permissions are somehow out of Selected OTP scope. It’s hard coded for what I know…

  2. The sub items are “selected” just like the (root) Model Properties:
    function InitGeneratorKeys(Generator, EntityClassName)
    {
    SelectOTPProperty(SelectOTPClass(Generator.SelectedOTP, EntityClassName),
    “Keys”, “Create all Keys”);

Generator.FileName = “C:\Temp\Keys.sql”;
}

You can get the EntityClassName from an Entity object (EntityObj.ClassName) or if you know it, you can use something like PEREntityOR10.
The “Create all Keys” is defined in Generator InitSelectedOTPDefinitions…

Hope it will help


#13

Oh… Nononono…

Sorry for mistaken you. Permissions of Objects can be selected this way:

SelectOTPProperty(SelectOTPClass(Generator.SelectedOTP, Generator.Root().ClassName),
“InstanceUserGroupRelations”, “”);

Just look at the API documentation and look for Model objects Properties. Then the Properties Captions are the same as in the Selected OTP Tree on the Generator Properties form


#14

Great.
It now works just as I want it to.
Thanks very much for your help Fero.

Kind regards
Malcolm


#15

Hi Malcolm,

Just to let you know that in Beta 3.2.1.12, the CR 47 449 is resolved. - Ability to load OTP selection (for SQL script generation) from XML file from scripts.

Beta release announcement:
http://modeling.inside.quest.com/thread.jspa?messageID=19360

Please feel free check it out in the Beta. (It will be available in next official release 3.2 too.)

The Reference Guide has also been updated in the Beta. Please see there the following functions:
CSApplication.GetSelectedOTPFolder
SelectedOTP…

Regards,

Vladka