从 DBUnit 访问临时表

发布于 2025-01-06 10:36:20 字数 2991 浏览 0 评论 0原文

我在 Sybase 中有一个存储过程,它返回临时表中的一些数据(我们称之为 #results)。如果我从自己的代码创建此表并调用存储过程并检查 #results 一切都很好(我使用 Python 来实现此目的)。我可以为我的测试生成预期的结果集。

但是,当我尝试创建 DBUnit 测试用例时,代码

  1. 通过 Spring JdbcTemplate 创建临时表

  2. 调用此过程并检查返回的数据

在检查结果集时,我从 DbUnit 收到 NoSuchTableException

15:55:52.980 [main] DEBUG c.m.e.e.dbtest.helper.SQLTestHelper - *** expected table: #results
15:55:52.980 [main] DEBUG org.dbunit.dataset.FilteredDataSet - getTable(tableName=#results) - start
15:55:52.980 [main] DEBUG o.d.d.filter.SequenceTableFilter - accept(tableName=#results) - start
15:55:52.980 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - start
15:55:52.980 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - end - result=#RESULTS
15:55:52.980 [main] DEBUG org.dbunit.database.DatabaseDataSet - getTable(tableName=#results) - start
15:55:52.980 [main] DEBUG org.dbunit.database.DatabaseDataSet - initialize() - start
15:55:52.980 [main] DEBUG org.dbunit.database.DatabaseDataSet - Initializing the data set from the database...
15:55:52.980 [main] DEBUG o.d.d.DatabaseDataSourceConnection - getConnection() - start
15:55:52.980 [main] DEBUG m.b.t.TransactionResourceManager - Fetched TransactionResourceResolver [null]
15:55:52.980 [main] DEBUG msjava.pool.BasicObjectPool - Attempting to retrieve object from pool 'ConnectionPoolOf-dbunitDS'
15:55:52.980 [main] DEBUG msjava.pool.BasicObjectPool - Retrieved object 'TransactionInfoCachingConnection on DBCallSavingConnection on com.sybase.jdbc3.jdbc.SybConnection@170984c' from pool 'ConnectionPoolOf-dbunitDS'
15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - 
    database product name=Adaptive Server Enterprise
    database major version=12
    database minor version=5
    jdbc driver name=jConnect (TM) for JDBC (TM)
    jdbc driver version=jConnect (TM) for JDBC(TM)/6.05(Build 26564)/P/EBF16903/JDK14/Sun May 31  1:05:35 2009
    jdbc driver major version=6
    jdbc driver minor version=0

15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - metadata resultset=com.sybase.jdbc3.jdbc.SybResultSet@1b595f3
15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - getTableMetaData(tableName=#results) - start
15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - initialize() - start
15:55:53.402 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - start
15:55:53.402 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - end - result=#RESULTS
15:55:53.402 [main] ERROR org.dbunit.database.DatabaseDataSet - Table '#results' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]

与测试代码执行并行检查数据库(在断点处),我可以看到临时表确实在 tempdb 中创建并填充了数据。

有没有人成功地完成过这样的事情(例如,使用 DbUnit 中的 Sybase 临时表)?如果是,怎么办?

I have a stored procedure in Sybase that returns some data in a temp table (let's call it #results). If I create this table from my own code and call the stored procedure and check the #results everything is fine (I use Python for this purpose). I can generate the expected result set for my test.

However when I try to create a DBUnit test case so that the code

  1. creates the temp table via the Spring JdbcTemplate

  2. calls this procedure and checks the returned data

I get a NoSuchTableException from DbUnit when checking the result set.

15:55:52.980 [main] DEBUG c.m.e.e.dbtest.helper.SQLTestHelper - *** expected table: #results
15:55:52.980 [main] DEBUG org.dbunit.dataset.FilteredDataSet - getTable(tableName=#results) - start
15:55:52.980 [main] DEBUG o.d.d.filter.SequenceTableFilter - accept(tableName=#results) - start
15:55:52.980 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - start
15:55:52.980 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - end - result=#RESULTS
15:55:52.980 [main] DEBUG org.dbunit.database.DatabaseDataSet - getTable(tableName=#results) - start
15:55:52.980 [main] DEBUG org.dbunit.database.DatabaseDataSet - initialize() - start
15:55:52.980 [main] DEBUG org.dbunit.database.DatabaseDataSet - Initializing the data set from the database...
15:55:52.980 [main] DEBUG o.d.d.DatabaseDataSourceConnection - getConnection() - start
15:55:52.980 [main] DEBUG m.b.t.TransactionResourceManager - Fetched TransactionResourceResolver [null]
15:55:52.980 [main] DEBUG msjava.pool.BasicObjectPool - Attempting to retrieve object from pool 'ConnectionPoolOf-dbunitDS'
15:55:52.980 [main] DEBUG msjava.pool.BasicObjectPool - Retrieved object 'TransactionInfoCachingConnection on DBCallSavingConnection on com.sybase.jdbc3.jdbc.SybConnection@170984c' from pool 'ConnectionPoolOf-dbunitDS'
15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - 
    database product name=Adaptive Server Enterprise
    database major version=12
    database minor version=5
    jdbc driver name=jConnect (TM) for JDBC (TM)
    jdbc driver version=jConnect (TM) for JDBC(TM)/6.05(Build 26564)/P/EBF16903/JDK14/Sun May 31  1:05:35 2009
    jdbc driver major version=6
    jdbc driver minor version=0

15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - metadata resultset=com.sybase.jdbc3.jdbc.SybResultSet@1b595f3
15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - getTableMetaData(tableName=#results) - start
15:55:53.402 [main] DEBUG org.dbunit.database.DatabaseDataSet - initialize() - start
15:55:53.402 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - start
15:55:53.402 [main] DEBUG o.dbunit.dataset.OrderedTableNameMap - getTableName(tableName=#results) - end - result=#RESULTS
15:55:53.402 [main] ERROR org.dbunit.database.DatabaseDataSet - Table '#results' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]

Checking the database in parallel with the test code execution (at a breakpoint) I can see that the temp table is indeed created in tempdb and filled with data.

Has anyone done such a thing successfully (eg. used a Sybase temp table from DbUnit)? If yes, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里南柯 2025-01-13 10:36:20

如果使用“#”作为表名称的第一个字符来创建临时表:

临时表:

  • 仅在用户会话期间或创建临时表的过程范围内存在

  • 无法在用户连接之间共享

  • 自动删除 在会议结束时或过程(或可以手动删除)

您可以创建常规用户通过在创建表的命令中指定数据库名称来创建 tempdb 中的表:

tempdb 中的常规用户表:

  • 可以跨会话持久保存

  • 可用于批量复制操作

  • 可以通过授予权限来共享

  • 必须由所有者显式删除(否则,它们会在 Adaptive Server 重新启动时被删除)

If you create temporary tables by using “#” as the first character of the table name:

Temporary tables:

  • Exist only for the duration of the user session or for the scope of the procedure that creates them

  • Cannot be shared between user connections

  • Are automatically dropped at the end of the session or procedure (or can be dropped manually)

You can create regular user tables in tempdb by specifying the database name in the command that creates the table:

Regular user tables in tempdb:

  • Can persist across sessions

  • Can be used by bulk copy operations

  • Can be shared by granting permissions on them

  • Must be explicitly dropped by the owner (otherwise, they are removed when Adaptive Server is restarted)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文