次のエラーが発生しました。
Datasource names for all the database tags within the cftransaction tag must be the same.
これは、次のコードから生じています。
transaction action="begin" {
try {
var data = {};
data.time = getTickCount();
addToLog("Persist", "Started persist operations");
doClientPersist();
cleanUp(arguments.importId);
addToLog("Persist", "Completed the persist operations successfully", ((getTickCount()-data.time)/1000));
return true;
} catch (any e) {
transactionRollback();
data.error = e;
}
}
トランザクションは、下位レベルのメソッドの割り当てを効果的にラップしていますdoClientPersist()
。このような呼び出しの 1 つは、フレームワーク データベースの抽象化レイヤーの奥深くにあり、別のデータ ソース (Postcode データ ソースとしましょう) から経度と緯度の情報を取得 (SELECT) します。このデータ ソースは厳密には読み取り専用です。
<cffunction name="getLatitudeAndLongitude" access="package" returntype="query" output="false">
<cfargument name="postcode" type="string" required="true" />
<cfset var qPostcode = ''/>
<cfquery name="qPostcode" datasource="postcodesDatasource">
SELECT
a.latitude,
a.longitude
FROM
postcodes AS a
WHERE
a.postcode = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#postcode#"/>
</cfquery>
<cfreturn qPostcode/>
</cffunction>
<cffunction name="getPostcodeCoordinates" access="public" returntype="struct" output="false">
<cfargument name="postcode" type="string" required="true"/>
<cfscript>
var data = {};
data.postcode = getFormattedPostcode(arguments.postcode);
data.valid = isValidPostcode(data.postcode);
data.coords = {};
if (data.valid) {
data.query = getLatitudeAndLongitude(data.postcode);
if (isQuery(data.query) && data.query.recordCount) {
data.coords["latitude"] = data.query["latitude"][1];
data.coords["longitude"] = data.query["longitude"][1];
} else if (data.valid == 2) {
/** No match, try short postcode (RECURSIVE) **/
data.coords = getPostcodeCoordinates(trim(left(data.postcode, len(data.postcode)-3)));
}
}
return data.coords;
</cfscript>
</cffunction>
問題を読むと、ドキュメントは次のように述べています。
In a transaction block, you can write queries to more than one database, but you must commit or roll back a transaction to one database before writing a query to another.
残念ながら、上記のように、この郵便番号データをフェッチするコードは、実際の永続化操作とはまったく関係がありません。これは、変更できない低レベル メソッドの Web を実行するためです。リモート データソース。
とにかく、トランザクション内で「最上位」メソッドをラップし、「郵便番号」データソースへの呼び出しを保持できるということはありますか?クライアントごとに郵便番号情報を複製する必要があるのはばかげていますが、操作は何か問題が発生した場合にロールバックします。
前もって感謝します。