Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Gdn::SQL Changing Up my Select query [RESOLVED]

odannycodannyc New
edited March 2016 in Vanilla 2.0 - 2.8

I'm trying to do this:

$Sql->select("findDistance(addresslatitude,addresslongitude, 34.11111111 -100.00000001) distance");

findDistance is a function inside of mysql I created, so that works just fine.

The only problem I'm having is, that select string is throwing an error with :

Incorrect parameters in the call to stored function 'findDistance'

And right below that I'm seeing it changes it to this:

'select *, findDistance(addresslatitude, addresslongitude, 34.1111 as 1111, -118.3695699) as distance

The problem is this: 34.1111 as 1111

Anyone have an idea on how to fix this?

Comments

  • Options
    odannycodannyc New
    edited March 2016

    @R_J @hgtonight ,

    Any idea? I tried looking into class.sqldriver.php but didn't want to mess with it.

    EDIT:
    This is the code that seems to be giving decimals in select method aliases, might be a bug?

    if ($Alias == '' || ($Count > 1 && $i > 0)) {
    if (preg_match('/^([^\s]+)\s+(?:as\s+)??([^]+)?$/', $Field, $Matches) > 0) {
    // This is an explicit alias in the select clause.
    $Field = $Matches[1];
    $Alias = $Matches[2];
    } elseif (preg_match('/^[^.]+.?([^`]+)?$/', $Field, $Matches) > 0) {
    // This is an alias from the field name.
    $Alias = $Matches[1];
    } else {
    $Alias = '';
    }
    // Make sure we aren't selecting * as an alias.
    if ($Alias == '*') {
    $Alias = '';
    }
    }

  • Options

    NEVERMIND,

    Found the solution:

    $Sql->select("AddressLatitude,AddressLongitude,{$Lat},{$Lng}", 'findDistance', 'distance');

    Turns out that select takes in 3 parameters.
    The second is the function you want to wrap the first parameter in and the third parameter is the alias.

  • Options
    subdreamersubdreamer San Jose, CA

    Awesome, glad you found the answer to your own question. :)

Sign In or Register to comment.