coldfusion
cfquery
サーチ…
パラメーター
| パラメータ | 詳細 |
|---|---|
| 名 | 値: 文字列 、デフォルト:はい |
| dbtype | 値:query / hql、デフォルト:no、備考:空白のままの場合は、通常のクエリです |
| 情報源 | デフォルト:いいえ、備考:データベース |
| パラメータ | 値: 構造体 、デフォルト:いいえ、備考:cfscript構文のみ! cfmlでは、 <cfqueryparam />を使用してSLQステートメント内に書き込まれ<cfqueryparam /> |
関数内でのcfqueryの使用
<cffunction name="getUserById" access="public" returntype="query">
<cfargument name="userId" type="numeric" required="yes" hint="The ID of the user">
<cfquery name="local.qryGetUser" datasource="DATABASE_NAME">
SELECT id,
name
FROM user
WHERE id = <cfqueryparam value="#arguments.userId#" cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn local.qryGetUser>
</cffunction>
クエリのクエリ
関数呼び出し
<!--- Load the user object based on the component path. --->
<cfset local.user = new com.User() />
<cfset local.allUsers = user.getAllUsers()>
<cfset local.specificUser = user.getUserIdFromQry(qry = local.allUsers, userId = 1)>
User.cfc
<cfcomponent>
<cffunction name="getAllUsers" access="public" returntype="query">
<cfquery name="local.qryGetAllUsers" datasource="DATABASE_NAME">
SELECT id,
name
FROM user
</cfquery>
<cfreturn local.qryGetAllUsers>
</cffunction>
<cffunction name="getUserIdFromQry" access="public" returntype="query">
<cfargument name="qry" type="query" required="Yes" hint="Query to fetch from">
<cfargument name="userId" type="numeric" required="Yes" hint="The ID of the user">
<cfquery name="local.qryGetUserIdFromQry" dbtype="query">
SELECT id,
name
FROM arguments.qry
WHERE id = <cfqueryparam value="#arguments.userId#" cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn local.qryGetUserIdFromQry>
</cffunction>
</component>
Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow