6 Replies Latest reply on Sep 19, 2008 11:21 AM by Vugof

    Making a query object with only certain columns?

    Vugof
      I need to make several identical charts using different queries, each using the same columns, say "name" and "age". I figured I could use a makeChart(query) function for this. The trick is, I need to ensure each query I pass in contains the variables "name" and "age".

      Rather than have the app blow up when I dont have the right column names, I figured I could have makeGraph() only accept a custom query object containing "name" and "age" as columns. Then when I run all my queries, I can copy the results into this query object and pass that to the makeChart() function. Is this possible?
        • 1. Re: Making a query object with only certain columns?
          -==cfSearching==- Level 4
          What about passing the column names as a parameter? Then the column names could be dynamic. You could set whatever defaults you want. Name and age if you prefer.
          • 2. Re: Making a query object with only certain columns?
            Vugof Level 1
            I could approach it that way, but I have about 7 different columns to pass so I'd have to pass in 8 parameters each time (query name + 7 cols).

            It'd be awesome if I could just say copy my query into this custom query object. Then all I'd need to worry about is the columns being in the right order during copy.
            • 3. Making a query object with only certain columns?
              -==cfSearching==- Level 4
              > I could approach it that way, but I have about 7 different columns to pass so I'd have
              > to pass in 8 parameters each time (query name + 7 cols).

              Why? If the chart function only uses two of the columns, you would just need to pass in the query object and the two column names that will be used for charting. Though if for some reason you needed all columns, you could always use the query "columnList" variable.

              > It'd be awesome if I could just say copy my query into this custom query object.
              > Then all I'd need to worry about is the columns being in the right order during copy.

              Yes, but you would still have to tell the object what columns to use for the chart. It seems much simpler to just pass the column names into your function and skip the complication of creating a new object.

              • 4. Re: Making a query object with only certain columns?
                Level 7
                > I could approach it that way, but I have about 7 different columns to pass so
                > I'd have to pass in 8 parameters each time (query name + 7 cols).

                Well: two. The query, and the list of columns.

                I'd approach this by just passing in a query, and stipulating in the hint
                for the argument that it must have specific columns. Within the method,
                check the correct columns are there, and if not: raise an exception.
                Garbage in: garbage out. I think you are overcomplicating things with what
                you're suggesting.

                Conversely, you could have two arguments:
                - a query (required)
                - a list of column mappings (optional)

                If there's no mappings, then the correct columns must be in place. If
                there's the mapping list, use those ones instead. There's - of course -
                still no guarantee that the columns in the mapping list will be in the
                query, but there's only so much one can do to accommodate the calling code.

                --
                Adam
                • 5. Re: Making a query object with only certain columns?
                  Dan Bracuk Level 5
                  quote:

                  Originally posted by: Vugof
                  I could approach it that way, but I have about 7 different columns to pass so I'd have to pass in 8 parameters each time (query name + 7 cols).

                  It'd be awesome if I could just say copy my query into this custom query object. Then all I'd need to worry about is the columns being in the right order during copy.

                  If you are passing a query with 7 columns, and your function is only going to use 2, how is supposed to know which two to use? You might want to use query of queries to get a two column query and send that to your function.
                  • 6. Re: Making a query object with only certain columns?
                    Vugof Level 1
                    Thanks for all the feedback! You guys are probably right, I am trying to overcomplicate things. I will go with the passing of the query + list of columns. Dan's QoQ approach seemed like it would achieve what I originally wanted, but I've read performance is not very stellar using this approach.

                    And I guess I should have been more clear on the 2 column issue - "name" and "age" columns were just examples, in reality I have 7 columns to pass. The list of columns should work well to get all 7. Thanks!!