使用預準備語句查詢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參數或類似的東西「分區」?