diff --git a/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LSqlDatabaseMetaData.java b/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LSqlDatabaseMetaData.java index d46302e..b8a73f3 100644 --- a/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LSqlDatabaseMetaData.java +++ b/com.dbeaver.jdbc.driver.libsql/src/main/java/com/dbeaver/jdbc/driver/libsql/LSqlDatabaseMetaData.java @@ -23,10 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; +import java.sql.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -116,4 +113,16 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam } } + @Override + public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { + String tableName = tableNamePattern; + 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(); + } + } } diff --git a/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LSqlDriverTest.java b/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LSqlDriverTest.java index 309e6f5..558c60c 100644 --- a/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LSqlDriverTest.java +++ b/com.dbeaver.jdbc.driver.libsql/src/test/java/com/dbeaver/jdbc/upd/driver/test/LSqlDriverTest.java @@ -39,12 +39,23 @@ public static void main(String[] args) throws Exception { printResultSet(dbResult); } } + try (Statement dbStat = connection.createStatement()) { + try (ResultSet dbResult = dbStat.executeQuery("select * from PRAGMA_TABLE_INFO('testme')")) { + printResultSet(dbResult); + } + } System.out.println("Tables:"); try (ResultSet tables = metaData.getTables(null, null, null, null)) { while (tables.next()) { String tableName = tables.getString("TABLE_NAME"); System.out.println("\t- " + tableName); + try (ResultSet columns = metaData.getColumns(null, null, tableName, null)) { + while (columns.next()) { + System.out.println("\t\t- " + columns.getString("COLUMN_NAME") + " " + columns.getString("TYPE_NAME")); + } + } + } }