Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miner不支持自写sql字符串 #36

Closed
lixiaohong0212 opened this issue Sep 15, 2017 · 2 comments
Closed

miner不支持自写sql字符串 #36

lixiaohong0212 opened this issue Sep 15, 2017 · 2 comments

Comments

@lixiaohong0212
Copy link

版本2.1.5

1.在设置where条件时只支持某个字段或者数组的形式。不支持在已有sql直接拼接一段字符串形成新的sql

例如:
不固定 (status = 1 and dec in ("ss", "cc")) or name = "kk"

2.解决方案
/Server/Asyn/Mysql/Miner.php

/**
* AND logical operator. 参考laravel起名
*/
(1) const LOGICAL_RAW = "RAW";

(2) 方法里的getCriteriaString
从原先的
case self::IS:
case self::IS_NOT:
改成
case self::LOGICAL_RAW:
case self::IS:
case self::IS_NOT:

(3)
在方法里
从原先
$statement .= $criterion['column'] . " " . $criterion['operator'] . " " . $value;
改成
if ($criterion['operator'] == self::LOGICAL_RAW) {
$statement .= " " . $value . " ";
} else {
$statement .= $criterion['column'] . " " . $criterion['operator'] . " " . $value;
}

3.调用效果支持
$selectMiner = $selectMiner->openWhere();
//wheres 代表 不固定 (status = 1 and dec in ("ss", "cc")) or name = "kk"
$selectMiner = $selectMiner->where('', $wheres, 'RAW');
$selectMiner = $selectMiner->closeWhere();

@tmtbe
Copy link
Collaborator

tmtbe commented Sep 18, 2017

多谢,已采纳

@tmtbe tmtbe closed this as completed Sep 18, 2017
@tmtbe
Copy link
Collaborator

tmtbe commented Sep 18, 2017

预计在2.5.2.版本会加入

public function http_testMysqlRaw()
    {
        $selectMiner = $this->mysql_pool->dbQueryBuilder->select('*')->from('account');
        $selectMiner = $selectMiner->where('', '(status = 1 and dec in ("ss", "cc")) or name = "kk"', Miner::LOGICAL_RAW);
        $this->http_output->end($selectMiner->getStatement(false));
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants