Noel Frankinet wrote:

I would like to create a user function to know if a record is contained in a rectangle ?
If have looked to sqlite_create_function
I know that my record has for column (xmin,ymin,xmax,ymax)
I would like to use the new function to write something like
select * from table where ??? contains ???? (how I pass the selecting rectangle)

Is it possible ?
How do I do that ?
Thank you

Noel,

You need to create a predicate function that returns a boolean or integer (0 or 1) value based on 6 input values. Conceptually it would look like this:

   int point_in_rect(px, py, rxl, rxh, ryl, ryh)

Where px and py are the location of a point, rxl and rxh are the low and high limits of the rectangle's x dimension, and ryl and ryh are the low and high limits of the rectangle's y dimension.

You would use this function like this:

   create table points(x int, y int, data text);

   select * from points where point_in_rect(x, y, 10, 100, 25, 75);

This should give you an idea of how to implement it using the sqlite APIs.

   /* implement point in rect predicate function */

   void point_in_rect(sqlite3_context* ctx, int argc, sqlite3_value** argv)
   {
       int p, rl, rh, in = 0;

       /* check x values first */
       p = sqlite3_value_int(argv[0]);
       rl = sqlite3_value_int(argv[2]);
       rh = sqlite3_value_int(argv[3]);
       if (p >= rl && p <=rh) {
           /* now check y values */
           p = sqlite3_value_int(argv[1]);
           rl = sqlite3_value_int(argv[4]);
           rh = sqlite3_value_int(argv[5]);
           if (p >= rl && p <= rh)
               in = 1;
       }
sqlite3_result_int(ctx, in);
   }


   /* register point in rect predicate */

   sqlite3* db;
   rc = sqlite3_create_function(db, "point_in_rect", 6,
           SQLITE_UTF8, NULL, point_in_rect, NULL, NULL);


HTH
Dennis Cote


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to