我在使用准备好的语句查询 Sybase IQ 时遇到问题。当我将整个查询键入为文本然后在不带参数的情况下对其调用 PrepareStatement 时,查询工作正常。但是当我坚持一个参数时,我会返回错误,即使我的 sql 是正确的。知道为什么吗?
此代码运行良好并运行我的查询:
errorquery<<"SELECT 1 as foobar \
, (SUM(1) over (partition by foobar) ) as myColumn \
FROM spgxCube.LPCache lpcache \
WHERE lpcache.CIG_OrigYear = 2001 ";
odbc::Connection* connQuery= SpgxDBConnectionPool::getInstance().getConnection("MyServer");
PreparedStatementPtr pPrepStatement(connQuery->prepareStatement(errorquery.str()));
pPrepStatement->executeQuery();
但这是完全相同的事情,只是我没有在代码中直接输入“2001”,而是用一个参数插入它:
errorquery<<"SELECT 1 as foobar \
, (SUM(1) over (partition by foobar) ) as myColumn \
FROM spgxCube.LPCache lpcache \
WHERE lpcache.CIG_OrigYear = ? ";
odbc::Connection* connQuery = SpgxDBConnectionPool::getInstance().getConnection("MyServer");
PreparedStatementPtr pPrepStatement(connQuery->prepareStatement(errorquery.str()));
int intVal = 2001;
pPrepStatement->setInt(1, intVal);
pPrepStatement->executeQuery();
这会产生这个错误: [Sybase][ODBC 驱动程序][Adaptive Server Anywhere]'(SUM(1) over(partition by foobar)) as myColumn'附近的无效表达式
知道为什么第二个失败时第一个有效吗?是否不允许将“分区依据”与插入的 sql 参数或类似的东西一起使用?
最佳答案
Sybase (ASA) Adaptive Server Anywhere 错误正常,IQ DB 中包含一个 Sybase ASA 实例,用于 SYSTEM 空间。
我不知道 Sybase IQ v12.7 之前的版本是否支持/完全支持分区依据。我记得在 v12.6 下遇到过问题。在 v12.7 或更高版本下它应该没问题,否则你的命令对我来说看起来不错。
关于c++ - 带有 "partition by"的准备好的语句对 Sybase IQ 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1088006/