earth_distance_sql() with named tables

scott.mclewin - November 21, 2006 - 07:48
Project:Location
Version:4.7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I need to use earth_distance_sql() in a query that contains named tables and joins to the location table twice (one is in a db_rewrite_sql call from a different module).

The SQL emitted by the function assumes that the fields latitude and longitude will be unnamed. This patch allows for an optional table name to inject into the SQL and does so in a fully backward compatible way.

AttachmentSize
location_search_dist_sql.patch1.17 KB

#1

scott.mclewin - March 15, 2007 - 18:38

I remain interested in having this patch comitted. What additional information do you need from me?

#2

ankur - March 15, 2007 - 19:50
Status:reviewed & tested by the community» needs work

Hey Scott,

Are you trying to pass in a full table name, or a table alias? If an alias, then there is no need for the brackets. Also, we should write the patch in a way where the '.' between the table name (or alias) and the name of the column ('latitude' or 'longitude' in this case) is supplied by the code in this function rather than being passed as part of the tbl_prefix parameter.

Finally, instead calling the optional parameter $tbl_prefix, we should call it $table_alias if the parameter is intended to be an alias (which I think is the way to go) or just $table_name if the parameter is intended to be the table name.

W

#3

scott.mclewin - March 16, 2007 - 19:07

@ankur,

It is intended to be a table alias and I agree the name should be changed. I'll do that.

I'll also change the code to add the "." within the function.

As for the brackets {$tbl_prefix}, to be clear those are not appearing in the output string. While not I cannot be 100% sure from your comment, it seems you were reading those as literals being included in the output. They are not. It's a php nomenclature to allow a variable to be directly against another, which I did to allow the default value of $tbl_prefix ("") to do nothing while allowing an alias to be correctly incorporated. My apologies if I am needlessly going over something you already knew.

Scott

#4

scott.mclewin - March 16, 2007 - 21:51
Status:needs work» reviewed & tested by the community

Here is the patch rolled again with the changes you requested.

AttachmentSize
location_search_dist_sql_0.patch 1.67 KB

#5

ankur - March 16, 2007 - 23:53
Status:reviewed & tested by the community» fixed

Applied to DRUPAL-4-7 and DRUPAL-5.
Thanks for the patch.

#6

scott.mclewin - March 17, 2007 - 04:20

No problem. Thanks for committing it and the review.

#7

Anonymous - March 31, 2007 - 04:30
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.