我正在3层弧中完成我的项目,如果可能,我需要从文本文件调用所有查询吗? [英] i am doin my project in 3 tier arc and i need to call the all query's from text file if it possible?

查看:31
本文介绍了我正在3层弧中完成我的项目,如果可能,我需要从文本文件调用所有查询吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以3层体系结构进行项目,如果可能,我需要从文本文件调用所有查询吗?
我的数据库是Oracle.

在此先感谢,

rpkaran.

I am doing my project in 3 tier architecture and I need to call the all query''s from text file if it possible?
and my DB is Oracle.

Thanks in Advance,
By
rpkaran.

推荐答案

您是说要在文本文件中存储SQL语句吗?
如果是这样,那很容易.尽管如果可以的话,我建议您加倍努力,将其转变为存储过程.

为了回答您的问题,我假设您知道或可以弄清楚如何读取文本文件的内容.

问题是您要在文本文件中放入什么.

简单的解决方案,只需将带有占位符的SQL放在参数中:

例如

SELECT * FROM Employee WHERE Id =:id

然后在您的代码中只需创建一个命令对象,然后从文件和所需的任何参数中添加命令文本:

Are you saying that you want to store your SQL statements in text files?
If so that''s easy-ish. Although If you could I''d suggest going the extra mile and turning them into Stored Procs.

To answer your question, I''m going to assume you know or can figure out how to read the contents of a text file.

The question is what do you put in the text file.

Simple Solution, just put SQL with placeholders for Parameters:

e.g.

SELECT * FROM Employee WHERE Id = :id

then in your code you simply create a command object and add the commandtext from the file and any parameters you need:

Dim sql as String = GetSqlFromFile("SELECT_ALL.sql")
Dim command As New OracleClient.OracleCommand(sql)
command.Parameters.AddWithValue(":id", 5)



我正在做一些捷径和硬编码工作,但这是
只是为了要点.

我要说的是,如果您要采用这种方法,那么
实际上,对SQL的更改可能需要更改
在任何情况下都可以访问您的代码,因为您的代码对以下内容有期望 传入的参数和返回的数据.

在这种情况下,我不确定放置
有什么好处 文本文件中的SQL.它可能比建立SQL更具可读性
在代码中包含字符串,但是至少构建SQL具有
允许您根据
动态调整SQL的好处 情况.

您正在做的事情是消除所有静态SQL的麻烦而没有
进入将SQL放入存储过程的最后一步.

现在,如果这是某种形式的学校作业,则将
将SQL转换为文本文件是一个有趣的练习,如果可以的话,我认为
我给了您足够的入门知识.

但是我不会在商业项目中使用这种方法.

对我来说,您可能一直在谈论将实际数据保存在文本文件中,而不是查询中.

让我知道.那是完全不同的鱼缸.
为此,我将数据存储为XML.

-Rd



I''m taking a few short cuts and hard coding stuff, but this is
just to give a gist.

What I''d say is that if you are going to take this approach then
in reality changes to your SQL would probably require changes
to your code in any case since your code has expectations about
the parameters it passes in and the data it gets back.

That being the case I''m not sure there''s much benefit in putting
SQL in text files. It''s perhaps more readable than building up SQL
with strings in your code, but at least building up the SQL has the
benefit of allowing you to dynamically adapt your SQL depending on
the situation.

What you''re doing is taking all of the hassle of Static SQL without
going to final step of putting your SQL into Stored Procs.

Now, if this is a school assignment of some sort then putting the
SQL into text files is an interesting exercise, and if so I think
I''ve given you enough to get started.

But I wouldn''t use that approach in a commercial project.

It just occured to me that you may have been talking about keeping actual data in text files rather than queries.

Let me know. That''s a whole different kettle of fish.
For that I''d store the data in XML.

-Rd


这篇关于我正在3层弧中完成我的项目,如果可能,我需要从文本文件调用所有查询吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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