Quantcast
Channel: Adobe Community : Unanswered Discussions - ColdFusion
Viewing all articles
Browse latest Browse all 5794

coldfusion mobile app - connection to remote database server under cfclient tag

$
0
0

down votefavorite

 

 

I am writing cf mobile app and using cfclient tag. I am encountering issue with remote datasource connection and can’t get it resolve. From cfclient I am using “rooms” as my datasource string which is defined in administrator as data source. It is connecting to remote sql server. “Tblblogs” exist in rooms database, but under cfclient i get error that “No such table exist”. However, if I take same query [blgQ] that selects “tblblogs” outside cfclient, it works fine without issue. I am not sure why it is not making right datasource connection under cfclient (as defined in administrator)

 

 

<html>
  
<body>
  
<h2>Add Expense</h2>
  
<form>
  
<table>
  
<tr>
  
<td>Date:</td><td><inputtype="date"id="dateTxt"></td>
  
</tr>
  
<tr>
  
<td>Amount:</td><td><inputtype="number"id="amtTxt"></td>
  
</tr>
  
<tr>
  
<td>Description</td>
  
<td><inputtype="text"id="descTxt"></td>
  
</tr>
  
<tr>
  
<tdcolspan="2">
  
<buttontype="button"id="addBtn">Add</button>
  
</td>
  
</tr>
  
</table>
  
</form>

  
<h2>Expenses:</h2>
  
<tableid="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>
  
<cfsetdocument.getElementById("expList").innerHTML=''>
  
<!--- on client side you do not need to pre-configure datasource --->
  
<cfsetdsn="rooms">
  
<cftry>

  
<!--- create database if not already created --->
  
<cfquerydatasource="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 --->
  
<cfquerydatasource="rooms"name="expenses">
  select * from expense order by expense_date desc
  
</cfquery>
  
<cfsetalert(expenses.amount)>



  
<!--- Loop over expenses query object and display --->
  
<cfloopquery="expenses">
  
<cfsetvartmpDate=newDate(expense_date)>
  
<cfsetaddExpenseRow(expense_date,amount,desc)>
  
</cfloop>

  
<cfcatchtype="any"name="e">
  
<cfsetalert(e.message)>
  
</cfcatch>
  
</cftry>

  
<!--- Helper function to add epxpense row to HTML table --->
  
<cffunctionname="addExpenseRow">
  
<cfargumentname="expense_date">
  
<cfargumentname="amt">
  
<cfargumentname="desc">


  
<cfoutput>
  
<cfsavecontentvariable="rowHtml">
  
<tr>
  
<td>#dateFormat(expense_date,"mm/dd/yyyy")#</td>
  
<td>#amt#</td>
  
<td>#desc#</td>
  
</tr>
  
</cfsavecontent>
  
</cfoutput>

  
<cfsetdocument.getElementById("expList").innerHTML +=rowHtml>
  
</cffunction>

  
<!--- Called from JS script block in response to click event for addBtn --->
  
<cffunctionname="addExpense">
  
<cfsetvartmpDate=newDate(document.getElementById("dateTxt").value)>
  
<cfsetvaramt=Number(document.getElementById("amtTxt").value)>
  
<cfsetvardesc=document.getElementById("descTxt").value>

  
<!--- TODO: Do data validation --->
  
<cftry>
  
<!--- Insert expense row into database table --->  
  
<cfquerydatasource="rooms"result="result">
  insert into expense (expense_date,amount,desc) values(
  
<cfqueryparamcfsqltype="cf_sql_date"value="#tmpDate.getTime()#">,
  
<cfqueryparamcfsqltype="cf_sql_numeric"value="#amt#">,
  
<cfqueryparamcfsqltype="cf_sql_varchar"value="#desc#">
  )
  
</cfquery>

  
<cfcatchtype="any"name="e">
  
<cfsetalert(e.message)>
  
</cfcatch>
  
</cftry>


  
<!--- add the new expense row to HTML table --->
  
<cfsetaddExpenseRow(tmpDate,amt,desc)>
  
</cffunction>

</cfclient>

<cfquerydatasource="rooms"name="blgQ">
  select * from tblblogs
  
</cfquery>
<cfdumpvar="#blgQ#"

>


Viewing all articles
Browse latest Browse all 5794

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>