Hi Kay,

On Tue, Sep 01, 2009 at 03:50:34PM +0200, Kay Röpke wrote:
> /* flag is set to non-blocking */ /* [1] */
>
> drizzle_query("select sleep(10000)", result); /* [2] */
> something_expensive();
> drizzle_read_result(result);  /* [3] */
>
> The above is scenario A.
> Let's suppose someone comes along and changes it scenario B by changing 
> [1] above to blocking behavior (I suppose this flag is per-drizzle 
> struct).
> In that case, IIUC, [2] will both send the query and wait for all the  
> packets to return from the server before returning to its caller.
> Will [3] be a no-op then?

Yes, this would turn into a no-op, since the result structure can
track what it has done already.

> /* flag set to blocking */
> drizzle_query("select sleep(10000)", result);
> /* do something with result */
> /* note: no drizzle_read_result anywhere in the code! */
>
> now change the flag to non-blocking and your code will magically stop  
> working, without any indication of why that might be the case (ok,  
> result will be empty).

Yeah, this would break.

> in fact, now that i think about it, why does libdrizzle need the  
> blocking mode at all? IIUC (aka i might be wrong) all it does is:
>
> void drizzle_query(result, …) {
>       /* send query somehow */
>       if (blocking) {
>               drizzle_read_result(result);
>       }
> }

Yeah, this is basically what is happening.

> now my first argument applies again: let one function do one thing :)
>
> blocking usage would then translate to:
> drizzle_query("…", result);
> drizzle_read_result(result);
>
> while non-blocking would be:
> drizzle_query("…", result);
> something_expensive();
> drizzle_read_result(result);

Yes, this is much simpler, no behavior flags. This is where I was
leaning. :)

> no need for storing and checking a flag at all (of course this API is  
> unsuitable for streamed resultsets, since drizzle_read_result implies  
> seeing the entire set first).

Well, drizzle_result_read() is actually reading just the result header,
not the entire result set. drizzle_result_buffer() blocks until the
entire result set is in. With just the header, you can then stream
per row, field, or even chunks of fields.

Thanks for the input! I think this is more argument to adding an
extra function or two and keeping them simple. I think originally
I was trying to make some things a bit too easy/clever with some
behavior flags that in fact did just the opposite.

-Eric

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to