method getColumnDefinitionStatement documentation in bbn\Db\Languages\Pgsql

Returns a statement for column definition.

function(string $name, array $col, bool $include_col_name = true, bool $for_alter = false) { array $col, bool $include_col_name = true, bool $for_alter = false ): string { $st = ''; if ($include_col_name) { $st .= ' ' . $this->escape($name) . ' '; } if (empty($col['type'])) { throw new \Exception(X::_('Column type is not provided')); } $col_type = $col['type']; if (array_key_exists('default', $col) && strpos($col['default'], '::') !== FALSE) { [$col['default']] = explode('::', $col['default']); } if ($col_type === 'USER-DEFINED') { if (!empty($col['udt_name'])) { $col['type'] = $col['udt_name']; } else { $col['type'] = $name; } } if (!in_array($col_type, self::$types)) { if (isset(self::$interoperability[$col_type])) { $st .= self::$interoperability[$col_type]; $col_type = self::$interoperability[$col_type]; } else if ($col_type === 'USER-DEFINED') { $st .= $col['type']; } else { throw new \Exception(X::_("Impossible to recognize the column type")." $col[type]"); } } else { $st .= $col['type']; } if ( !empty($col['maxlength']) && $col_type !== 'bytea' && ( (in_array($col_type, self::$numeric_types) && in_array($col_type, self::$numeric_with_max_values)) || !in_array($col_type, self::$numeric_types) ) ) { $st .= '(' . $col['maxlength']; if (!empty($col['decimals'])) { $st .= ',' . $col['decimals']; } $st .= ')'; } if (empty($col['null'])) { if ($for_alter) { $st .= ',' . PHP_EOL; $st .= 'ALTER COLUMN ' . $this->escape($name); $st .= ' SET NOT NULL,' . PHP_EOL; } else { $st .= ' NOT NULL'; } } if (!empty($col['virtual'])) { $st .= ' GENERATED ALWAYS AS (' . $col['generation'] . ') VIRTUAL'; } elseif (array_key_exists('default', $col)) { if ($for_alter) { $st .= ',' . PHP_EOL; $st .= 'ALTER COLUMN ' . $this->escape($name); $st .= ' SET DEFAULT '; } else { $st .= ' DEFAULT '; } if (($col['default'] === 'NULL') || Str::isNumber($col['default']) || strpos($col['default'], '(') || in_array(strtoupper($col['default']), ['CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP']) ) { $st .= (string)$col['default']; } else { $st .= "'" . trim($col['default'], "'") . "'"; } } return rtrim($st, ',' . PHP_EOL); }

Returns a statement for column definition. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.