Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integer limited to 7 characters? #8

Open
alexalouit opened this issue Dec 12, 2014 · 1 comment
Open

integer limited to 7 characters? #8

alexalouit opened this issue Dec 12, 2014 · 1 comment

Comments

@alexalouit
Copy link

Exemple environnement:

CREATE TABLE `temp` (
  `data` text,
  `index` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `temp` (`data`, `index`)
VALUES
    ('{\"entry1\":\"string1\", \"entry2\":2232372}',1),
    ('{\"entry1\":\"string1\", \"entry2\":22323721}',1),
    ('{\"entry1\":\"string2\", \"entry2\":\"22323721\"}',1);

SELECT * FROM `temp` WHERE `index` = '1' AND json_get(data, 'entry2') = 22323721 ;

Will return only string2, not the string1 with entry2(int).
With one less character, it works.
There is no way around this limitation?

@rajesh1158
Copy link

I exactly had this problem. I worked around it by saving all values except booleans in the json as strings. I used the below function to convert every integer to string before I save to database (it is in php):

function convertIntegersInArrayToStrings(&$arr) {
    foreach($arr as &$val) {
        if(is_array($val)) {
            convertIntegersInArrayToStrings($val);
        } else if(is_bool($val) === FALSE && preg_match('/^\d+$/', $val) == 1) {
            $val = strval($val);
        }
    }
}

Before passing my array to mysql for saving, I pass it through the above function to convert integers to string. This works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants