Skip to content

ER_SP_DOES_NOT_EXIST: FUNCTION users.AsText does not exist #4715

Closed

Description

@zhfish
mysql> select `users`.AsText(`location`) from users;
FUNCTION users.AsText does not exist
mysql> select AsText(`location`) from users;
+--------------------+
| AsText(`location`) |
+--------------------+
| POINT(10 10)       |
| POINT(10 10)       |
| POINT(10 10)       |
+--------------------+
3 rows in set (0.05 sec)

could i not use users default ?

Activity

  1. zhfish commented on Oct 23, 2015

    @zhfish
    Author
    select AsText(`users`.`location`) from users;
    

    is right

  2. janmeier commented on Oct 23, 2015

    @janmeier
    Member

    Can you please show the actual sequelize code that produces the issue?

  3. zhfish commented on Oct 23, 2015

    @zhfish
    Author
    var user = yield connect.users.findOne({
            where:{
                userName: userLogin.userName
            },
        });
    
  4. janmeier commented on Oct 23, 2015

    @janmeier
    Member

    And the model definitons, and some actual data?

  5. zhfish commented on Oct 23, 2015

    @zhfish
    Author

    model

    /* jshint indent: 2 */
    
    module.exports = function(sequelize, DataTypes) {
      return sequelize.define('users', {
        ID: {
          type: 'CHAR(36)',
          allowNull: false,
          defaultValue: '',
          primaryKey: true
        },
        userName: {
          type: DataTypes.STRING,
          allowNull: true
        },
        password: {
          type: DataTypes.STRING,
          allowNull: true
        },
        location: {
          type: DataTypes.GEOMETRY,
          allowNull: true
        }
      });
    };
    
    

    data

    +--------------------------------------+-------------+--------------------------------------------------------------+----------------------------+
    | ID                                   | username    | password                                                     | AsText(`users`.`location`) |
    +--------------------------------------+-------------+--------------------------------------------------------------+----------------------------+
    | 09c20a66-e4c5-4ecd-b8d7-567559847827 | 13800138000 | $2a$10$c9gmMhN4L63K1rmSF4poauzELud8X6MumK./efE/I32mxmo8npeNe | POINT(10 10)               |
    | 55d2d8e5-855f-4bdd-b374-b540cd8ec288 | 13800138001 | $2a$10$Vge6nXgY6jw5D4HzeuekoOimF80wSrszkyOCH7vXY2ffgK0qWgsNq | POINT(10 10)               |
    | b71ee44e-87a1-4678-b241-081a206d7e80 | 13800138002 | $2a$10$J.zrGp8Vy28jvbxkwaNHqeY.iRc9tOhrRmqUdaCxqjeFv7Soc0Nuq | POINT(10 10)               |
    +--------------------------------------+-------------+--------------------------------------------------------------+----------------------------+
    3 rows in set (0.03 sec)
    
    
  6. mickhansen commented on Oct 23, 2015

    @mickhansen
    Contributor

    @zhfish Please add the entire find call. (The AsText function call in particular)

  7. zhfish commented on Oct 23, 2015

    @zhfish
    Author

    i won't call asText directly,
    geometry for mysql do it

  8. zhfish commented on Oct 24, 2015

    @zhfish
    Author

    i try to fix it
    i'm sorry ,i don't understand how to write unit test

  9. mickhansen commented on Oct 25, 2015

    @mickhansen
    Contributor

    Please include the full query called that errors and it would be helpfull to have a SSCCE.
    You can check out the test/ folder for ways to write test cases, specifically look for the geometry tests.

  10. alxarch commented on Nov 6, 2015

    @alxarch

    The issue is more complex than the solution the proposed patch gives.
    This occurs on models that have a GEOMETRY column when used in conjunction
    with an include option. The abstract query writer for tries to prefix column names with table names for include to work properly but the GEOMETRY type uses selectGeometry() which in mysql uses a function call (AsText(column)).

    Things are even worse if the table with the GEOMETRY column is not the primary table. Then geometrySelect() is not called at all, returning the blob as column value.

    Currently GEOMETRY type is broken for the inlcude option. A proper solution requires checking for GEOMETRY columns in more places in selectQuery and passing the mainTableAs as an option to geometrySelect so it can prefix column names appropriately.

    Also a more general solution would require a refactor to handle function calling attributes in more gracefully instead of filling the code up with if (isGeometrySelect(attr)) { ... because every function-calling custom column will require special treatment.

  11. janmeier commented on Nov 6, 2015

    @janmeier
    Member

    @alxarch Agreed, thats why the proposed PR has not been merged yet - the solution is too simple, and it includes no tests :(

    It would be a great help if you could provide those test cases :)

  12. alxarch commented on Nov 6, 2015

    @alxarch

    @janmeier I browsed through the tests for mysql query-generator but there is nothing that tests the include option. (Although it influences the behavior of selectQuery substancially) Is there some place else I should add tests? Having tests for include only for GEOMETRY columns is pointless. I could provide examples of failing combinations of define('Foo', {blah..}) and Foo.findAll({where: {blah...}, include{blah...}) if that's what you mean. Otherwise I'll need some guidance for writing the appropriate tests

  13. alxarch commented on Nov 6, 2015

    @alxarch

    @janmeier there seems to exist such a function that it's docstring says it handles function attributes called query(). But the code doesn't handle the {fn:'foo'} case. I could start from there for a patch.

  14. janmeier commented on Nov 6, 2015

    @janmeier
    Member

    Those tests are old - we are hoping to migrate them at some point. Unit tests for include sql are here https://github.com/sequelize/sequelize/blob/master/test/unit/sql/select.test.js

    Which function are you referring to?

  15. alxarch commented on Nov 6, 2015

    @alxarch

    I found dialects/abstract/QueryGenerator.quote(). As i look through the code, I see that quoting of attributes is inconsistent. At some places names are quoted properly with backticks but some cases the names are joined by . without quoting the parts. I am trying to add the fn case to solve the geometry issue by returning an {fn: 'asText', cols: ['foo']} object from selectGeometry().

  16. alxarch commented on Nov 7, 2015

    @alxarch

    @janmeier I added a working solution that passes two simple inclusion tests (primary and secondary table).

  17. janmeier commented on Dec 4, 2015

    @janmeier
    Member

    We no longer use axText when selecting geometry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions