Click here to Skip to main content
15,907,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 28-Sep-10 23:18pm
v2
Comments
Hiren solanki 29-Sep-10 5:18am    
minor edit for grammar and removed irritative icons.

1 solution

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:

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


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.

EDIT: 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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900