Mygeneration: Obtain the database name of all Oracle databases. Name of the data table life Column

Source: Internet
Author: User

Use the mygeneration Automatic Generation Code tool to obtain the Database Name and data table name of all Oracle databases. The procedure is as follows:
1. Set the database link string provider = oraoledb. oracle.1; Password = mypassword; persist Security info = true; user id = myid; Data Source = mydatasource in default settings of mygeration
2. Copy the following code to the form on the interface code tab.

Public class generatedgui: dotnetscriptgui
{
Public generatedgui (zeuscontext context): Base (context ){}

//-----------------------------------------
// The User Interface entry point
//-----------------------------------------
Public override void setup ()
{
// ** Uncomment code below to see UI **

// UI. width = 100;
// UI. Height = 100;
// Guilabel lbldemo = UI. addlabel ("lbldemo", "Demo", "demo tooltip ");
// UI. showgui = true;

// Guilabel lblpath;
// Guitextbox txtnamespace;
Guicombobox cmbdatabase;
Guicombobox cmbtable;
Guicombobox cmbcolumn;
 
Ui. Title = "read all data tables ";
UIS. width = 450;
Ui. Height = 500;
Ui. backcolor = "wheat ";
Ui. showgui = true;
// Add a Form Control
Ui. addlabel ("lblpath", "output path:", "select the output path .");
String soutputpath = "";
If (input. Contains ("defaultoutputpath "))
{
Soutputpath = input ["defaultoutputpath"]. tostring ();
}
// Output file storage path
Ui. addtextbox ("txtpath", soutputpath, "select the output path .");
Ui. addfilepicker ("btnpath", "select path", "select the output path.", "txtpath", true );
// Program namespace
Ui. addlabel ("lblnamespace", "namespace:", "provide your objects namespace .");
Ui. addtextbox ("txtnamespace", "ZTE. tmobileupdate", "provide your objects namespace .");
// Database drop-down list
Ui. addlabel ("lbldatabases", "database selection:", "select a database in the dropdown below .");
Cmbdatabase = UI. addcombobox ("cmbdatabase", "select a database .");
Setupdatabasedropdown (cmbdatabase );
Cmbdatabase. attachevent ("onchange", "cmbdatabase_onchange ");
// Select a data table
Ui. addlabel ("lbltables", "data table Selection:", "select tables from the ListBox below .");
Cmbtable = UI. addcombobox ("cmbtable", "select tables :");
Setuptablesdropdown (cmbdatabase, cmbtable );
Cmbtable. attachevent ("onchange", "cmbtable_onchange ");
// Select View
Ui. addlabel ("lblcolumns", "field selection:", "select columns from the ListBox below .");
Cmbcolumn = UI. addcombobox ("cmbcolumn", "select columns :");

}
 
Public void setupdatabasedropdown (guicombobox databases)
{
Try
{
If (mymeta. isconnected)
{
Databases. binddata (mymeta. databases );
// Determine whether the Database List is empty
If (mymeta. defaultdatabase! = NULL)
{
Databases. selectedvalue = mymeta. defaultdatabase. Alias;
Bindtables (databases. selectedvalue );
}
}
}
Catch
{
}
}
Public void setuptablesdropdown (guicombobox databases, guicombobox tables)
{
Try
{
If (mymeta. isconnected)
{
// Check whether the data table list is empty
If (databases. selectedvalue! = NULL) & (tables. selectedvalue! = NULL ))
{
Bindcolumns (databases. selectedvalue, tables. selectedvalue );
}
}
}
Catch
{
}
}
 
// Database switching event
Public void cmbdatabase_onchange (guicombobox Control)
{
Guicombobox cmbdatabases = UI ["cmbdatabase"] As guicombobox;
Bindtables (cmbdatabases. selectedtext );
}
// Data table switching event
Public void cmbtable_onchange (guicombobox Control)
{
Guicombobox cmbdatabases = UI ["cmbdatabase"] As guicombobox;
Guicombobox cmbtable = UI ["cmbtable"] As guicombobox;
Bindcolumns (cmbdatabases. selectedtext, cmbtable. selectedtext );
}
 
Public void bindtables (string sdatabase)
{
Try
{
Idatabase DB = mymeta. Databases [sdatabase];
Guicombobox cmbtable = UI ["cmbtable"] As guicombobox;
Cmbtable. binddata (db. Tables );
}
Catch
{
}
}
 
Public void bindcolumns (string sdatabase, string stable)
{
Try
{
Idatabase DB = mymeta. Databases [sdatabase];
Itable objtable = dB. Tables [stable];
Guicombobox cmbcolumn = UI ["cmbcolumn"] As guicombobox;
Cmbcolumn. binddata (objtable. columns );
}
Catch
{
}
}
}
3. Copy the following code to the form on the template code tab.
<%
Public class generatedtemplate: dotnetscripttemplate
{
Public generatedtemplate (zeuscontext context): Base (context ){}

//---------------------------------------------------
// Render () is where you want to write your logic
//---------------------------------------------------
Public override void render ()
{
If (context. Objects. containskey ("dnputils "))
{
Dnputils. saveinputtocache (context );
}
String strfilenamebase = input ["txtpath"]. tostring ();
String strnamespace = input ["txtnamespace"]. tostring ();
String strdatabasename = input ["cmbdatabase"]. tostring ();
String strtablename = input ["cmbtable"]. tostring ();
String strcolumnname = input ["cmbcolumn"]. tostring ();

Output. writeln ("output file path:" + strfilenamebase );
Output. writeln ("namespace name:" + strnamespace );
Output. writeln ("Current Database Name:" + strdatabasename );
Output. writeln ("current data table name:" + strtablename );
Output. writeln ("Name of the selected column:" + strcolumnname );
Getalldatabasename ();
}
// Output all database names
Private void getalldatabasename ()
{
Foreach (idatabase D in mymeta. databases)
{
Getalltablesname (D. Alias );
}
}
// Output all data table names
Private void getalltablesname (string sdatabase)
{
Idatabase objdatabase = mymeta. Databases [sdatabase];
Output. writeln ("Current Database:" + sdatabase + "Total number of data tables:" + objdatabase. Tables. Count );
Foreach (itable t in objdatabase. Tables)
{
Getallcolumnsname (sdatabase, T. Alias );
}
}
Private void getallcolumnsname (string sdatabase, string stable)
{
Idatabase objdatabase = mymeta. Databases [sdatabase];
Itable objtable = objdatabase. Tables [stable];
Output. writeln ("current data table:" + stable + "Total number of data columns:" + objtable. Columns. Count );
Foreach (icolumn C in objtable. columns)
{
If (C. isinprimarykey)
{
Output. writeln ("primary key name:" + C. Alias );
}
Else
{
Output. writeln ("common column name:" + C. Alias );
}
}
}

}
%>
4. Click the run arrow button on the menu to display all the results in the form on the output tab.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.