我对 ColdFusion 还很陌生,正在尝试从数据库中提取数据并将其发送到我创建的电子邮件功能。
myQry = new Query();
myQry.setSQL("select * from stocknotifications LEFT JOIN options ON stocknotifications.stocknotification_id = options.option_id ORDER BY stocknotification_id DESC LIMIT 1 "); //set query
qryRes = myQry.execute();
writedump(qryRes.getResult(), false);
Mail = variables.NotificationService.newMail();
Mail.setTo("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5d3f3b2f38333e351d39382e2934333c293432333e302e733e32732836" rel="noreferrer noopener nofollow">[email protected]</a>");
Mail.setSubject( "New Stock Request" );
// render body with layout which uses the rc.emailView
Mail.setBody(ToString(qryRes.getResult()));
variables.NotificationService.sendMail( Mail );
我的 writeDump() 工作并显示表中的最后一项。唯一的问题是我无法将它传递到 setBody() 而不抛出错误。
Can't cast Complex Object Type Query to String Use Built-In-Function "serialize(Query):String" to create a String from Query
有什么想法吗?
最佳答案
根据您收到的错误消息,您实际上可以将 toString 替换为序列化,然后就可以了。
如果您想要的只是将数据发送到电子邮件而不关心表示方式,快速而肮脏,您可能需要尝试SerializeJSON()
;它将把 query
转换为带有 COLUMNS
和 DATA
的 JSON
字符串:
Mail.setBody(SerializeJSON(qryRes.getResult()));
关于ColdFusion 对象到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24206311/