Front desk Patchwork SQL statements to the background

Source: Internet
Author: User
Tags reflection

Sometimes we will make some SQL in the foreground dynamically generated, this is the first thing we have to do is to verify that he is not legal, if the SQL statement at the end of and or or we have to delete processing, otherwise it will be an error.

1. Front-desk JS judge whether to meet the left and right bracket symmetry

function Checkbracket (algorithms) {            var bracket = [];            var algorithms = Algorithms | | '';            for (var i = 0; i < algorithms.length; i++) {                if (Algorithms.charat (i) = = "(") {                    Bracket.push (')                }                if (Algorithms.charat (i) = = ")") {                    if (bracket.length) {                        bracket.pop ()                    } else {                        alert (' conditional brackets are not paired, missing opening parenthesis! ')                        return false;}}            }            if (bracket.length) {                alert (' conditional brackets are not paired, the closing parenthesis is missing! ')                return false;            }            return true;        }

2. Determine if the SQL statement syntax is met

public string Getbool (string exp)    {        string flag = "true";        Try        {            if (exp. EndsWith ("and") | | Exp. EndsWith ("or"))            {                exp = exp. Contains ("and")? Exp. Substring (0, exp. LENGTH-4): Exp. Substring (0, exp. Length-3);            }            EXP = exp. Replace ("and", "&&"). Replace ("or", "| |");            var type = Type.gettypefromprogid ("Msscriptcontrol.scriptcontrol");            var obj = activator.createinstance (type);            Type. InvokeMember ("Language", System.Reflection.BindingFlags.SetProperty, NULL, obj, new object[] {"JavaScript"});            var result = type. InvokeMember ("Eval", System.Reflection.BindingFlags.InvokeMethod, NULL, obj, new object[] {exp});        }        catch (Exception e)        {            flag = "false";        }        return flag;    }


Front desk Patchwork SQL statements to the background

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.