Store a complex hash in Apache::Sessions:MySQL session












1















So, I'm trying to store a decoded JSON object into a tied apache session. This is my code:



    $url="https://apilink";

$content = get($url);
die "Can't Get $url" if (! defined $content);

$jsonOb = decode_json($content);
%aprecords = %$jsonOb;

#Push the jsonOb in the session
$session{apirecords} = %aprecords ;


$session{apirecords} does not store the %aprecords reference. Although, when I substitute the statement to $session{apirecords} = %jsonOb ; , it stores apirecords in the sessions table but the reference to %jsonOb has no values in it.



PS:
I have tried the following and none of them seem to work:
1) $session{apirecords} = %$jsonOb ;
2) $session{apirecords} = { %aprecords } ;



JSON object is perfectly well structured.



Code for tying a session:



  tie %session, "Apache::Session::MySQL", $sessionID, 
{
Handle => $dbObject,
LockHandle => $dbObject,
TableName => 'sessions',
};

#If a session ID doesn't exist, create a new session and get new session ID
if (!defined ($sessionID)){
$sessionID = $session{_session_id};
$session{count}=0;
}


A helping hand would be much much appreciated!



JSON Sample: https://jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943










share|improve this question

























  • Let's try and narrow down the issue. If you store a simple scalar value instead of a json data structure, do you meet the same issue or you are able to then retrieve the data ?

    – GMB
    Nov 26 '18 at 13:05











  • @GMB yes, if I say $session{apirecords} = "hello"; it does store "hello" as an entry. When I change it to $session{apirecords} = "$content"; it doesn't store the encoded json held by $content

    – Kay
    Nov 26 '18 at 18:47











  • Allright, then what happens if you store a simple hash reference, like $session{api_records} = { hello => "world" }; Are you able to recover it afterwards ? Also, can you show us what the JSON data looks like before you store it, using Data::Dumper for example ?

    – GMB
    Nov 26 '18 at 19:50











  • Okay so, I tried $session{apirecords} = { hello => "world" }; and then I tried to retrieve it using %helloOb = %{$session{apirecords}}; print $helloOb{hello}; The result was: world , which means it worked! The JSON looks like: jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943

    – Kay
    Nov 26 '18 at 23:07













  • OK thanks.That's quite a big JSON object. What is the type and size of the database field where you try to store it ? Maybe you JSON just can't fit in the storage

    – GMB
    Nov 26 '18 at 23:11
















1















So, I'm trying to store a decoded JSON object into a tied apache session. This is my code:



    $url="https://apilink";

$content = get($url);
die "Can't Get $url" if (! defined $content);

$jsonOb = decode_json($content);
%aprecords = %$jsonOb;

#Push the jsonOb in the session
$session{apirecords} = %aprecords ;


$session{apirecords} does not store the %aprecords reference. Although, when I substitute the statement to $session{apirecords} = %jsonOb ; , it stores apirecords in the sessions table but the reference to %jsonOb has no values in it.



PS:
I have tried the following and none of them seem to work:
1) $session{apirecords} = %$jsonOb ;
2) $session{apirecords} = { %aprecords } ;



JSON object is perfectly well structured.



Code for tying a session:



  tie %session, "Apache::Session::MySQL", $sessionID, 
{
Handle => $dbObject,
LockHandle => $dbObject,
TableName => 'sessions',
};

#If a session ID doesn't exist, create a new session and get new session ID
if (!defined ($sessionID)){
$sessionID = $session{_session_id};
$session{count}=0;
}


A helping hand would be much much appreciated!



JSON Sample: https://jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943










share|improve this question

























  • Let's try and narrow down the issue. If you store a simple scalar value instead of a json data structure, do you meet the same issue or you are able to then retrieve the data ?

    – GMB
    Nov 26 '18 at 13:05











  • @GMB yes, if I say $session{apirecords} = "hello"; it does store "hello" as an entry. When I change it to $session{apirecords} = "$content"; it doesn't store the encoded json held by $content

    – Kay
    Nov 26 '18 at 18:47











  • Allright, then what happens if you store a simple hash reference, like $session{api_records} = { hello => "world" }; Are you able to recover it afterwards ? Also, can you show us what the JSON data looks like before you store it, using Data::Dumper for example ?

    – GMB
    Nov 26 '18 at 19:50











  • Okay so, I tried $session{apirecords} = { hello => "world" }; and then I tried to retrieve it using %helloOb = %{$session{apirecords}}; print $helloOb{hello}; The result was: world , which means it worked! The JSON looks like: jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943

    – Kay
    Nov 26 '18 at 23:07













  • OK thanks.That's quite a big JSON object. What is the type and size of the database field where you try to store it ? Maybe you JSON just can't fit in the storage

    – GMB
    Nov 26 '18 at 23:11














1












1








1








So, I'm trying to store a decoded JSON object into a tied apache session. This is my code:



    $url="https://apilink";

$content = get($url);
die "Can't Get $url" if (! defined $content);

$jsonOb = decode_json($content);
%aprecords = %$jsonOb;

#Push the jsonOb in the session
$session{apirecords} = %aprecords ;


$session{apirecords} does not store the %aprecords reference. Although, when I substitute the statement to $session{apirecords} = %jsonOb ; , it stores apirecords in the sessions table but the reference to %jsonOb has no values in it.



PS:
I have tried the following and none of them seem to work:
1) $session{apirecords} = %$jsonOb ;
2) $session{apirecords} = { %aprecords } ;



JSON object is perfectly well structured.



Code for tying a session:



  tie %session, "Apache::Session::MySQL", $sessionID, 
{
Handle => $dbObject,
LockHandle => $dbObject,
TableName => 'sessions',
};

#If a session ID doesn't exist, create a new session and get new session ID
if (!defined ($sessionID)){
$sessionID = $session{_session_id};
$session{count}=0;
}


A helping hand would be much much appreciated!



JSON Sample: https://jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943










share|improve this question
















So, I'm trying to store a decoded JSON object into a tied apache session. This is my code:



    $url="https://apilink";

$content = get($url);
die "Can't Get $url" if (! defined $content);

$jsonOb = decode_json($content);
%aprecords = %$jsonOb;

#Push the jsonOb in the session
$session{apirecords} = %aprecords ;


$session{apirecords} does not store the %aprecords reference. Although, when I substitute the statement to $session{apirecords} = %jsonOb ; , it stores apirecords in the sessions table but the reference to %jsonOb has no values in it.



PS:
I have tried the following and none of them seem to work:
1) $session{apirecords} = %$jsonOb ;
2) $session{apirecords} = { %aprecords } ;



JSON object is perfectly well structured.



Code for tying a session:



  tie %session, "Apache::Session::MySQL", $sessionID, 
{
Handle => $dbObject,
LockHandle => $dbObject,
TableName => 'sessions',
};

#If a session ID doesn't exist, create a new session and get new session ID
if (!defined ($sessionID)){
$sessionID = $session{_session_id};
$session{count}=0;
}


A helping hand would be much much appreciated!



JSON Sample: https://jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943







mysql json apache perl session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 22:54







Kay

















asked Nov 26 '18 at 5:08









KayKay

63




63













  • Let's try and narrow down the issue. If you store a simple scalar value instead of a json data structure, do you meet the same issue or you are able to then retrieve the data ?

    – GMB
    Nov 26 '18 at 13:05











  • @GMB yes, if I say $session{apirecords} = "hello"; it does store "hello" as an entry. When I change it to $session{apirecords} = "$content"; it doesn't store the encoded json held by $content

    – Kay
    Nov 26 '18 at 18:47











  • Allright, then what happens if you store a simple hash reference, like $session{api_records} = { hello => "world" }; Are you able to recover it afterwards ? Also, can you show us what the JSON data looks like before you store it, using Data::Dumper for example ?

    – GMB
    Nov 26 '18 at 19:50











  • Okay so, I tried $session{apirecords} = { hello => "world" }; and then I tried to retrieve it using %helloOb = %{$session{apirecords}}; print $helloOb{hello}; The result was: world , which means it worked! The JSON looks like: jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943

    – Kay
    Nov 26 '18 at 23:07













  • OK thanks.That's quite a big JSON object. What is the type and size of the database field where you try to store it ? Maybe you JSON just can't fit in the storage

    – GMB
    Nov 26 '18 at 23:11



















  • Let's try and narrow down the issue. If you store a simple scalar value instead of a json data structure, do you meet the same issue or you are able to then retrieve the data ?

    – GMB
    Nov 26 '18 at 13:05











  • @GMB yes, if I say $session{apirecords} = "hello"; it does store "hello" as an entry. When I change it to $session{apirecords} = "$content"; it doesn't store the encoded json held by $content

    – Kay
    Nov 26 '18 at 18:47











  • Allright, then what happens if you store a simple hash reference, like $session{api_records} = { hello => "world" }; Are you able to recover it afterwards ? Also, can you show us what the JSON data looks like before you store it, using Data::Dumper for example ?

    – GMB
    Nov 26 '18 at 19:50











  • Okay so, I tried $session{apirecords} = { hello => "world" }; and then I tried to retrieve it using %helloOb = %{$session{apirecords}}; print $helloOb{hello}; The result was: world , which means it worked! The JSON looks like: jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943

    – Kay
    Nov 26 '18 at 23:07













  • OK thanks.That's quite a big JSON object. What is the type and size of the database field where you try to store it ? Maybe you JSON just can't fit in the storage

    – GMB
    Nov 26 '18 at 23:11

















Let's try and narrow down the issue. If you store a simple scalar value instead of a json data structure, do you meet the same issue or you are able to then retrieve the data ?

– GMB
Nov 26 '18 at 13:05





Let's try and narrow down the issue. If you store a simple scalar value instead of a json data structure, do you meet the same issue or you are able to then retrieve the data ?

– GMB
Nov 26 '18 at 13:05













@GMB yes, if I say $session{apirecords} = "hello"; it does store "hello" as an entry. When I change it to $session{apirecords} = "$content"; it doesn't store the encoded json held by $content

– Kay
Nov 26 '18 at 18:47





@GMB yes, if I say $session{apirecords} = "hello"; it does store "hello" as an entry. When I change it to $session{apirecords} = "$content"; it doesn't store the encoded json held by $content

– Kay
Nov 26 '18 at 18:47













Allright, then what happens if you store a simple hash reference, like $session{api_records} = { hello => "world" }; Are you able to recover it afterwards ? Also, can you show us what the JSON data looks like before you store it, using Data::Dumper for example ?

– GMB
Nov 26 '18 at 19:50





Allright, then what happens if you store a simple hash reference, like $session{api_records} = { hello => "world" }; Are you able to recover it afterwards ? Also, can you show us what the JSON data looks like before you store it, using Data::Dumper for example ?

– GMB
Nov 26 '18 at 19:50













Okay so, I tried $session{apirecords} = { hello => "world" }; and then I tried to retrieve it using %helloOb = %{$session{apirecords}}; print $helloOb{hello}; The result was: world , which means it worked! The JSON looks like: jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943

– Kay
Nov 26 '18 at 23:07







Okay so, I tried $session{apirecords} = { hello => "world" }; and then I tried to retrieve it using %helloOb = %{$session{apirecords}}; print $helloOb{hello}; The result was: world , which means it worked! The JSON looks like: jsonblob.com/feed3bba-f1cd-11e8-9450-2904e8ecf943

– Kay
Nov 26 '18 at 23:07















OK thanks.That's quite a big JSON object. What is the type and size of the database field where you try to store it ? Maybe you JSON just can't fit in the storage

– GMB
Nov 26 '18 at 23:11





OK thanks.That's quite a big JSON object. What is the type and size of the database field where you try to store it ? Maybe you JSON just can't fit in the storage

– GMB
Nov 26 '18 at 23:11












1 Answer
1






active

oldest

votes


















0














As pointed out by GMB. The blob size(64 KB) wasn't big enough for the JSON object.
The solution is to change blob datatype to mediumblob .






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475054%2fstore-a-complex-hash-in-apachesessionsmysql-session%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As pointed out by GMB. The blob size(64 KB) wasn't big enough for the JSON object.
    The solution is to change blob datatype to mediumblob .






    share|improve this answer




























      0














      As pointed out by GMB. The blob size(64 KB) wasn't big enough for the JSON object.
      The solution is to change blob datatype to mediumblob .






      share|improve this answer


























        0












        0








        0







        As pointed out by GMB. The blob size(64 KB) wasn't big enough for the JSON object.
        The solution is to change blob datatype to mediumblob .






        share|improve this answer













        As pointed out by GMB. The blob size(64 KB) wasn't big enough for the JSON object.
        The solution is to change blob datatype to mediumblob .







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 30 '18 at 16:07









        KayKay

        63




        63
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475054%2fstore-a-complex-hash-in-apachesessionsmysql-session%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen