3

I have the following table join that runs fine in Microsoft SQL Server and returns the expected results.

SELECT     d.id1, c.content_type
FROM       Document2 AS d INNER JOIN
           Content2 AS c ON d.content_id = c.content_id
WHERE     (d.class_id = 1)

However when I place the statement into a ColdFusion CFC, the statement will not execute and I am not getting anything to return. Does the syntax change within the CFC file? Is the Microsoft SQL syntax different from the ColdFusion CFC syntax? Or am I missing something else here?

This is the relevant function. I can get this code to work if I use a simple SQL statement that is not a table join. However, when I insert the table join statement nothing will return.

  remote array function getcontent() {
    var q = new com.adobe.coldfusion.query();
     q.addParam( name="searchParam", value="#searchName#" );
    q.setDatasource("Document");
    q.setSQL("SELECT d.id1, c.content_type FROM Document2 
    AS d INNER JOIN   
    Content2 AS c ON d.content_id = c.content_id WHERE (d.class_id = 1)");

    var data = q.execute().getResult();
    var result = [];
    for(var i=1; i<= data.recordCount; i++) {
        arrayAppend(result, {"id"=data.d.id1[i], "Type"=data.c.content_type[i]});
    }
    return result;
}
4

1 に答える 1

8

問題は次のコード行です。

arrayAppend(result, {"id"=data.d.id1[i], "Type"=data.c.content_type[i]});


そのようなデータベース変数を参照することはありません。テーブルエイリアスは列エイリアスの一部ではありません。

単に使用する必要があります:

data.id1[i]


列エイリアスに実際にが含まれている場合.は、次のように角かっこ表記を使用して参照する必要があります。

data['d.id1'][i]

ただし、ここでも、テーブルエイリアスは列エイリアスの一部ではないため、これは必要ありません。

于 2012-08-29T14:45:56.443 に答える