Download the PHP package zqx/sql-translation without Composer

On this page you can find all versions of the php package zqx/sql-translation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sql-translation

sql-translation

A pure PHP SQL parser to translate custom sql to MySQL or PostgreSQL

安装

推荐使用composer进行安装,然后引用vendor/autoload.php即可

composer require zqx/sql-translation

What

Why

  1. 在BI系统或者和数据有关的场景下,需要让业务人员通过动态写sql进行查询,可以使用公式、运算符、字段、字符串、数字以及以上各种内容的组合来增强灵活性。
    • 期内充值:如数据为新登时间:2018-10-01;时间:2018-10-03;金额:100.00,由业务人员加上动态字段date_diff(时间,新登时间)识别每条充值记录为玩家新登第n日充值;
    • 权重分摊:如数据有自营流水、联运流水、投入等字段,每天的盈利计算公式为自营+联运*20%-投入
  2. 针对同一个公式,需要保证均能正常翻译成MySQL或者PostgreSQL的执行代码,减少上层业务对下层db的直接依赖。
    • 例如拼接字符串函数:MySQL中为concat(str1, str2), PostgreSQL为(str1 || str2)
  3. 保证良好的安全性,避免通过动态sql直接穿透到代码执行区域,减少恶意的sql注入风险。
  4. 通过别名映射,如rectime=>时间展示给用户,避免用户直接拿到数据库真实字段名,同时还可以屏蔽不想被访问到的字段。

How

  1. 初始化

  2. 传入sql伪码进行编译

具体示例可看:demo.php

更多进行sql编译的例子可看单元测试用例:TranslatorTest.php

实现分析

流程图

步骤分析

1. 分词

使用正则进行分词:

得到tokenList:

2. 解析

语法分析使用从底向上的方式,定义S为原语,同时可以通过传入运算符、函数、括号、关键字生成4种状态的复合S。

示例

3. 生成器

基础流程

针对不同db生成不同的函数目标码

版本记录

v1.0

第一个版本:支持函数、字段、运算符等组合的单sql转化。

v1.1

把原有的分词器实现从直接扫描法升级为使用正则扫描。

v1.2

新增循环、声明和变量等语句的支持。


All versions of sql-translation with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zqx/sql-translation contains the following files

Loading the files please wait ....