1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\System\Db;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2019, Afterlogic Corp.
14: *
15: * @package Api
16: * @subpackage Db
17: */
18: class Field
19: {
20: public const AUTO_INT = 10;
21: public const AUTO_INT_BIG = 11;
22: public const AUTO_INT_UNSIGNED = 12;
23: public const AUTO_INT_BIG_UNSIGNED = 13;
24:
25: public const BIT = 20;
26: public const INT = 21;
27: public const INT_SHORT = 22;
28: public const INT_SMALL = 23;
29: public const INT_BIG = 24;
30: public const INT_UNSIGNED = 25;
31: public const INT_SHORT_SMALL = 26;
32: public const INT_BIG_UNSIGNED = 27;
33:
34: public const CHAR = 31;
35: public const VAR_CHAR = 32;
36: public const TEXT = 33;
37: public const TEXT_MEDIUM = 37;
38: public const TEXT_LONG = 34;
39: public const BLOB = 35;
40: public const BLOB_LONG = 36;
41:
42: public const DATETIME = 40;
43:
44: /**
45: * @var string
46: */
47: protected $sName;
48:
49: /**
50: * @var int
51: */
52: protected $iType;
53:
54: /**
55: * @var mixed
56: */
57: protected $mDefault;
58:
59: /**
60: * @var int
61: */
62: protected $iCustomLen;
63:
64: /**
65: * @var bool
66: */
67: protected $bNotNullWithOutDefault;
68:
69: /**
70: * @param string $sName
71: * @param int $iType
72: * @param mixed $mDefault = null
73: * @param int $iCustomLen = null
74: * @param bool $bNotNullWithOutDefault = false
75: */
76: public function __construct($sName, $iType, $mDefault = null, $iCustomLen = null, $bNotNullWithOutDefault = false)
77: {
78: $this->sName = $sName;
79: $this->iType = $iType;
80: $this->mDefault = $mDefault;
81: $this->iCustomLen = $iCustomLen;
82: $this->bNotNullWithOutDefault = $bNotNullWithOutDefault;
83: }
84:
85: /**
86: * @return string
87: */
88: public function Name()
89: {
90: return $this->sName;
91: }
92:
93: /**
94: * @param string $sTableName
95: * @param IDbHelper $oHelper
96: * @return string
97: */
98: public function ToAlterString($sTableName, $oHelper)
99: {
100: return sprintf(
101: 'ALTER TABLE %s ADD %s',
102: $oHelper->EscapeColumn($sTableName),
103: $this->ToString($oHelper)
104: );
105: }
106:
107: /**
108: * @return string
109: */
110: public function ToString($oHelper)
111: {
112: return $oHelper->FieldToString($this->sName, $this->iType, $this->mDefault, $this->iCustomLen, $this->bNotNullWithOutDefault);
113: }
114: }
115: