- WIP on insert/update statement
This commit is contained in:
1 parent
bad5123447
commit
828daffec8
13 files changed
+311
-36
No files matched your search
+51
-8
@@ -10,6 +10,12 @@ class QueryBuilder
|
||||
* Those are the parameters we are going to bind to PDO.
|
||||
*/
|
||||
public array $parameters = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* Those values are to be inserted or updated
|
||||
*/
|
||||
public array $values = [];
|
||||
|
||||
public string $conditionOperator = Query\Where::CONDITION_AND;
|
||||
|
||||
@@ -31,13 +37,45 @@ class QueryBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete(string $alias = "") : self
|
||||
public function insert(array $fieldlist, string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self
|
||||
{
|
||||
if ( ! $this->has(Query\Insert::class) ) {
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
}
|
||||
|
||||
if ( $schema ) {
|
||||
$table = "\"$schema\".$table";
|
||||
}
|
||||
|
||||
$insert = new Query\Insert();
|
||||
$this->push($insert);
|
||||
|
||||
$insert->fieldist = $fieldlist;
|
||||
$insert->alias = $alias;
|
||||
$insert->table = $table;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function values(array $dataset) : self
|
||||
{
|
||||
|
||||
if ( false === ( $values = $this->has(Query\Values::class) ) ) {
|
||||
$values = new Query\Values();
|
||||
$this->push($values);
|
||||
}
|
||||
|
||||
$values->add($dataset);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function delete() : self
|
||||
{
|
||||
if ( ! $this->has(Query\Delete::class) ) {
|
||||
$delete = new Query\Delete();
|
||||
|
||||
$delete->alias = $alias;
|
||||
$this->push($delete);
|
||||
$this->push(new Query\Delete());
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -45,8 +83,6 @@ class QueryBuilder
|
||||
|
||||
public function from(string $table, ? string $alias = null, ? string $database = null, ? string $schema = null) : self
|
||||
{
|
||||
// $table = "\"$table\"";
|
||||
|
||||
if ( $database ) {
|
||||
$table = "\"$database\".$table";
|
||||
}
|
||||
@@ -61,6 +97,7 @@ class QueryBuilder
|
||||
else {
|
||||
$from = new Query\From($this);
|
||||
$this->push($from);
|
||||
|
||||
$from->set($alias ? [ $alias => $table ] : $table);
|
||||
}
|
||||
|
||||
@@ -98,6 +135,7 @@ class QueryBuilder
|
||||
|
||||
$this->conditionOperator = $operator;
|
||||
$where->add($field, $value, $operator, $condition, $not);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -181,7 +219,8 @@ class QueryBuilder
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
public function addParameter($value, $key = null) {
|
||||
public function addParameter($value, string $key = null) : string
|
||||
{
|
||||
if ( $key === null ) {
|
||||
$key = ":p" . $this->parameterIndex++;
|
||||
}
|
||||
@@ -189,4 +228,8 @@ class QueryBuilder
|
||||
$this->parameters[$key] = $value;
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function addValues(array $values) {
|
||||
$this->values = $values;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user