Most of the DAO header files in src/library/dao have definitions for the names 
of tables, and the names of columns in the tables, but they're used 
sporadically; quite often, references to them are hardcoded.

I'm writing a new feature (the aforementioned auto-DJ-crates), and the 
necessary info is stored in a temporary table, so I'm writing several SQL 
queries.  I'm just wondering if I should hardcode the table/column references 
(which won't automatically get updated if the underlying names change), or try 
to write them using the table/column names defined in header files (which makes 
the query harder to read).

Here's an example.  The comment is the hardcoded, human-readable version, and 
following it is the hard-to-read one that'll adapt automatically to changes.


    // INSERT INTO temp_autodj_crates (track_id, craterefs, timesplayed, 
autodjrefs) SELECT crate_tracks.track_id, COUNT (*), library.timesplayed, 0 
FROM crate_tracks, library WHERE crate_tracks.crate_id IN (SELECT id FROM 
crates WHERE autodj = 1) AND crate_tracks.track_id = library.id AND 
library.mixxx_deleted = 0 GROUP BY crate_tracks.track_id, library.timesplayed;
    strQuery = QString ("INSERT INTO " AUTODJCRATES_TABLE
        " (" AUTODJCRATESTABLE_TRACKID ", " AUTODJCRATESTABLE_CRATEREFS ", "
        AUTODJCRATESTABLE_TIMESPLAYED ", " AUTODJCRATESTABLE_AUTODJREFS ")"
        " SELECT " CRATE_TRACKS_TABLE ".%1 , COUNT (*), "
        LIBRARY_TABLE ".%2, 0 FROM " CRATE_TRACKS_TABLE ", " LIBRARY_TABLE
        " WHERE " CRATE_TRACKS_TABLE ".%4 IN "
        "(SELECT %5 FROM " CRATE_TABLE " WHERE %6 = 1) AND "
        CRATE_TRACKS_TABLE ".%1 = " LIBRARY_TABLE ".%7 AND " LIBRARY_TABLE
        ".%3 == 0 GROUP BY " CRATE_TRACKS_TABLE ".%1, " LIBRARY_TABLE ".%2")
            .arg (CRATETRACKSTABLE_TRACKID)        // %1
            .arg (LIBRARYTABLE_TIMESPLAYED)        // %2
            .arg (LIBRARYTABLE_MIXXXDELETED)    // %3
            .arg (CRATETRACKSTABLE_CRATEID)        // %4
            .arg (CRATETABLE_ID)                // %5
            .arg (CRATETABLE_AUTODJ)            // %6
            .arg (LIBRARYTABLE_ID);                // %7


Which should I do?

Pretty soon, I'll make a blueprint for the auto-DJ-crates feature.


Steven Boswell
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Get Mixxx, the #1 Free MP3 DJ Mixing software Today
http://mixxx.org


Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to