Annotate the stored procedure in SQL Server and create it in mysql.

Source: Internet
Author: User

Annotate the stored procedure in SQL Server and create it in mysql.

#! /Usr/bin/perl

Use DBI;

Use Switch;

Use Encode;

Use Encode: CN;

My $ source_name = "sqldb ";

My $ source_user_name = "sa ";

'My $ source_user_psd = "123 ";

My $ db_name = "mysqldb ";

My $ location = "192.168.0.208 ";

My $ port = "3306 ";

My $ db_user = "zoe ";

My $ db_pass = "123 ";

My $ dbh = DBI-> connect ("dbi: ODBC: $ source_name", $ source_user_name, $ source_user_psd );

# Getting all user tables

My $ something = $ dbh-> prepare ("select name from sys. objects where type = 'P '");

$ Something-> execute ();

My $ n = 0;

My $ OK = 0;

My $ sort_column = "";

While (@ data = $ something-> fetchrow_array ())

{

# Print $ data [0];

Print 'query table '. $ data [0]. "Stored Procedure \ n ";

My $ SQL _create = "EXEC Sp_HelpText '$ data [0]'";

My $ dbh_mssql = DBI-> connect ("dbi: ODBC: $ source_name", $ source_user_name, $ source_user_psd, {RaiseError => 1 });

$ Dbh_mssql-> {LongTruncOk} = 1;

$ Dbh_mssql-& gt; {LongReadLen} = 1048576;

My $ sth_select = $ dbh_mssql-> prepare ($ SQL _create );

$ Sth_select-> execute () or die 'cannot execute: '. $ sth_select-> errstr ();

My $ select_col;

My $ select_data;

While ($ select_data = $ sth_select-> fetchrow_array ())

{

$ Select_col. = $ select_data;

}

Do_ SQL ($ data [0], $ select_col );

}

$ Something-> finish;

$ Dbh-> disconnect;

Print 'stored procedure creation of all Table'. "\ n ";

Sub do_ SQL

{

Print 'start to create'. $ _ [0]. 'table Stored Procedure'. "\ n ";

My $ SQL =$ _ [1];

Open (FILE, "》createtableallproduce.txt ");

Syswrite (FILE, "$ n \ n ");

Syswrite (FILE, "$ data [0] \ n ");

Syswrite (FILE, "$ SQL \ n ");

Close (FILE );

$ SQL = ~ S/\ */------ annotation starts --------/g;

$ SQL = ~ S/\ * \ // ------ end the annotation --------/g;

$ SQL = 'create processure '. $ _ [0]. '()'. "\ n ". 'begin '. "\ n ". '/*'. $ SQL. '*/'. "\ n ". 'End ;';

My $ data_base = "DBI: mysql: $ db_name: $ location: $ port ";

My $ dbh3 = DBI-> connect ($ data_base, $ db_user, $ db_pass );

$ Dbh3-> do ("SET character_set_client = 'utf8 '");

$ Dbh3-> do ("SET character_set_connection = 'utf8 '");

My $ data_str = encode ("UTF-8", decode ("gbk", $ SQL ));

My $ something = $ dbh3-> prepare ($ SQL );

Open (FILE, "Export myproduce.txt ");

Syswrite (FILE, "$ n \ n ");

Syswrite (FILE, "$ data [0] \ n ");

Syswrite (FILE, "$ SQL \ n ");

Close (FILE );

$ Something-> execute () or die "$ data_str ---- ERROR ::$ data_str ::$ dbh3-> errstr ";

$ Dbh3-> disconnect;

Print 'create'. $ _ [0]. 'END of the table Stored Procedure '. "\ n ";

}

Related Article

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.