CFWheels:将表映射到另一个数据库Database.tablename [英] CFWheels: Map table to another database Database.tablename

查看:222
本文介绍了CFWheels:将表映射到另一个数据库Database.tablename的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为cforms的数据源,它可以访问两个数据库
cforms和cquizes



我想创建以下查询:

  select * from cquizes.tb_depts; 

我有一个表tb_depts的模型:

 < cfcomponent extends =Model> 
< cffunction name =init>
< cfset table(tb_depts)>
< / cffunction>
< / cfcomponent>

我的控制器:

  list = model(tb_depts)。findAll(order =id); 

当我运行此控制器/操作。它给我以下错误:

  [Macromedia] [Oracle JDBC驱动程序] [Oracle] ORA-00942:table或view不存在

并生成以下查询:

  SELECT * FROM tb_depts 

是因为tb_depts不存在于数据库cforms中,它会抛出未找到的错误。但是有没有办法告诉模型,使用数据源cforms访问数据库cquizes。例如

  cquizes.tb_depts 

它似乎使用与数据源名称匹配的数据库。是否有办法解决这个功能。

解决方案

如果你需要从另一个数据库获取数据, 。为此,您需要为第二个数据库 cquizes 创建数据源。然后在模型文件中使用该数据源名称。这将覆盖该模型的默认数据源。



例如,如果将第二个数据源命名为 cquizdatasource / p>

 < cfcomponent extends =Model> 
< cffunction name =init>
< cfset dataSource(cquizdatasource)>
< cfset table(tb_depts)>
< / cffunction>
< / cfcomponent>

您的查询应该在问题中的所述场景中正常工作。对此有一些限制,请查看链接以了解详情。 / p>

I have a datasource called "cforms" which has access to two database "cforms" and "cquizes"

I wish to create the following query:

select * from cquizes.tb_depts;

I have a model for table "tb_depts":

<cfcomponent extends="Model">
    <cffunction name="init">
        <cfset table("tb_depts")>
    </cffunction>
</cfcomponent>

And my controller:

list = model("tb_depts").findAll(order="id");

When I run this controller/action. It gives me the following error:

[Macromedia][Oracle JDBC Driver][Oracle]ORA-00942: table or view does not exist

And it generates the following query:

 SELECT * FROM tb_depts

I understand what the problem is because since "tb_depts" doesn't exist in database "cforms" it throws that not found error. However is there are way to tell the model that using the datasource "cforms" access database "cquizes". For example

cquizes.tb_depts

Its seems to use the database that matches the datasource name. Is there a way to work around this functionality.

解决方案

If you need to get data from another database, There is an alternative way. For that you need to create a datasource for your second database cquizes. Then use that datasource name in the model file. This will override default datasource for that model.

For example, If you name your second datasource as cquizdatasource then in your model would be like

<cfcomponent extends="Model">
    <cffunction name="init">
        <cfset dataSource("cquizdatasource")>
        <cfset table("tb_depts")>
    </cffunction>
</cfcomponent>

Your query should work fine with the said scenario in the question. There are limitations to this, check out the link to know more.

这篇关于CFWheels:将表映射到另一个数据库Database.tablename的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆