Cool, Thanks again, I need to write a modified version to handle my situation.
You should put it on cflib I think I understand Andrews question, but they way you did it adds the extra ability to insert lots of extra rows to the end of a query and then fill them later. Regards Dale Fraser http://learncf.com http://flexcf.com -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Onnis Sent: Thursday, 15 May 2008 11:47 AM To: [email protected] Subject: [cfaussie] Re: queryAddRow Yes that's right dale. With this function also, all the columns don't have to be passed in either. If it finds the column it the "rowData" param it populates it otherwise it is just left empty. Using the array function is going to be faster than looping over recordsets also. Steve -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Dale Fraser Sent: Thursday, 15 May 2008 8:09 AM To: [email protected] Subject: [cfaussie] Re: queryAddRow Thanks Steve, I think I understand that. You are converting each column to an array inserting a row into that array and adding that column back to a new query, correct? Regards Dale Fraser -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Onnis Sent: Wednesday, 14 May 2008 6:56 PM To: [email protected] Subject: [cfaussie] Re: queryAddRow 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 [email protected] 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 -~----------~----~----~----~------~----~------~--~---
