On 06 Sep 2013, at 17:51, Simon Davies <simon.james.dav...@gmail.com> wrote:

>> Are there any other ways to kind of memoize the GeomFromText function
>> (or the parameters to distance) besides aux_data?
> 
> select Distance( constGeom, geometry ) from table, (select
> GeomFromText('Point(13.457 3)') as constGeom );

I just tried this out, but unfortunately it doesn't make a difference. I guess 
this boils down to the same thing as what I was doing before. table and the sub 
select get joined and the function is invoked for every row again.
Or I could be doing something in wrong in my code of course. Snippet copied 
below. With a simple query this prints 'Recreate' for each row.

Pepijn

disclaimer: this is just quick and dirty proof of concept code to see if this 
would work or not.

static void ST_Contains(sqlite3_context *context, int nbArgs, sqlite3_value 
**args) {
  GEOS_START(context);
  const GEOSPreparedGeometry *pg1 = sqlite3_get_auxdata(context, 0);
  if (pg1 == NULL) {
    printf("Recreate\n");
    GEOSGeometry *g1 = GEOS_GET_GEOM( args, 0 );
    if (g1 == NULL) {
      sqlite3_result_error(context, error_message(&error), -1);
      return;
    }
    pg1 = GEOSPrepare_r(GEOS_HANDLE, g1);
    if (pg1 == NULL) {
      sqlite3_result_error(context, error_message(&error), -1);
      return;
    }
  } else {
    printf("Reuse\n");
  }

  GEOSGeometry *g2 = GEOS_GET_GEOM( args, 1 );
  if (g2 == NULL) {
    sqlite3_result_error(context, error_message(&error), -1);
    return;
  }
  char result = GEOSPreparedContains_r(GEOS_HANDLE, pg1, g2);
  if (result == 2) {
    geom_get_geos_error(&error);
    sqlite3_result_error(context, error_message(&error), -1);
  } else {
    sqlite3_result_int(context, result);
  }
  GEOS_FREE_GEOM( g2 );
  sqlite3_set_auxdata(context, 0, pg1, NULL);
}
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to