|
@@ -11,6 +11,7 @@ namespace think\db\builder;
|
|
|
|
|
|
use think\db\BaseQuery;
|
|
|
use think\db\BaseQuery as Query;
|
|
|
+use think\db\BaseQuery as Query;
|
|
|
use think\db\Builder;
|
|
|
use think\db\Raw;
|
|
|
|
|
@@ -22,6 +23,32 @@ class Dm extends Builder
|
|
|
protected $insertAllSql = '%INSERT% INTO %TABLE% (%FIELD%) VALUES %DATA% %COMMENT%';
|
|
|
protected $updateSql = 'UPDATE %TABLE% %JOIN% SET %SET% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
|
|
|
|
|
|
+ public function select(Query $query, bool $one = false): string
|
|
|
+ {
|
|
|
+ $options = $query->getOptions();
|
|
|
+
|
|
|
+ return str_replace(
|
|
|
+ ['%TABLE%', '%PARTITION%', '%DISTINCT%', '%EXTRA%', '%FIELD%', '%JOIN%', '%WHERE%', '%GROUP%', '%HAVING%', '%ORDER%', '%LIMIT%', '%UNION%', '%LOCK%', '%COMMENT%', '%FORCE%'],
|
|
|
+ [
|
|
|
+ $this->parseTable($query, $options['table']),
|
|
|
+ $this->parsePartition($query, $options['partition']),
|
|
|
+ $this->parseDistinct($query, $options['distinct']),
|
|
|
+ $this->parseExtra($query, $options['extra']),
|
|
|
+ $this->parseField($query, $options['field'] ?? []),
|
|
|
+ $this->parseJoin($query, $options['join']),
|
|
|
+ $this->parseWhere($query, $options['where']),
|
|
|
+ $this->parseGroup($query, $options['group']),
|
|
|
+ $this->parseHaving($query, $options['having']),
|
|
|
+ $this->parseOrder($query, $options['order']),
|
|
|
+ $this->parseLimit($query, $one ? '1' : $options['limit']),
|
|
|
+ $this->parseUnion($query, $options['union']),
|
|
|
+ $this->parseLock($query, $options['lock']),
|
|
|
+ $this->parseComment($query, $options['comment']),
|
|
|
+ $this->parseForce($query, $options['force']),
|
|
|
+ ],
|
|
|
+ $this->selectSql
|
|
|
+ );
|
|
|
+ }
|
|
|
/**
|
|
|
* 生成insertall SQL
|
|
|
* @access public
|