At 4:07 PM +0000 1/12/04, Harry Jackson wrote:
Dan Sugalski wrote:

Well...


What I'd like, I think, is something simple and straightforward. Right now we've got to fetch each column for each row one by one, which is a pain in the neck if you want to get a full row back. Having a fetchrow that returned an Array with the value for column one in the 0th slot, column 2 in the 1st slot and so on would be about 80% of the solution.

I have done this part.



Having a fetchrow_hash that returned a Hash where the keys are the column names and the values are the column values would be most of the rest.

I read somewhere that accessing a hash was slightly slower than accessing and array which is one reason why I never used it. The other reason is that if I name the fileds in the hash then the user needs to know the names to access them or perform some magic to get them. With an array they come out in the order they are aksed for.

Definitely. However... Having seen code in production, generally the fields aren't changeable and are known at compile-time, or folks are writing generic code (for better or worse). In the first case people use hash access because they know there's a "name" and "city" field in the results, and in the second case they're iterating across the keys and pulling out values.


Since folks are going to wrap the results in a hash regardless of whether it's a good idea or not (not going there... :) we might as well have it in at the very lowest level where we can get the information most efficiently.

Another reason not to use the hash method above is that you are moving column names around that will not change throughout the transaction (is this not more bulky than using arrays). Should we not return the names and types first and then subsequent rows in arrays indexed in order of retrieval.

I like this method becasue thats how I have already done it ;-) just being biased.

That works too. If the information's available someone'll build what they want. Whichever way you're comfortable with. (Though given my preferences, I'd add in the hash fetch version as part of the low-level interface)


--
                                        Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to