我正在编写一个 CF 移动应用程序并使用 cfclient
标签。我遇到远程数据源连接问题,无法解决。
从 cfclient,我使用"房间"作为我的数据源字符串,该字符串在 CF 管理器中定义为数据源。它正在连接到远程 SQL Server。"房间"数据库中存在"Tblblogs",但在 cfclient 下我收到一个错误:> 不存在这样的表
但是,如果我采用在 cfclient 外部选择"tblblogs"的相同查询 [blgQ],它工作正常且没有问题。我不确定为什么它没有在 cfclient(如管理员中定义(下建立正确的数据源连接。
<!DOCTYPE html>
<html >
<body>
<h2>Add Expense</h2>
<form >
<table >
<tr>
<td>Date:</td> <td><input type="date" id="dateTxt"></td>
</tr>
<tr>
<td>Amount:</td> <td><input type="number" id="amtTxt"></td>
</tr>
<tr>
<td>Description</td>
<td><input type="text" id="descTxt"></td>
</tr>
<tr>
<td colspan="2">
<button type="button" id="addBtn">Add</button>
</td>
</tr>
</table>
</form>
<h2>Expenses:</h2>
<table id="expList">
<tr>
<th>Date</th>
<th>Amount</th>
<th>Description</th>
</tr>
</table>
</body>
</html>
<script >
document.getElementById("addBtn").onclick = function(){
addExpense();
}
</script>
<!--- cfclient code starts here --->
<cfclient>
<cfset document.getElementById("expList").innerHTML =''>
<!--- on client side you do not need to pre-configure datasource --->
<cfset dsn = "rooms">
<cftry>
<!--- create database if not already created --->
<cfquery datasource="rooms">
create table if not exists expenses (
id integer primary key,
expense_date integer,
amount real,
desc text
)
</cfquery>
<!--- Get expense records from the table --->
<cfquery datasource="rooms" name="expenses">
select * from expense order by expense_date desc
</cfquery>
<cfset alert(expenses.amount)>
<!--- Loop over expenses query object and display --->
<cfloop query="expenses">
<cfset var tmpDate = new Date(expense_date)>
<cfset addExpenseRow(expense_date,amount,desc)>
</cfloop>
<cfcatch type="any" name="e">
<cfset alert(e.message)>
</cfcatch>
</cftry>
<!--- Helper function to add epxpense row to HTML table --->
<cffunction name="addExpenseRow" >
<cfargument name="expense_date" >
<cfargument name="amt" >
<cfargument name="desc" >
<cfoutput >
<cfsavecontent variable="rowHtml" >
<tr>
<td>#dateFormat(expense_date,"mm/dd/yyyy")#</td>
<td>#amt#</td>
<td>#desc#</td>
</tr>
</cfsavecontent>
</cfoutput>
<cfset document.getElementById("expList").innerHTML += rowHtml>
</cffunction>
<!--- Called from JS script block in response to click event for addBtn --->
<cffunction name="addExpense" >
<cfset var tmpDate = new Date(document.getElementById("dateTxt").value)>
<cfset var amt = Number(document.getElementById("amtTxt").value)>
<cfset var desc = document.getElementById("descTxt").value>
<!--- TODO: Do data validation --->
<cftry>
<!--- Insert expense row into database table --->
<cfquery datasource="rooms" result="result">
insert into expense (expense_date,amount,desc) values(
<cfqueryparam cfsqltype="cf_sql_date" value="#tmpDate.getTime()#">,
<cfqueryparam cfsqltype="cf_sql_numeric" value="#amt#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#desc#">
)
</cfquery>
<cfcatch type="any" name="e">
<cfset alert(e.message)>
</cfcatch>
</cftry>
<!--- add the new expense row to HTML table --->
<cfset addExpenseRow(tmpDate,amt,desc)>
</cffunction>
</cfclient>
<cfquery datasource="rooms" name="blgQ">
select * from tblblogs
</cfquery>
<cfdump var="#blgQ#"
> Blockquote
<cfclient>
上的<cfquery>
实际上与常规<cfclient>
不是一回事。
它旨在与 Web SQL 进行轻量级交互。Web SQL 并非普遍受支持,也不太可能得到普遍支持。 <cfclient>
也将遭受困扰<cfform>
的所有问题。也就是说,javascript将向前移动,但由此标签生成的代码可能不会。
请参阅用于移动开发的客户端 CFML。
我怀疑您正在尝试做一些可能更适合 AJAX 或 REST 的事情