MySQL 语句块解析
Posted 上下博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL 语句块解析 相关的知识,希望对你有一定的参考价值。
var i, b, c = "";
for (i = 0; i < q.length; i++) {
b = q.charAt(i), -1 === e.indexOf(b) || 0 != d ? -1 === a.indexOf(b) || 0 != d ? ("'" == b && 0 == f % 2 && (g += 1), '"' == b && 0 == g % 2 && (f += 1), d = 0 == g % 2 && 0 == f % 2 ? !1 : !0, -1 === a.indexOf(b) || 0 != d ? c += b : ("" != c && h.push([c, i]), h.push([b, i]), c = "")) : ("" != c && h.push([c, i]), h.push([b, i]), c = "", "'" == b && 0 == f % 2 && (g += 1), '"' == b && 0 == g % 2 && (f += 1)) : ("" != c && h.push([c, i]), c = "")
}
console.log(h);
从网上找了一些SQL语句
SHOW DATABASES;
CREATE USER name IDENTIFIED BY 'ssap(":dr ow';
SET PASSWORD FOR name=PASSWORD('fdddfd');
SHOW GRANTS FOR name;
GRANT SELECT ON db_name.* TO name;
SHOW DATABASES;
DELETE FROM tb_name WHERE id=3;
CREATE PROCEDURE pro(
IN num INT,OUT total INT)
BEGIN
SELECT SUM(score) INTO total FROM tb_name WHERE id=num;
END;
DROP PROCEDURE pro;
解析效果如下
[
[ 'SHOW', 4 ],
[ 'DATABASES', 14 ],
[ ';', 14 ],
[ '\nCREATE', 22 ],
[ 'USER', 27 ],
[ 'name', 32 ],
[ 'IDENTIFIED', 43 ],
[ 'BY', 46 ],
[ "'", 47 ],
[ 'ssap(":dr ow', 70 ],
[ "'", 70 ],
[ ';', 71 ],
[ '\nSET', 76 ],
[ 'PASSWORD', 85 ],
[ 'FOR', 89 ],
[ 'name', 94 ],
[ '=', 94 ],
[ 'PASSWORD', 103 ],
[ '(', 103 ],
[ "'", 104 ],
[ 'fdddfd', 111 ],
[ "'", 111 ],
[ ')', 112 ],
[ ';', 113 ],
[ '\nSHOW', 119 ],
[ 'GRANTS', 126 ],
[ 'FOR', 130 ],
[ 'name', 135 ],
[ ';', 135 ],
[ '\nGRANT', 142 ],
[ 'SELECT', 149 ],
[ 'ON', 152 ],
[ 'db_name.*', 162 ],
[ 'TO', 165 ],
[ 'name', 170 ],
[ ';', 170 ],
[ '\nSHOW', 176 ],
[ 'DATABASES', 186 ],
[ ';', 186 ],
[ '\nDELETE', 194 ],
[ 'FROM', 199 ],
[ 'tb_name', 207 ],
[ 'WHERE', 213 ],
[ 'id', 216 ],
[ '=', 216 ],
[ '3', 218 ],
[ ';', 218 ],
[ '\nCREATE', 226 ],
[ 'PROCEDURE', 236 ],
[ 'pro', 240 ],
[ '(', 240 ],
[ '\n\n', 243 ],
[ 'IN', 249 ],
[ 'num', 253 ],
[ 'INT', 257 ],
[ ',', 257 ],
[ 'OUT', 261 ],
[ 'total', 267 ],
[ 'INT', 271 ],
[ ')', 271 ],
[ '\n\n', 274 ],
[ 'BEGIN\n\n', 285 ],
[ 'SELECT', 295 ],
[ 'SUM', 299 ],
[ '(', 299 ],
[ 'score', 305 ],
[ ')', 305 ],
[ 'INTO', 311 ],
[ 'total', 317 ],
[ 'FROM', 322 ],
[ 'tb_name', 330 ],
[ 'WHERE', 336 ],
[ 'id', 339 ],
[ '=', 339 ],
[ 'num', 343 ],
[ ';', 343 ],
[ '\n\n', 346 ],
[ 'END', 353 ],
[ ';', 353 ],
[ '\nDROP', 359 ],
[ 'PROCEDURE', 369 ],
[ 'pro', 373 ],
[ ';', 373 ]
]
以上是关于MySQL 语句块解析 的主要内容,如果未能解决你的问题,请参考以下文章