On Fri, 2006-06-02 at 07:58 +1000, Bojan Smojver wrote: > One more note here: if we go with this approach, this is almost > certainly something for APU 2.0 due to existing implementation > incompatibility. For instance, PostgreSQL driver uses %d to cast to > integer in SQL, but fetches a char* as an argument nonetheless. If we > were to implement a change in which an int* is expected with %d, > current code would break.
Now this got me thinking (I know, I shouldn't be doing this :-), because waiting for APR 2.0 probably means waiting for Apache 2.4 as well... Instead of introducing various types of pointers on C side and then using that in p[v]query/select, maybe we can stick to const char * instead, but encode other information into the string. For instance, something referred to as %b (blob, binary data) could be passed into p[v]query/select and fetched fromo apr_dbd_binary_get() as: length:column:table:payload ------ ------ ----- ------- ^ ^ ^ ^ | | | +-----------> binary data, length in size +------+------+-----------------> ascii Obviously, for most databases column and table could be omitted, reducing the thing to: length:::payload or even: length:payload With this approach we can: - keep binary compatibility - cater for Oracle "sing and dance" routine - keep passing strings around for everything, but most importantly the simple stuff (strings, integers, floats etc.), as we are doing now - get stuff back in this format from apr_dbd_binary_get() I know it's going to a bit of hassle to "pack" and "unpack" data, but we can have handy little functions (or even macros) for that, making the job much easier. In such a case, the "format identifiers" would have to be adjusted slightly, in order to preserve current meanings. The types would mostly have meaning on the SQL side and less on C side (i.e. everything would be picked up as const char *). Something like this: - %s - varchar - %S - text - %c - char - %C - unsigned char - %h - short - %H - unsigned short - %d - integer - %D - unsigned integer - %o - long - %O - unsigned long (big L has been taken by Oracle driver already!) - %q - quad (i.e. long long) - %Q - unsigned quad - %f - float - %F - double - %i - time - %a - date - %A - datetime - %t - timestamp - %T - timestamp with zone - %b - blob (only this one is encoded on C side as per above!) The above would be the only things we'd advertise in APU 1.3.x, so that people know they can rely on this. All other letters that are currently implemented differently (e.g. %L in Oracle driver), would be kept silently to avoid breaking things. Then in APR 2.0, we can do the fancy stuff with buckets, brigades and other goodies. <fire_proof_suit_on/> ;-) -- Bojan
