web-base/Core/Driver/SQL/Query/CreateProcedure.class.php

51 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2021-04-08 18:29:47 +02:00
<?php
2022-11-18 18:06:46 +01:00
namespace Core\Driver\SQL\Query;
2021-04-08 18:29:47 +02:00
2022-11-18 18:06:46 +01:00
use Core\Driver\SQL\Column\Column;
2023-01-09 15:59:53 +01:00
use Core\Driver\SQL\Expression\Expression;
2022-11-18 18:06:46 +01:00
use Core\Driver\SQL\SQL;
2021-04-08 18:29:47 +02:00
class CreateProcedure extends Query {
private string $name;
private array $parameters;
private array $statements;
private $returns;
public function __construct(SQL $sql, string $procName) {
parent::__construct($sql);
$this->name = $procName;
$this->parameters = [];
$this->statements = [];
$this->returns = NULL;
}
2023-01-09 15:59:53 +01:00
public function param(Expression $parameter): CreateProcedure {
2021-04-08 18:29:47 +02:00
$this->parameters[] = $parameter;
return $this;
}
public function returns($column): CreateProcedure {
$this->returns = $column;
return $this;
}
public function exec(array $statements): CreateProcedure {
$this->statements = $statements;
return $this;
}
2021-04-09 16:05:36 +02:00
public function build(array &$params): ?string {
2021-04-08 18:29:47 +02:00
$head = $this->sql->getProcedureHead($this);
$body = $this->sql->getProcedureBody($this);
$tail = $this->sql->getProcedureTail();
return "$head BEGIN $body END; $tail";
}
public function getName(): string { return $this->name; }
public function getParameters(): array { return $this->parameters; }
public function getReturns() { return $this->returns; }
public function getStatements(): array { return $this->statements; }
}