2009-07-06 107 views
0

使用预准备语句查询Sybase IQ时出现问题。查询工作正常时,我键入整个查询作为文本,然后调用PrepareStatement没有参数。但是当我坚持一个参数时,即使我的sql是正确的,我也会返回错误。任何想法为什么?使用“partition by”编写的语句不适用于Sybase IQ?

此代码工作完全正常,运行我的查询:

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)在(由foobar的分区)),为myColumn'

任何想法为什么第一个工程,如果第二个失败?你不允许使用插入sql参数或类似的东西“分区”?

回答

0

我对Adaptive Server Anywhere知之甚少,但您正在使用Adaptive Server Anywhere驱动程序来查询Sybase IQ。

这真的是你想要的吗?

1

Sybase(ASA)Adaptive Server Anywhere错误没有问题,IQ DB中包含Sybase ASA实例,用于SYSTEM空间。

我不知道在Sybase IQ v12.7之前的版本中是否支持/完全支持partition by。我记得在v12.6下有问题。在v12.7或更高版本中,它应该没问题,否则你的命令对我来说看起来不错。