packages/ztd-query-core/src/Exception/ColumnAlreadyExistsException.php
1<?php
2
3declare(strict_types=1);
4
5namespace ZtdQuery\Exception;
6
7/**
8 * Exception thrown when attempting to add a column that already exists.
9 */
10final class ColumnAlreadyExistsException extends SimulationException
11{
12 /**
13 * The SQL statement that attempted to add the column.
14 */
15 private string $sql;
16
17 /**
18 * The name of the table.
19 */
20 private string $tableName;
21
22 /**
23 * The name of the column that already exists.
24 */
25 private string $columnName;
26
27 /**
28 * @param string $sql The SQL statement.
29 * @param string $tableName The name of the table.
30 * @param string $columnName The name of the column that already exists.
31 */
32 public function __construct(string $sql, string $tableName, string $columnName)
33 {
34 parent::__construct(sprintf("Column '%s' already exists in table '%s'.", $columnName, $tableName));
35 $this->sql = $sql;
36 $this->tableName = $tableName;
37 $this->columnName = $columnName;
38 }
39
40 /**
41 * Get the SQL statement.
42 */
43 public function getSql(): string
44 {
45 return $this->sql;
46 }
47
48 /**
49 * Get the name of the table.
50 */
51 public function getTableName(): string
52 {
53 return $this->tableName;
54 }
55
56 /**
57 * Get the name of the column that already exists.
58 */
59 public function getColumnName(): string
60 {
61 return $this->columnName;
62 }
63}
64