Component that helps generating sql code



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








.



Relevant Pages

  • Re: Multilayer applications
    ... >> business object is not constrained in needing to contain ... What about sql queries providing ... > In a SQL solution everyting should be solved by SQL engine itself. ... SQL engine increases and crosses into the business rules. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Issues with Compact Framework VS 2005 migration
    ... We are using VB.net & SQL CE 3.0 for Device. ... We are having common code files for Desktop & device application, ... We have many issues while migration. ... SQL Queries which works fine on previous SQL CE 2.0 now does not return ...
    (microsoft.public.sqlserver.ce)
  • Re: i5 performance problems
    ... Check QSYSOPR message queue around the time the problem occurs, and see if you are getting messages like: ... Interactive usage approaching installed capacity ... Certain SQL queries over some files or tables that might not have all the necessary indexes could cause the system to build temporary indexes and this can be quite expensive in terms of CPU and I/O, and could help to push your system "over the limit" if someone is running SQL queries interactively. ...
    (comp.sys.ibm.as400.misc)
  • Re: Multiplicity, Change and MV
    ... programmers/users are stupid. ... Given that the people online who are considered the best and the brightest experts from among the pick crowd are universally stupid, ... If they had a SQL ... My brain remains functional. ...
    (comp.databases.theory)
  • Re: Migrating away from MS-Access
    ... if you convert your Access tables directly over to SQL ... Regular SQL queries will still need to pull all the ... data down from the server before it can process it. ... SQL queries will need to be converted to stored procedures to see any ...
    (comp.databases.ms-access)