Wow good work steve... that is one complete line of code... none of my dodgy fly by night sort of gibberish ;)... made into a UDF too... you submitted it anywhere yet ?
On May 14, 6:55 pm, "Steve Onnis" <[EMAIL PROTECTED]> wrote: > Here you go > > Got bored and always like a challenge :) > > ///////////////////////////////////////////////////////// > <cfscript> > function queryInsertRow(query, position, rowData) { > /* > query : the query object > position : the position to add the new row > rowData : a structure containing the names of the > columns as keys > */ > > var columns = listToArray(query.columnList); > var rowCount = MAX(query.recordCount + 1, position); > var columnCount = arrayLen(columns); > var columnStruct = structNew(); > var c = ""; > var q = queryNew(""); > > // loop over the query columns > for (c=1; c LTE columnCount; c = c + 1) { > // get the values out of the column > columnStruct[columns[c]] = > listToArray(evaluate("valueList(query.#columns[c]#)")); > > // arrayInserAt() fails if the inser position is > greater then the avalable array length > // so resize the array and set the array element at > the position > if (position GT query.recordCount) { > arrayResize( > columnStruct[columns[c]], > rowCount > ); > > arraySet( > columnStruct[columns[c]], > position, > position, > IIF(structKeyExists(rowData, > columns[c]), "rowData[columns[c]]", "''") > ); > } > > // Use arrayInserAt() to inject the new value > else { > arrayInsertAt( > columnStruct[columns[c]], > position, > IIF(structKeyExists(rowData, > columns[c]), "rowData[columns[c]]", "''") > ); > } > // add the column back into our new query > queryAddColumn( > q, > columns[c], > columnStruct[columns[c]] > ); > } > return q; > } > > qry = queryNew(""); > queryAddColumn(qry, "fruit", listToArray("banana,apple,orange")); > queryAddColumn(qry, "vegies", > listToArray("carrot,cucumber,tomato")); > > </cfscript> > <cfdump var="#qry#"> > > <cfscript> > newRow = structNew(); > newRow["fruit"] = "new fruit"; > > qry = queryInsertRow( > qry, > 2, > newRow > ); > </cfscript> > > <cfdump var="#qry#"> > ///////////////////////////////////////////////////////// --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "cfaussie" group. To post to this group, send email to cfaussie@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cfaussie?hl=en -~----------~----~----~----~------~----~------~--~---