Skip to content

Commit

Permalink
dbeaver/dbeaver#23361 Columns for all tables read
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Nov 1, 2024
1 parent a2f30b8 commit 858cb2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,22 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
@Override
public ResultSet getColumns(String catalog, String schemaPattern, String tableName, String columnNamePattern) throws SQLException {
verifySchemaParameters(catalog, schemaPattern);
try (PreparedStatement dbStat = connection.prepareStatement(
"SELECT NULL as TABLE_CAT, NULL AS TABLE_SCHEM,'" + tableName + "' AS TABLE_NAME," +
"name as COLUMN_NAME," + Types.VARCHAR + " AS DATA_TYPE, type AS TYPE_NAME, 0 AS COLUMN_SIZE," +
"NULL AS REMARKS,cid AS ORDINAL_POSITION " +
"FROM PRAGMA_TABLE_INFO('" + tableName + "')")
) {
return dbStat.executeQuery();
if (CommonUtils.isEmpty(tableName) || "%".equals(tableName)) {
tableName = null;
}
return executeQuery(
"WITH all_tables AS (SELECT name AS tn FROM sqlite_master WHERE type = 'table'" +
(tableName == null ? "" : " and name=" + LibSqlUtils.escape(tableName)) + ") \n" +
"SELECT NULL as TABLE_CAT, NULL AS TABLE_SCHEM, at.tn as TABLE_NAME,\n" +
"pti.name as COLUMN_NAME," + Types.VARCHAR + " AS DATA_TYPE, pti.type AS TYPE_NAME, 0 AS COLUMN_SIZE," +
"NULL AS REMARKS,pti.cid AS ORDINAL_POSITION " +
"FROM all_tables at INNER JOIN pragma_table_info(at.tn) pti\n" +
"ORDER BY TABLE_NAME");
}

@Override
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
public ResultSet getPrimaryKeys(String catalog, String schema, String tableName) throws SQLException {
String table = tableName;
PrimaryKeyFinder pkFinder = new PrimaryKeyFinder(connection, table);
String[] columns = pkFinder.getColumns();

Expand All @@ -141,12 +145,9 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
for (int i = 0; i < columns.length; i++) {
if (i > 0) sql.append(" union ");
sql.append("select ")
.append(pkName)
.append(" as pk, '")
.append(LibSqlUtils.escape(LibSqlUtils.unquote(columns[i])))
.append("' as cn, ")
.append(i + 1)
.append(" as ks");
.append(pkName).append(" as pk, '")
.append(LibSqlUtils.escape(LibSqlUtils.unquote(columns[i]))).append("' as cn, ")
.append(i + 1).append(" as ks");
}

sql.append(") order by cn;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public LibSqlExecutionResult[] executeBatch(
try {
HttpURLConnection conn = openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent",
LibSqlConstants.DRIVER_INFO + " " +
LibSqlConstants.DRIVER_VERSION_MAJOR + "." + LibSqlConstants.DRIVER_VERSION_MINOR);
conn.setDoOutput(true);

try (OutputStream os = conn.getOutputStream()) {
Expand Down

0 comments on commit 858cb2c

Please sign in to comment.