- Work done on insert() and update() function from QueryBuilder.
- Fixed save() and saveAll() from repository - QueryBuilder can now be flushed after queries.
This commit is contained in:
1 parent
79fdabe786
commit
d1961ec807
9 files changed
+122
-44
No files matched your search
+46
-15
@@ -39,15 +39,15 @@ class QueryBuilder
|
||||
|
||||
public function insert(array $fieldlist, string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self
|
||||
{
|
||||
if ( null === $this->getFragment(Query\Insert::class) ) {
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
}
|
||||
|
||||
if ( null === $this->getFragment(Query\Insert::class) ) {
|
||||
if ( $schema ) {
|
||||
$table = "\"$schema\".$table";
|
||||
}
|
||||
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
}
|
||||
|
||||
$insert = new Query\Insert();
|
||||
$this->push($insert);
|
||||
|
||||
@@ -73,14 +73,14 @@ class QueryBuilder
|
||||
|
||||
public function update(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self
|
||||
{
|
||||
if ( ! $this->getFragment(Query\Update::class) ) {
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
}
|
||||
|
||||
if ( ! $this->getFragment(Query\Update::class) ) {
|
||||
if ( $schema ) {
|
||||
$table = "\"$schema\".$table";
|
||||
}
|
||||
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
}
|
||||
|
||||
$update = new Query\Update();
|
||||
$this->push($update);
|
||||
@@ -95,7 +95,7 @@ class QueryBuilder
|
||||
public function set(array $dataset) : self
|
||||
{
|
||||
|
||||
if ( null === ( $values = $this->getFragment(Query\Set::class) ) ) {
|
||||
if ( null === ( $set = $this->getFragment(Query\Set::class) ) ) {
|
||||
$set = new Query\Set($this);
|
||||
$this->push($set);
|
||||
}
|
||||
@@ -116,13 +116,13 @@ class QueryBuilder
|
||||
|
||||
public function from(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self
|
||||
{
|
||||
if ( $database ) {
|
||||
$table = "$database.$table";
|
||||
}
|
||||
|
||||
if ( $schema ) {
|
||||
$table = "\"$schema\".$table";
|
||||
}
|
||||
|
||||
if ( $database ) {
|
||||
$table = "$database.$table";
|
||||
}
|
||||
|
||||
if ( null !== ( $from = $this->getFragment(Query\From::class) ) ) {
|
||||
$from->add($alias ? [ $alias => $table ] : $table);
|
||||
@@ -219,6 +219,28 @@ class QueryBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function join(string $type, $table, $field, $value, bool $outer = false) : self
|
||||
{
|
||||
if ( null === $join = $this->getFragment(Query\Join::class) ) {
|
||||
$join = new Query\Join();
|
||||
$this->push($join);
|
||||
}
|
||||
|
||||
$join->add($type, $table, $field, $value);
|
||||
|
||||
$join->outer = $outer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
/*
|
||||
"LEFT JOIN PAI_DOS ON PAI_DOS.MATR = PAI_DOS_EMPL.MATR"
|
||||
"LEFT JOIN PAI_DOS_2 ON PAI_DOS_2.MATR = PAI_DOS.MATR"
|
||||
"LEFT JOIN PAI_CAND ON PAI_CAND.MATR = PAI_DOS.MATR"
|
||||
|
||||
"LEFT JOIN PAI_TAB_CORP_EMPL ON PAI_TAB_CORP_EMPL.CORP_EMPL = PAI_DOS_EMPL.CORP_EMPL",
|
||||
"LEFT JOIN PAI_TAB_LIEU_TRAV ON PAI_TAB_LIEU_TRAV.LIEU_TRAV = PAI_DOS_EMPL.LIEU_TRAV",
|
||||
"LEFT JOIN PAI_TAB_BAT ON PAI_TAB_BAT.BAT = PAI_TAB_LIEU_TRAV.BAT"
|
||||
*/
|
||||
public function push(Query\Fragment $queryFragment) : self
|
||||
{
|
||||
$this->queryStack[] = $queryFragment;
|
||||
@@ -240,6 +262,15 @@ class QueryBuilder
|
||||
|
||||
return implode(" ", $sql);
|
||||
}
|
||||
|
||||
public function reset() : void
|
||||
{
|
||||
$this->parameters = $this->values = $this->queryStack = [];
|
||||
$this->conditionOperator = Query\Where::CONDITION_AND;
|
||||
$this->parameterIndex = 0;
|
||||
|
||||
unset($this->where);
|
||||
}
|
||||
|
||||
public function getFragment(string $class) : ? Query\Fragment
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user