• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 28, 2017 May 28, 2017

Copy link to clipboard

Copied

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><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#"

>

TOPICS
Database access

Views

3.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2017 Jun 03, 2017

Copy link to clipboard

Copied

LATEST

The error message might just be correct. To verify, comment out all the code, except

<cfquery datasource="rooms" name="blgQ">
  select * from tblblogs
  
</cfquery>
<cfdump var="#blgQ#">

and run the same page.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation