Component that helps generating sql code

  • Thread starter Thread starter Peter Laan
  • Start date Start date
P

Peter Laan

I've been spending a few hours writing a component that helps generate
simple sql queries. But if I can come up with the idea, it's probably stupid
or someone has already done it. So does anyone know of a component that does
something like this (or is it a stupid idea)? It's no supposed to be able to
handle all queries, just make life a bit simpler 95% of the time. The code
would look something like this (SqlSelect is the helper class):

SqlSelect sql = new SqlSelect("Customers");
sql.AddSelectColumn("fname");
sql.AddSelectColumn("lname");
sql.AddWhereParameter("fname", "john");
sql.AddWhereParameter("lname", "smith");
SqlCommand cmd = sql.GetCommand(conn);

I then had another idea. Why not make a program that extracts all user table
data from the database and creates source code with constants for all table
and column names. Is this another stupid idea? The generated source code
would be something like this:

namespace Appname.DBNames
{
public class Customers
{
public const string a_TableName = "Customers";
public const string c_fname = "fname";
public const string c_id = "id";
public const string c_lname = "lname";
}
}

One class for each table. The 'c_' is there in case a column name collides
with a reserved name. 'a_' is used to get the table name first in
intellisense.

You would get great help from intellisense by typing
DBNames.Customers.c_lname. But if you don't use a component like above to
help generate the sql code, the code might get ugly. The sql string would
quickly get very long.

Any comments?


Peter
 
Peter,

The last month the two in this thread had long (in general friendly)
discussions in some dotnet newsgroups. Maybe can you look in it what you
find that fits you. They both have their own product by the way, however
they have done it very much besides those products, however more in a
theoretical approach.

There is much more than only this thread.

http://groups-beta.google.com/group...ab9f6f4f4fd/e05d2d117d4e5ea8#e05d2d117d4e5ea8

I hope this helps,

Cor
 
Back
Top