Search code examples
javascriptnode.jsmariadbconnectorzerofill

MariaDB Connector Removing Leading Zeros on ZEROFILL fields


I've just upgraded from MySQL 5.7 to MariaDB 10.3 and one functionality difference has me stumped. I have an index field that is of the following type:

UserID | int(9) unsigned zerofill

If I execute the following query:

SELECT UserID FROM User WHERE UserID='000000003';

I get:

+-----------+
| UserID    |
+-----------+
| 000000003 |
+-----------+

If I use the MariaDB callback connector from Node.js I get the following:

[
        {
            "UserID": 3
        }
]

How do I prevent the MariaDB Connector/Node.js Callback API from stripping off the leading zeros from an index? Right now I understand that I can pad every instance of a index reference within my API after all my queries, but this just seems... inefficient.

Is there a better way? Thanks.


Solution

  • node.js driver automatically evaluate value type. Since that's an int, 3 is the expected value.

    If you explicitly want a string you can tell by sql, like query select cast (UserID AS CHAR) as UserID from User WHERE UserID='000000003';

    This will return

    [
            {
                "UserID": '000000003'
            }
    ]