Home |  MySQL Buzz |  FAQ |  Feeds |  Submit your blog feed |  Feedback |  Archive |  Aggregate feed RSS 2.0 English Deutsch Español Français Italiano 日本語 Русский
Running Python scripts within MySQL Workbench
+0 Vote Up -0 Vote Down

In my previous blog post I explained how to enable Python in the MySQL Workbench GRT Shell. This blog explains how to run a simple Python script using Workbench. You don't need to change any preferences to make this work.

Save the following little script to a file called wbscript.py. It will print the tables in the first schema of the first model opened.


import grt

model = grt.root.wb.doc.physicalModels[0]
for tab in model.catalog.schemata[0].tables:
print "Table: `%s`" % (tab.name)

To see the output of the script make sure that:

  1. you have a model open (with at least 1 table)
  2. the Output Window is visible: View > Advanced > Output Window
  3. make the Output option active in the Output Window (defaults to Messages)

In Workbench, chose Tools > Run Workbench Script and locate the script. Open it and it will run immediately (successfully, hopefully!). The output should be something like this (name of table could be something else):


Executing script /Users/geert/Projects/mysql/wbscript.py...
Table: `t1`

Script finished.

Running Workbench scripts is easy, but more awesome would be to make your own plug-in! This is however a different beast that I'll hopefully cover in next posts.

Votes:

You must be logged in with a MySQL.com account to vote on Planet MySQL entries. More information on PlanetMySQL voting.

Planet MySQL © 1995-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Sun Microsystems, Inc. and does not
necessarily represent the opinion of Sun Microsystem, Inc. or any other party.