Beispiel #1
0
void FbIncrementFunction::Execute(wxSQLite3FunctionContext& ctx)
{
	int id = ctx.GetArgCount()>0 ? ctx.GetInt(0) : 0;
	m_increment++;
	id += m_increment;
	ctx.SetResult(-id);
}
Beispiel #2
0
void FbSearchFunction::Execute(wxSQLite3FunctionContext& ctx)
{
	int argc = ctx.GetArgCount();
	if (argc != 1) {
		ctx.SetResultError(wxString::Format(fbT("Wrong SEARCH argc: %d."), argc));
		return;
	}

	wxString input = ctx.GetString(0);
	wxArrayString words;
	wxStringTokenizer tkz(Lower(input), wxT(' '), wxTOKEN_STRTOK);
	while (tkz.HasMoreTokens()) {
		words.Add(tkz.GetNextToken());
	}

	size_t count = m_masks.Count();
	for (size_t i = 0; i < count; i++) {
		bool not_found = true;
		size_t count = words.Count();
		for (size_t j = 0; j < count; j++) {
			if ( words[j].Matches(m_masks[i]) ) {
				not_found = false;
				break;
			}
		}
		if (not_found) {
			ctx.SetResult(false);
			return;
		}
	}
	ctx.SetResult(true);
}
Beispiel #3
0
void FbAuthorFunction::Execute(wxSQLite3FunctionContext& ctx)
{
	if (ctx.GetArgCount() == 3) {
		wxString res = ctx.GetString(0).Trim(true);
		(res << wxT(' ') << ctx.GetString(1).Trim(false)).Trim(true);
		(res << wxT(' ') << ctx.GetString(2).Trim(false)).Trim(true);
		ctx.SetResult(res.Trim(false));
	}
}
Beispiel #4
0
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;
  }
Beispiel #6
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(" "));
    }
  }
Beispiel #7
0
void FbLowerFunction::Execute(wxSQLite3FunctionContext& ctx)
{
	int argc = ctx.GetArgCount();
	if (argc == 1) {
		wxString str = Lower(ctx.GetString(0));
		size_t len = str.Len();
		for (size_t i = 0; i < len; i++) {
			if (str[i] == 0x0451) str[i] = 0x0435;
			#ifndef SQLITE_ENABLE_ICU
			if (!IsAlpha(str[i])) str[i] = 0x20;
			#endif
		}
		ctx.SetResult(str);
	} else {
		ctx.SetResultError(wxString::Format(fbT("Wrong LOWER argc: %d."), argc));
	}
}
void DistanceMercatorFunc::Execute(wxSQLite3FunctionContext& ctx)
{
    if ( ctx.GetArgCount() != 4 )
    {
        ctx.SetResultError(_T("Function takes exactly 4 arguments."));
        return;
    }
    double lat0 = ctx.GetDouble(0);
    double lon0 = ctx.GetDouble(1);
    double lat1 = ctx.GetDouble(2);
    double lon1 = ctx.GetDouble(3);
    if ( lat0 > 90. || lat0 < -90. || lat1 > 90. || lat1 < -90.)
    {
        ctx.SetResultError(_T("Latitude must be between -90 and 90."));
        return;
    }
    
    if ( lon0 > 180. || lon0 < -180. || lon1 > 180. || lon1 < -180.)
    {
        ctx.SetResultError(_T("Longitude must be between -180 and 180."));
        return;
    }
    
    double dist;
    DistanceBearingMercator_Plugin(lat0, lon0, lat1, lon1, NULL, &dist);
    
    ctx.SetResult(dist);
}
Beispiel #9
0
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;
}
Beispiel #10
0
void FbLetterFunction::Execute(wxSQLite3FunctionContext& ctx)
{
	if (ctx.GetArgCount() == 1) {
		ctx.SetResult(Letter(ctx.GetString(0)));
	}
}
Beispiel #11
0
void FbGenreFunction::Execute(wxSQLite3FunctionContext& ctx)
{
	if (ctx.GetArgCount() == 1) ctx.SetResult( DecodeList(ctx.GetString(0)) );
}