void FbAggregateFunction::Aggregate(wxSQLite3FunctionContext& ctx) { wxSortedArrayString** acc = (wxSortedArrayString **) ctx.GetAggregateStruct(sizeof (wxSortedArrayString **)); if (*acc == NULL) *acc = new wxSortedArrayString ; for (int i = 0; i < ctx.GetArgCount(); i++) { wxString text = ctx.GetString(i); text.Trim(true).Trim(false); if (!text.IsEmpty()) (**acc).Add(text); } }
// Set the result of the aggregate function virtual void Finalize(wxSQLite3FunctionContext& ctx) { // Get the temporary memory conatining the result wxString** acc = (wxString**) ctx.GetAggregateStruct(sizeof (wxString**)); // Set the result ctx.SetResult(*(*acc)); // Important: Free the allocated wxString delete *acc; *acc = 0; }
// Concatenate all values virtual void Aggregate(wxSQLite3FunctionContext& ctx) { // Get the temporary memory for storing the intermediate result wxString** acc = (wxString**) ctx.GetAggregateStruct(sizeof (wxString**)); // Allocate a wxString instance in the first aggregate step if (*acc == NULL) { *acc = new wxString(wxT("")); } // Concatenate all arguments for (int i = 0; i < ctx.GetArgCount(); i++) { (*acc)->Append(ctx.GetString(i)); (*acc)->Append(wxT(" ")); } }
void FbAggregateFunction::Finalize(wxSQLite3FunctionContext& ctx) { wxSortedArrayString ** acc = (wxSortedArrayString **) ctx.GetAggregateStruct(sizeof (wxSortedArrayString **)); if ((*acc) == NULL) return; wxString result; size_t iCount = (*acc)->Count(); for (size_t i=0; i<iCount; i++) { wxString text = (**acc).Item(i); if (!result.IsEmpty()) result << wxT(", "); if (!text.IsEmpty()) result << text; } ctx.SetResult(result); delete *acc; *acc = 0; }