To create a stored procedure annotation in SQL Server to MySQL

Source: Internet
Author: User
Tags odbc prepare

To create a stored procedure annotation in SQL Server to 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);

#获取所有的用户表

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

$sth->execute ();

my $n = 0;

my $ok = 0;

My $sort _column= "";

while (@data = $sth->fetchrow_array ())

{

#print $data [0];

print ' is querying 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->{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);

}

$sth->finish;

$DBH->disconnect;

print ' All tables stored procedure creation end '. ' n ";

Sub Do_sql

{

print ' starts creating '. $_[0]. ' Table's stored procedure '. ' n ";

My $sql =$_[1];

Open (FILE, "" "Createtableallproduce.txt");

Syswrite (FILE, "$nn");

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

Syswrite (FILE, "$sqln");

Close (FILE);

$sql =~s//*/------notes begin--------/g;

$sql =~s/*//------annotation end--------/g;

$sql = ' CREATE PROCEDURE '. $_[0]. ' () '. ' N '. ' BEGIN '. ' n ". '/* '. $sql. ' */'." n ". ' End; ';

My $data _base = "Dbi:mysql: $db _name: $location: $port";

My $dbh 3=dbi-> Connect ($data _base, $db _user, $db _pass);

$DBH 3->do ("SET character_set_client = ' UTF8 '");

$DBH 3->do ("SET character_set_connection = ' UTF8 '");

My $data _str=encode ("Utf-8", Decode ("GBK", $sql));

My $sth = $dbh 3->prepare ($sql);

Open (FILE, "" "Myproduce.txt");

Syswrite (FILE, "$nn");

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

Syswrite (FILE, "$sqln");

Close (FILE);

$sth->execute () or Die "$data _str----ERROR:: $data _str:: $dbh 3->errstr";

$DBH 3->disconnect;

print ' Create '. $_[0]. ' The table's stored procedure ends '. ' 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.