代码之家  ›  专栏  ›  技术社区  ›  Frank V

sqlitejdbc和preparedStatement使用pragma table_info

  •  4
  • Frank V  · 技术社区  · 15 年前

    我正在使用Java和 SQLiteJDBC 使用sqlite。我需要访问给定表的列的名称,并且我发现可以通过以下命令完成此操作:

    pragma table_info(myTable)
    

    但是,当尝试执行以下操作时,我会得到一个错误。

    PreparedStatement _pstmt =
        this._DBConnection.prepareStatement("pragma table_info( '?' );",
             new String[] {_tableName} );
    

    java.sql.sqlException:nyi

    我不知道NYI是什么意思,而且,我不确定我是否能做我想做的。关于如何获取列名有什么建议吗?

    2 回复  |  直到 12 年前
        1
  •  3
  •   Bill Karwin    15 年前

    NYI的意思是“尚未实施”。

    我想“pragma table_info”命令可能不能作为准备好的语句直接执行。

    在sqliteJDBC驱动程序类的代码中有一个执行pragma语句的示例 org.sqlite.Metadata ,方法如 getColumns() getPrimaryKeys() .

    我不能摘录代码并将其发布在这里,因为这样做与StackOverflow使用的Creative Commons许可证不兼容。所以请去那个链接看看。

        2
  •  2
  •   Mark Rushakoff    15 年前

    这是从 SQLiteJDBC source code :

     public PreparedStatement prepareStatement(String sql, int autoC)
            throws SQLException { throw new SQLException("NYI"); }
        public PreparedStatement prepareStatement(String sql, int[] colInds)
            throws SQLException { throw new SQLException("NYI"); }
        public PreparedStatement prepareStatement(String sql, String[] colNames)
            throws SQLException { throw new SQLException("NYI"); }
        public PreparedStatement prepareStatement(String sql, int rst, int rsc) 
                                    throws SQLException {
            return prepareStatement(sql, rst, rsc,
                                    ResultSet.CLOSE_CURSORS_AT_COMMIT);
        }
    

    我猜nyi的意思是“还没有实现”。

    如果pragma的问题没有解决,

    sqlite> CREATE TABLE a(col1, col2, col3);
    sqlite> CREATE TABLE b(w, x, y, z);
    sqlite> SELECT * FROM sqlite_master;
    table|a|a|2|CREATE TABLE a(col1, col2, col3)
    table|b|b|3|CREATE TABLE b(w, x, y, z)
    
    sqlite> SELECT sql FROM sqlite_master;
    CREATE TABLE a(col1, col2, col3)
    CREATE TABLE b(w, x, y, z)
    

    您可以从 sqlite_master 表并自己分析它们。