- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当与 hibernate 的“hbm2ddl.auto = update”设置一起使用时,SQLiteJDBC 给我以下异常:
org.sqlite.MetaData.getImportedKeys not yet implemented
有什么解决办法吗?我在下面找到了一个,并将其张贴在这里以供将来引用,但还有其他人有更好的想法吗?
最佳答案
通过一些浏览,我发现有人为它做了一个补丁,它是在这里可见:http://www.sqlpower.ca/forum/posts/list/2258.page
我已将此补丁应用于最新版本的 MetaData.javagithub,并将其重新编译为 .class 文件并使用 7-zip 将其复制到 .jar 中,现在它可以很好地与 Hibernate 配合使用。
这是更新后的 java 文件:http://snipt.org/NnH
这是 MetaData.java 文件的前半部分(分成两半,因为它太大了):
/*
* Copyright (c) 2007 David Crawshaw <david@zentus.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package org.sqlite;
import java.sql.*;
import java.util.Hashtable;
class MetaData implements DatabaseMetaData
{
private static String sqlQuote(String str) {
if (str == null) {
return "NULL";
}
int i, single = 0, dbl = 0;
for (i = 0; i < str.length(); i++) {
if (str.charAt(i) == '\'') {
single++;
} else if (str.charAt(i) == '"') {
dbl++;
}
}
if (single == 0) {
return "'" + str + "'";
}
if (dbl == 0) {
return "\"" + str + "\"";
}
StringBuffer sb = new StringBuffer("'");
for (i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c == '\'') {
sb.append("''");
} else {
sb.append(c);
}
}
return sb.toString();
}
private Conn conn;
private PreparedStatement
getTables = null,
getTableTypes = null,
getTypeInfo = null,
getCatalogs = null,
getSchemas = null,
getUDTs = null,
getColumnsTblName = null,
getSuperTypes = null,
getSuperTables = null,
getTablePrivileges = null,
getExportedKeys = null,
getProcedures = null,
getProcedureColumns = null,
getAttributes = null,
getBestRowIdentifier = null,
getVersionColumns = null,
getColumnPrivileges = null,
getIndexInfo = null;
/** Used by PrepStmt to save generating a new statement every call. */
private PreparedStatement getGeneratedKeys = null;
MetaData(Conn conn) { this.conn = conn; }
void checkOpen() throws SQLException {
if (conn == null) throw new SQLException("connection closed"); }
synchronized void close() throws SQLException {
if (conn == null) return;
try {
if (getTables != null) getTables.close();
if (getTableTypes != null) getTableTypes.close();
if (getTypeInfo != null) getTypeInfo.close();
if (getCatalogs != null) getCatalogs.close();
if (getSchemas != null) getSchemas.close();
if (getUDTs != null) getUDTs.close();
if (getColumnsTblName != null) getColumnsTblName.close();
if (getSuperTypes != null) getSuperTypes.close();
if (getSuperTables != null) getSuperTables.close();
if (getTablePrivileges != null) getTablePrivileges.close();
if (getExportedKeys != null) getExportedKeys.close();
if (getProcedures != null) getProcedures.close();
if (getProcedureColumns != null) getProcedureColumns.close();
if (getAttributes != null) getAttributes.close();
if (getBestRowIdentifier != null) getBestRowIdentifier.close();
if (getVersionColumns != null) getVersionColumns.close();
if (getColumnPrivileges != null) getColumnPrivileges.close();
if (getGeneratedKeys != null) getGeneratedKeys.close();
getTables = null;
getTableTypes = null;
getTypeInfo = null;
getCatalogs = null;
getSchemas = null;
getUDTs = null;
getColumnsTblName = null;
getSuperTypes = null;
getSuperTables = null;
getTablePrivileges = null;
getExportedKeys = null;
getProcedures = null;
getProcedureColumns = null;
getAttributes = null;
getBestRowIdentifier = null;
getVersionColumns = null;
getColumnPrivileges = null;
getGeneratedKeys = null;
} finally {
conn = null;
}
}
public Connection getConnection() { return conn; }
public int getDatabaseMajorVersion() { return 3; }
public int getDatabaseMinorVersion() { return 0; }
public int getDriverMajorVersion() { return 1; }
public int getDriverMinorVersion() { return 1; }
public int getJDBCMajorVersion() { return 2; }
public int getJDBCMinorVersion() { return 1; }
public int getDefaultTransactionIsolation()
{ return Connection.TRANSACTION_SERIALIZABLE; }
public int getMaxBinaryLiteralLength() { return 0; }
public int getMaxCatalogNameLength() { return 0; }
public int getMaxCharLiteralLength() { return 0; }
public int getMaxColumnNameLength() { return 0; }
public int getMaxColumnsInGroupBy() { return 0; }
public int getMaxColumnsInIndex() { return 0; }
public int getMaxColumnsInOrderBy() { return 0; }
public int getMaxColumnsInSelect() { return 0; }
public int getMaxColumnsInTable() { return 0; }
public int getMaxConnections() { return 0; }
public int getMaxCursorNameLength() { return 0; }
public int getMaxIndexLength() { return 0; }
public int getMaxProcedureNameLength() { return 0; }
public int getMaxRowSize() { return 0; }
public int getMaxSchemaNameLength() { return 0; }
public int getMaxStatementLength() { return 0; }
public int getMaxStatements() { return 0; }
public int getMaxTableNameLength() { return 0; }
public int getMaxTablesInSelect() { return 0; }
public int getMaxUserNameLength() { return 0; }
public int getResultSetHoldability()
{ return ResultSet.CLOSE_CURSORS_AT_COMMIT; }
public int getSQLStateType() { return sqlStateSQL99; }
public String getDatabaseProductName() { return "SQLite"; }
public String getDatabaseProductVersion() throws SQLException {
return conn.libversion();
}
public String getDriverName() { return "SQLiteJDBC"; }
public String getDriverVersion() { return conn.getDriverVersion(); }
public String getExtraNameCharacters() { return ""; }
public String getCatalogSeparator() { return "."; }
public String getCatalogTerm() { return "catalog"; }
public String getSchemaTerm() { return "schema"; }
public String getProcedureTerm() { return "not_implemented"; }
public String getSearchStringEscape() { return null; }
public String getIdentifierQuoteString() { return " "; }
public String getSQLKeywords() { return ""; }
public String getNumericFunctions() { return ""; }
public String getStringFunctions() { return ""; }
public String getSystemFunctions() { return ""; }
public String getTimeDateFunctions() { return ""; }
public String getURL() { return conn.url(); }
public String getUserName() { return null; }
public boolean allProceduresAreCallable() { return false; }
public boolean allTablesAreSelectable() { return true; }
public boolean dataDefinitionCausesTransactionCommit() { return false; }
public boolean dataDefinitionIgnoredInTransactions() { return false; }
public boolean doesMaxRowSizeIncludeBlobs() { return false; }
public boolean deletesAreDetected(int type) { return false; }
public boolean insertsAreDetected(int type) { return false; }
public boolean isCatalogAtStart() { return true; }
public boolean locatorsUpdateCopy() { return false; }
public boolean nullPlusNonNullIsNull() { return true; }
public boolean nullsAreSortedAtEnd() { return !nullsAreSortedAtStart(); }
public boolean nullsAreSortedAtStart() { return true; }
public boolean nullsAreSortedHigh() { return true; }
public boolean nullsAreSortedLow() { return !nullsAreSortedHigh(); }
public boolean othersDeletesAreVisible(int type) { return false; }
public boolean othersInsertsAreVisible(int type) { return false; }
public boolean othersUpdatesAreVisible(int type) { return false; }
public boolean ownDeletesAreVisible(int type) { return false; }
public boolean ownInsertsAreVisible(int type) { return false; }
public boolean ownUpdatesAreVisible(int type) { return false; }
public boolean storesLowerCaseIdentifiers() { return false; }
public boolean storesLowerCaseQuotedIdentifiers() { return false; }
public boolean storesMixedCaseIdentifiers() { return true; }
public boolean storesMixedCaseQuotedIdentifiers() { return false; }
public boolean storesUpperCaseIdentifiers() { return false; }
public boolean storesUpperCaseQuotedIdentifiers() { return false; }
public boolean supportsAlterTableWithAddColumn() { return false; }
public boolean supportsAlterTableWithDropColumn() { return false; }
public boolean supportsANSI92EntryLevelSQL() { return false; }
public boolean supportsANSI92FullSQL() { return false; }
public boolean supportsANSI92IntermediateSQL() { return false; }
public boolean supportsBatchUpdates() { return true; }
public boolean supportsCatalogsInDataManipulation() { return false; }
public boolean supportsCatalogsInIndexDefinitions() { return false; }
public boolean supportsCatalogsInPrivilegeDefinitions() { return false; }
public boolean supportsCatalogsInProcedureCalls() { return false; }
public boolean supportsCatalogsInTableDefinitions() { return false; }
public boolean supportsColumnAliasing() { return true; }
public boolean supportsConvert() { return false; }
public boolean supportsConvert(int fromType, int toType) { return false; }
public boolean supportsCorrelatedSubqueries() { return false; }
public boolean supportsDataDefinitionAndDataManipulationTransactions()
{ return true; }
public boolean supportsDataManipulationTransactionsOnly() { return false; }
public boolean supportsDifferentTableCorrelationNames() { return false; }
public boolean supportsExpressionsInOrderBy() { return true; }
public boolean supportsMinimumSQLGrammar() { return true; }
public boolean supportsCoreSQLGrammar() { return true; }
public boolean supportsExtendedSQLGrammar() { return false; }
public boolean supportsLimitedOuterJoins() { return true; }
public boolean supportsFullOuterJoins() { return false; }
public boolean supportsGetGeneratedKeys() { return false; }
public boolean supportsGroupBy() { return true; }
public boolean supportsGroupByBeyondSelect() { return false; }
public boolean supportsGroupByUnrelated() { return false; }
public boolean supportsIntegrityEnhancementFacility() { return false; }
public boolean supportsLikeEscapeClause() { return false; }
public boolean supportsMixedCaseIdentifiers() { return true; }
public boolean supportsMixedCaseQuotedIdentifiers() { return false; }
public boolean supportsMultipleOpenResults() { return false; }
public boolean supportsMultipleResultSets() { return false; }
public boolean supportsMultipleTransactions() { return true; }
public boolean supportsNamedParameters() { return true; }
public boolean supportsNonNullableColumns() { return true; }
public boolean supportsOpenCursorsAcrossCommit() { return false; }
public boolean supportsOpenCursorsAcrossRollback() { return false; }
public boolean supportsOpenStatementsAcrossCommit() { return false; }
public boolean supportsOpenStatementsAcrossRollback() { return false; }
public boolean supportsOrderByUnrelated() { return false; }
public boolean supportsOuterJoins() { return true; }
public boolean supportsPositionedDelete() { return false; }
public boolean supportsPositionedUpdate() { return false; }
public boolean supportsResultSetConcurrency(int t, int c)
{ return t == ResultSet.TYPE_FORWARD_ONLY
&& c == ResultSet.CONCUR_READ_ONLY; }
public boolean supportsResultSetHoldability(int h)
{ return h == ResultSet.CLOSE_CURSORS_AT_COMMIT; }
public boolean supportsResultSetType(int t)
{ return t == ResultSet.TYPE_FORWARD_ONLY; }
public boolean supportsSavepoints() { return false; }
public boolean supportsSchemasInDataManipulation() { return false; }
public boolean supportsSchemasInIndexDefinitions() { return false; }
public boolean supportsSchemasInPrivilegeDefinitions() { return false; }
public boolean supportsSchemasInProcedureCalls() { return false; }
public boolean supportsSchemasInTableDefinitions() { return false; }
public boolean supportsSelectForUpdate() { return false; }
public boolean supportsStatementPooling() { return false; }
public boolean supportsStoredProcedures() { return false; }
public boolean supportsSubqueriesInComparisons() { return false; }
public boolean supportsSubqueriesInExists() { return true; } // TODO: check
public boolean supportsSubqueriesInIns() { return true; } // TODO: check
public boolean supportsSubqueriesInQuantifieds() { return false; }
public boolean supportsTableCorrelationNames() { return false; }
public boolean supportsTransactionIsolationLevel(int level)
{ return level == Connection.TRANSACTION_SERIALIZABLE; }
public boolean supportsTransactions() { return true; }
public boolean supportsUnion() { return true; }
public boolean supportsUnionAll() { return true; }
public boolean updatesAreDetected(int type) { return false; }
public boolean usesLocalFilePerTable() { return false; }
public boolean usesLocalFiles() { return true; }
public boolean isReadOnly() throws SQLException
{ return conn.isReadOnly(); }
public ResultSet getAttributes(String c, String s, String t, String a)
throws SQLException {
if (getAttributes == null) getAttributes = conn.prepareStatement(
"select "
+ "null as TYPE_CAT, "
+ "null as TYPE_SCHEM, "
+ "null as TYPE_NAME, "
+ "null as ATTR_NAME, "
+ "null as DATA_TYPE, "
+ "null as ATTR_TYPE_NAME, "
+ "null as ATTR_SIZE, "
+ "null as DECIMAL_DIGITS, "
+ "null as NUM_PREC_RADIX, "
+ "null as NULLABLE, "
+ "null as REMARKS, "
+ "null as ATTR_DEF, "
+ "null as SQL_DATA_TYPE, "
+ "null as SQL_DATETIME_SUB, "
+ "null as CHAR_OCTET_LENGTH, "
+ "null as ORDINAL_POSITION, "
+ "null as IS_NULLABLE, "
+ "null as SCOPE_CATALOG, "
+ "null as SCOPE_SCHEMA, "
+ "null as SCOPE_TABLE, "
+ "null as SOURCE_DATA_TYPE limit 0;");
return getAttributes.executeQuery();
}
public ResultSet getBestRowIdentifier(String c, String s, String t,
int scope, boolean n) throws SQLException {
if (getBestRowIdentifier == null)
getBestRowIdentifier = conn.prepareStatement(
"select "
+ "null as SCOPE, "
+ "null as COLUMN_NAME, "
+ "null as DATA_TYPE, "
+ "null as TYPE_NAME, "
+ "null as COLUMN_SIZE, "
+ "null as BUFFER_LENGTH, "
+ "null as DECIMAL_DIGITS, "
+ "null as PSEUDO_COLUMN limit 0;");
return getBestRowIdentifier.executeQuery();
}
public ResultSet getColumnPrivileges(String c, String s, String t,
String colPat)
throws SQLException {
if (getColumnPrivileges == null)
getColumnPrivileges = conn.prepareStatement(
"select "
+ "null as TABLE_CAT, "
+ "null as TABLE_SCHEM, "
+ "null as TABLE_NAME, "
+ "null as COLUMN_NAME, "
+ "null as GRANTOR, "
+ "null as GRANTEE, "
+ "null as PRIVILEGE, "
+ "null as IS_GRANTABLE limit 0;");
return getColumnPrivileges.executeQuery();
}
public ResultSet getColumns(String c, String s, String tbl, String colPat)
throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs;
String sql;
checkOpen();
if (getColumnsTblName == null)
getColumnsTblName = conn.prepareStatement(
"select tbl_name from sqlite_master where tbl_name like ?;");
// determine exact table name
getColumnsTblName.setString(1, tbl);
rs = getColumnsTblName.executeQuery();
if (!rs.next())
return rs;
tbl = rs.getString(1);
rs.close();
sql = "select "
+ "null as TABLE_CAT, "
+ "null as TABLE_SCHEM, "
+ "'" + escape(tbl) + "' as TABLE_NAME, "
+ "cn as COLUMN_NAME, "
+ "ct as DATA_TYPE, "
+ "tn as TYPE_NAME, "
+ "2000000000 as COLUMN_SIZE, "
+ "2000000000 as BUFFER_LENGTH, "
+ "10 as DECIMAL_DIGITS, "
+ "10 as NUM_PREC_RADIX, "
+ "colnullable as NULLABLE, "
+ "null as REMARKS, "
+ "null as COLUMN_DEF, "
+ "0 as SQL_DATA_TYPE, "
+ "0 as SQL_DATETIME_SUB, "
+ "2000000000 as CHAR_OCTET_LENGTH, "
+ "ordpos as ORDINAL_POSITION, "
+ "(case colnullable when 0 then 'N' when 1 then 'Y' else '' end)"
+ " as IS_NULLABLE, "
+ "null as SCOPE_CATLOG, "
+ "null as SCOPE_SCHEMA, "
+ "null as SCOPE_TABLE, "
+ "null as SOURCE_DATA_TYPE from (";
// the command "pragma table_info('tablename')" does not embed
// like a normal select statement so we must extract the information
// and then build a resultset from unioned select statements
rs = stat.executeQuery("pragma table_info ('"+escape(tbl)+"');");
boolean colFound = false;
for (int i=0; rs.next(); i++) {
String colName = rs.getString(2);
String colType = rs.getString(3);
String colNotNull = rs.getString(4);
int colNullable = 2;
if (colNotNull != null) colNullable = colNotNull.equals("0") ? 1:0;
if (colFound) sql += " union all ";
colFound = true;
colType = colType == null ? "TEXT" : colType.toUpperCase();
int colJavaType = -1;
if (colType == "INT" || colType == "INTEGER")
colJavaType = Types.INTEGER;
else if (colType == "TEXT")
colJavaType = Types.VARCHAR;
else if (colType == "FLOAT")
colJavaType = Types.FLOAT;
else
colJavaType = Types.VARCHAR;
sql += "select "
+ i + " as ordpos, "
+ colNullable + " as colnullable, '"
+ colJavaType + "' as ct, '"
+ escape(colName) + "' as cn, '"
+ escape(colType) + "' as tn";
if (colPat != null)
sql += " where upper(cn) like upper('" + escape(colPat) + "')";
}
sql += colFound ? ");" :
"select null as ordpos, null as colnullable, "
+ "null as cn, null as tn) limit 0;";
rs.close();
return stat.executeQuery(sql);
}
数据
关于java - SQLiteJDBC 给 org.sqlite.MetaData.getImportedKeys not yet implemented error with Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2861900/
我正在开发一个 SQLite 数据库。数据库已经填满了,但我想重构它。这是我需要做的一个示例: 我目前有一张 table : CREATE TABLE Cars (ID INTEGER PRIMARY
我正在使用 Mono、SQLite、Dapper 和 Dapper 扩展。我可以从数据库中读取数据,但插入不起作用。我正在使用 sqlite 的 Mono 驱动程序。 错误并不能提供太多信息,至少对我
我有一个使用 SQLite 的 Windows Phone 8 应用程序。该应用程序具有许多数据库功能,并包含一个 sqlite 数据库文件,在运行该应用程序时,该文件将被复制到本地文件夹并进行访问。
为 sqlite 创建索引时有排序顺序。 https://sqlite.org/lang_createindex.html Each column name or expression can be
顾名思义,我怀疑如果有一些引用被删除的表会发生什么,例如表的某些字段的索引。 SQLite是否会自动处理?在执行drop命令之前,数据库所有者是否应注意任何实例? 最佳答案 我认为不需要家政服务。 S
我想知道是否有可能将从计数中获得的整数转换为REAL 类似于以下内容(尽管这不起作用) SELECT CAST (COUNT (ColumnA) AS Count) AS REAL) FROM Tab
我无法在SQLite数据库上执行一些更新。我正在Windows上使用SQLite 3 Shell。 我正在运行以下命令: update resovled_chrom_counts set genus
我知道SQLite中的触发器顺序是不确定的(您不能确定将首先执行哪个触发器),但是表约束和触发器之间的关系又如何呢? 我的意思是,假设我在一个列中有一个UNIQUE(或CHECK)约束,并且在该表上有
我的 CustomTags 表可能有一系列“临时”记录,其中 Tag_ID 为 0,并且 Tag_Number 将有一些五位数的值。 定期,我想清理我的 Sqlite 表以删除这些临时值。 例如,我可
我有A,B,C和D的记录。 我的SQL1 SELECT * FROM main_table order by main_table.date desc limit 2返回A和B。 我的SQL2 SEL
select round(836.0)返回836.0 我如何删除sqlite查询中的尾随零。 836.00应该是836 836.440应该是836.44 最佳答案 如果需要836.44,则需要十进制返
我正在研究RQDA中的文本,并且正在使用Firefox SQLite Manager访问数据库,以便可以更轻松地搜索文件。我创建并填充了虚拟表: CREATE VIRTUAL TABLE texts
我有这样的数据: table1 id | part | price 1 | ox900 | 100 2 | ox980 | 200 和 table2 id | part | price 1
我正在尝试将一些数据插入现有的SQLite表中。该表和数据库是使用相同的API创建的,但是由于某种原因,插入操作无效,并且从不给我任何错误消息。 我正在BlackBerry 9550模拟器上对此进行测
例如,我在名为SALARY的列中插入一个值。如果插入的值大于1000,我想将字符串HIGH插入到RANK列中,否则将插入LOW中。 我可以使用SQLite做到吗? 最佳答案 在插入之前使用触发器,然后
假设我有一个包含三列A,B,C的表t1,其中(A,B)包含唯一键(具有数十万行)。由于90%的查询将采用SELECT C FROM t1 WHERE A =?和B = ?,我想我要为A,B和C提供覆盖
在一个SQLite3数据库中,我有一个表“ projects”,其id字段由以下方式组成: [user id]_[user's project id] 例如,用户ID = 45,这是一些数据: 45_
我了解PRAGMA foreign_key和ON DELETE RESTRICT/NO ACTION的概念,但是我面临的是另一种情况。 我需要删除一个父行,但保持与之关联的子行。例如: CREATE
我的c#应用程序从Web服务1读取文件列表,并将完整的文件名插入table1,然后从第二个Web服务读取list并将它们插入到table2。 这些表具有相同的结构,如下所示: create table
我在以下情况下尝试将Record1的ID更新为Record2的ID: 两个表中的名称相同,并且 在Record2中权重更大。 记录1 | ID | Weight | Name | |----|----
我是一名优秀的程序员,十分优秀!