1
//@abi action
    void testhand() {
        gamecurrents gamecurrenttable(_self, _self);
        auto existing = gamecurrenttable.find( _self ); 
        if(existing == gamecurrenttable.end()) { 
            gamecurrenttable.emplace(_self,[&](auto& thisrow)
            {
                thisrow.account = _self;
                thisrow.hand = 'a'; // DO NOT WORK
                thisrow.version = 1;
            });
        }else{
            eosio::print( "Edit here, ", hand );
            gamecurrenttable.modify( existing, 0,[&](auto& thisrow){
                thisrow.hand = "";  // WORK !!
                thisrow.version = 2;
            });
        }
    }

First I run the above action.

 ./cleos push action (myeosid) testhand '[]' -p (myeosid)

After than, I fetch the row

cleos get table (myeosid) (myeosid) gamecurrent

error occured

Error 3015013: Unpack data exception
Error Details:
Unable to unpack built-in type 'string' while processing 'gamecurrent.hand' read datastream of length 32 over by -4

But when I put "" data, it works. (when I run above test action again. it will update data by "")

     "rows": [{
      "account": (myeosid),
      "price": "0.0000 SYS",
      "version": 2,
      "count": 0,
      "hand": "",
      "date": 0
    }
  ],
  "more": false

the struct is

/// @abi table gamecurrent i64
    struct gamecurrent{
        account_name account;
        asset price;
        uint8_t version;
        string hand;
        ..
        uint64_t primary_key() const { return account;}
        EOSLIB_SERIALIZE(gamecurrent,(account)(price)(version)(hand)..)
    };
1

I have tried your code and i also have coded in updated version of eosio compiler i.e, eosio.cdt my code to modify table data is look like this

void tablecheck::updatedata ( capi_name user , string name )
{
    require_auth( _self );// requires authorization of contract owner
    checktb ctbl(_self, user);
    auto it = ctbl.find(user);

    // adding account name to userstats table
    ctbl.modify(it,_self, [&](auto &p) {
            p.name = "z";

    });
}

Table structure is like

    struct [[eosio::table, eosio::contract("tablecheck")]]
    checktbl {
        capi_name user;
        string name;


        capi_name primary_key() const { return user; }
        EOSLIB_SERIALIZE( checktbl ,(user) (name)  );
    };

And i executed this command (tablecheck12 is my account name)

cleos get table tablecheck12 tablecheck12 checktbl

I got this result

{
  "rows": [{
      "user": "tablecheck12",
      "name": "z"
    }
  ],
  "more": false
}

So it works for me in new compiler you got error may be because of compiler you can try it out using eosio.cdt

| improve this answer | |
  • Right. The compiler was updated. I did not test on that. – Lawyer Kenny Dec 26 '18 at 9:10
0

I'm not the C++ expert but I think you are trying to use the wrong data type in the string.

If you use a single quotes 'a' - that is a char value and not a string. You probably meant a string with a single character in it. Try using double quotes "a".

| improve this answer | |
  • Thank your for your reply. I tried double quotation again ( thisrow.hand = "a"; ) But same result. – Lawyer Kenny Dec 26 '18 at 5:14
-1

Remove EOSLIB_SERIALIZE(gamecurrent,(account)(price)(version)(hand)..), and then redeploy it for another account.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.