Atitit. MSSQL SQL Server conversion MySQL and paging SQL AST build

Source: Internet
Author: User
Tags mssql

Atitit. MSSQL SQL Server conversion MySQL and paging SQL AST build

1. Main conversions :: function Conversion , paging conversion 1

2. Ideas :: MSSQL SQL >>ast>>mysql 1

3. the main SQL is as follows ::: 1

4. Mssql2mysqlconvertor (proj:wechatadm4propt 2

1. The main conversion::Conversion of Functions,Paging Conversion2. Ideas:: MSSQL SQL >>ast>>mysql3. sqlthe main following:::

Author :: Old Wow's paw attilax ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

SELECT GroupID,

GroupName

CONVERT (varchar, createtime, +) as Createtime,

Weixinusercount,

Remark

From

(SELECT row_number () over (ORDER by Createtime DESC) as RowNum, D1.group Id

D1.groupname,

D1.createtime,

D1.remark,

(SELECT count (D2. UserID)

From T_mb_weixinuser D2

WHERE d2.groupid=d1.groupid) as Weixinusercount

From T_mb_group D1

WHERE 1=1)

As groups

WHERE RowNum between 1 and 10

4.Mssql2mysqlconvertor (proj:wechatadm4propt

Public class mssql2mysqlconvertor {

@Inject

SqlAstBuilderP32 astbldr;

SqlAstP32 ast;

/**

 *  @author Attilax The claws of old Wow

 *  @since p33 j_t_37

*/

public   static   void   main ( string []   args )  {

String txt = filex. Read (pathx. ClassPath () +  "/mssql1.sql" );

txt  =  Strutil . Replaceenterchar2space (txt);

txt  =  txt . ReplaceAll ("row_number.*,"", " ");

Mssql2mysqlconvertor x = new mssql2mysqlconvertor();

String sql_mysql = x. Convert (txt);

System . out . println (JsonX. toJsonStrO88 (x. AST ));

System . out . println (sql_mysql);

}

/**

 *  @author Attilax The claws of old Wow

 *  @return

 *  @since p33 m_j_45

*/

private   string   convert ( string   txt )  {

String page_s = strutil. Find ("rowNum (. +) between.+and.+$", txt). Get (0)

. toString ();

page_s  =  Strutil . Replacedoublespace (page_s);

String [] a = page_s. toUpperCase (). Trim (). Split ("between");

String [] a2 = a[1]. toLowerCase (). Trim (). Split ("and");

Sqlpageparam p = new sqlpageparam();

p . startindex  =  integer parseint ( a2 [ Span style= "COLOR: #ff0ff" >0 ]. trim ())  -  1

P . pagesize  =  Integer . parseint (A2[1]. Trim ());

AST  =  New SqlAstP32();

AST . Preother  =  txt . substring (0, txt. ) indexOf (page_s));

AST . Pagepart  =  P ;

if (ast. Preother . Trim (). toLowerCase (). EndsWith ("where"))

AST . Preother  =  AST . Preother  +  "1=1" ;

return ast. Preother  +  "Limit"  +  P . StartIndex  +  ","  +  P . pagesize ;

}

Atitit. MSSQL SQL Server conversion MySQL and paging SQL AST build

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.