method getColumns documentation in bbn\Db\Languages\Sqlite
Returns the columns' configuration of the given table.
function(string $table)
{
if (!$this->check()) {
return null;
}
$r = [];
if ($table = $this->tableFullName($table)) {
$p = 1;
if ($rows = $this->getRows("PRAGMA table_info($table)")) {
foreach ($rows as $row){
$f = $row['name'];
$r[$f] = [
'position' => $p++,
'null' => $row['notnull'] == 0 ? 1 : 0,
'key' => $row['pk'] == 1 ? 'PRI' : null,
'default' => is_string($row['dflt_value'])
? rtrim(
ltrim($row['dflt_value'], "'"),
"'"
)
: $row['dflt_value'],
// INTEGER PRIMARY KEY is a ROWID
// https://www.sqlite.org/autoinc.html
'extra' => $row['type'] === 'INTEGER' && $row['pk'] == 1 ? 'auto_increment' : null,
'maxlength' => null,
'signed' => 1
];
if ($row['dflt_value'] !== '') {
$r[$f]['defaultExpression'] = false;
}
if (in_array($row['dflt_value'], ['CURRENT_TIME', 'CURRENT_DATE', 'CURRENT_TIMESTAMP'], true)) {
$r[$f]['defaultExpression'] = true;
}
$type = strtolower($row['type']);
if (strpos($type, 'blob') !== false) {
$r[$f]['type'] = 'BLOB';
}
elseif (( strpos($type, 'int') !== false ) || ( strpos($type, 'bool') !== false ) || ( strpos($type, 'timestamp') !== false )) {
$r[$f]['type'] = 'INTEGER';
if (strpos($type, 'unsigned') !== false) {
$r[$f]['signed'] = 0;
}
}
elseif (( strpos($type, 'floa') !== false ) || ( strpos($type, 'doub') !== false ) || ( strpos($type, 'real') !== false )) {
$r[$f]['type'] = 'REAL';
if (strpos($type, 'unsigned') !== false) {
$r[$f]['signed'] = 0;
}
}
elseif (( strpos($type, 'char') !== false ) || ( strpos($type, 'text') !== false )) {
$r[$f]['type'] = 'TEXT';
}
if (preg_match_all('/\((.*?)\)/', $row['type'], $matches)) {
$r[$f]['maxlength'] = (int)$matches[1][0];
}
if (!isset($r[$f]['type'])) {
$r[$f]['type'] = 'TEXT';
}
}
}
}
return $r;
}
Returns the columns' configuration of the given table. 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.
© 2011-2023
BBN Solutions