Re: Decouple SQL queries from class in OOP design



> it's not good to mix SQL queries with
> application codes in classes, because it limits the usability of the
> classes and bound them to the local database schema.

Your application (and classes) will be bound to the local database
schema anyway. This mapping has to be done somewhere. Your classes "on
top" of the SQL statements will not survive any major schema changes
just because you separate the SQL strings.

> But I am not sure
> what the best way is to decouple them. The method that I am using right
> now is to create a hash to store all the SQL statements and prepare
> them in the main program, then I will pass this hash as a variable to
> all the classes that are going to use it.

This design will probably just cause you and your colleagues extra
work. When you add functions to your application you both have to edit
you classes AND edit the SQL statement list. When someone tries to read
and understand your application, he has to read both the classes and
the SQL statement list simultaneously to be able to understand what the
application actually do.

Fredrik Bertilsson
http://butler.sourceforge.net

.



Relevant Pages

  • DES 1.7.0 Released
    ... Datalog Educational System version 1.7.0 ... SQL statements ... for tables created with SQL statements can be ... expressions which are evaluated before ...
    (comp.lang.prolog)
  • Performance: Query optimizer producing sub-optimal result?
    ... As part of a suite of SQL statements I am trying to write a data integrity ... SELECT UID, fnCheck ... The optimizer seems to move the "DISTINCT" action in the subquery to the end ... Define a View which performs the SELECT DISTINCT part of option A. My SQL ...
    (microsoft.public.sqlserver.programming)
  • RE: Manipulating MS Access records with excel VBA + ADO
    ... Data - Import External Data - New Database query ... Select the control button view dataor edit query. ... Look for SQL button to get the SQL ... Take the SQL statements and put into a string by adding double quotes. ...
    (microsoft.public.excel.programming)
  • RE: Newline inserted?
    ... Are you processing individual SQL statements (does your file contain SQL ... DBI is not your best bet to do this. ... When I attempt to load this file into Oracle 10g using the DBI I get the ...
    (perl.dbi.users)
  • Re: Security Questions
    ... I expect you're concerned with SQL injection attacks and you should be. ... WHEN the schema changes, you're back to opening up N projects that might have referenced the schema in some specific way. ... Am I correct in my understanding that, if @Message contains any SQL statements, that will not cause any problems within this procedure? ...
    (microsoft.public.dotnet.framework.adonet)