[GRASS-user] Max length of sql_query in v.extract

Glynn Clements glynn at gclements.plus.com
Thu Jan 28 13:43:12 EST 2010


Markus Neteler wrote:

>     if (where == NULL || strlen(where) == 0)
>         G_snprintf(buf, 1023, "SELECT %s FROM %s", col, tab);
>     else
>         G_snprintf(buf, 1023, "SELECT %s FROM %s WHERE %s", col, tab, where);
> 
>     G_debug(3, "  SQL: %s", buf);
> 
>     db_init_string(&stmt);
>     db_append_string(&stmt, buf);
> 
> I guess that we need to change to dynamic string length allocation here?
> The cut string is pretty close to the 1023 chars length.

AFAICT, the raison d'être for the dbString type was precisely to avoid
this sort of issue. I suggest:

	db_init_string(&stmt);
	db_append_string(&stmt, "SELECT ");
	db_append_string(&stmt, col);
	db_append_string(&stmt, " FROM ");
	db_append_string(&stmt, tab);
	if (where && *where) {
	    db_append_string(&stmt, " WHERE ");
	    db_append_string(&stmt, where);
	}

Beyond that, maybe we need db_sprintf_string()?

BTW, as we appear to be taking the availability of snprintf() for
granted, maybe it's time to re-write G_asprintf() (the current
fallback implementation where vasprintf() isn't available writes to a
temporary file then reads it back in, which isn't exactly efficient).

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list