Skip to content

Commit 0b351fa

Browse files
authored
feat: adicionado funções para trazer informações da tabela
1 parent 8c21ab4 commit 0b351fa

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/Database/Schema/Grammar.php

+63
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,69 @@ public function compileAdd(Blueprint $blueprint, Fluent $command)
9393
return 'ALTER TABLE ' . $table . ' ADD ' . implode(', ', $columns);
9494
}
9595

96+
97+
/**
98+
* @param $table
99+
* @return string
100+
* Functions do compile the columns of a given table
101+
*/
102+
public function compileColumns($table)
103+
{
104+
return "SELECT
105+
col.name,
106+
type.name AS type_name,
107+
col.length AS length,
108+
col.prec AS precision,
109+
col.scale AS places,
110+
CASE WHEN (col.status & 0x08) = 0x08 THEN 'YES' ELSE 'NO' END AS nullable,
111+
def.text AS [default],
112+
CASE WHEN (col.status & 0x80) = 0x80 THEN 'YES' ELSE 'NO' END AS autoincrement,
113+
NULL AS collation, -- Sybase não fornece suporte direto para collation em colunas
114+
com.text AS comment -- Comentários associados à coluna, se existirem
115+
FROM
116+
sysobjects obj
117+
JOIN
118+
syscolumns col ON obj.id = col.id
119+
JOIN
120+
systypes type ON col.usertype = type.usertype
121+
LEFT JOIN
122+
syscomments def ON col.cdefault = def.id -- Valores padrão da coluna
123+
LEFT JOIN
124+
syscomments com ON col.colid = com.colid -- Comentários associados às colunas (se habilitados)
125+
WHERE
126+
obj.type IN ('U', 'V') -- 'U' para tabelas, 'V' para visões
127+
AND obj.name = '$table'
128+
AND user_name(obj.uid) = user_name()
129+
ORDER BY
130+
col.colid";
131+
}
132+
133+
/**
134+
* @param $table
135+
* @return string
136+
* Functions that return the indexes of a given table
137+
*/
138+
public function compileIndexes($table)
139+
{
140+
return "SELECT
141+
DISTINCT i.name,
142+
index_col(o.name, i.indid, c.colid) AS column_name,
143+
CASE WHEN i.status & 2048 = 2048 THEN 'YES' ELSE 'NO' END AS is_primary,
144+
CASE WHEN i.status & 2 = 2 THEN 'YES' ELSE 'NO' END AS is_unique
145+
FROM
146+
sysobjects o
147+
INNER JOIN sysindexes i ON i.id = o.id
148+
INNER JOIN syscolumns c ON c.id = o.id
149+
WHERE
150+
o.type = 'U' -- Apenas tabelas de usuário
151+
AND o.name = '$table' -- Nome da tabela alvo
152+
AND i.indid > 0 -- Índices não-triviais
153+
AND i.status & 2 = 2 -- Apenas índices do sistema (ajuste se necessário)
154+
AND index_col(o.name, i.indid, c.colid) IS NOT NULL -- Verifica colunas válidas associadas ao índice
155+
ORDER BY
156+
i.name, column_name";
157+
}
158+
96159
/**
97160
* Compile a primary key command.
98161
*

0 commit comments

Comments
 (0)