Atitit. Mssql SQL server converts mysql and paging SQL ast, atitit. mssqlast

Source: Internet
Author: User

Atitit. Mssql SQL server converts mysql and paging SQL ast, atitit. mssqlast

Atitit. Mssql SQL server converts mysql and sets up paging SQL ast

 

1. Major conversions: Function Conversion, paging conversion 1

2. Idea: mssql SQL> ast> mysql 1

3. SQL mainly includes: 1

4. Mssql2MysqlConvertor (proj: wechatAdm4propt 2

 

 

1. Major conversions: function conversions and paging conversions 2. Ideas: mssql SQL> ast> mysql3. the main SQL statements are as follows :::

 

Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com

Reprinted please indicate Source: http://blog.csdn.net/attilax

 

SELECT groupid,

Groupname,

Convert (varchar, createtime, 120) AS createtime,

WeixinuserCount,

Remark

FROM

(SELECT row_number () over (order by createtime DESC) AS rowNum, d1.groupid,

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 old wow's paw

* @ 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 old wow's paw

* @ 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 ("");

String [] a2 = a [1]. toLowerCase (). trim (). split ("and ");

SqlPageParam p = new SqlPageParam ();

P. startIndex = Integer. parseInt (a2 [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;

 

}

 

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.