Forum BigDB DatabaseArray of strings and Contains()

Discussion and help relating to the PlayerIO database solution, BigDB.

DatabaseArray of strings and Contains()

Postby complexitydesigns » July 11th, 2013, 2:17 am

It seems that if you have a DatabaseArray comprised of only strings Contains() will always return false? Is this unintended or is a workaround required?

This is on Unity fyi.

I ended up just using a DatabaseObject instead of an Array to achieve what I was going for.
complexitydesigns
 
Posts: 2
Joined: June 2nd, 2013, 2:00 am

Re: DatabaseArray of strings and Contains()

Postby Henrik » July 16th, 2013, 11:25 pm

Do you have a short code example that triggers the bug?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: DatabaseArray of strings and Contains()

Postby romeoordos » September 17th, 2013, 12:18 pm

I see this topic is dead but I had same problem and I have a solution. It can save some time for someone ;)

complexitydesigns tries to check if DatabaseArray contains some string with DatabaseArray.Contains() function. But if you'll check the documentation then you'll see that Contains() is used for other purpose. It checks if array contains property, and not value.

If you want to check the existance of some string value in DatabaseArray you can use LINQ expression in C#:

Code: Select all
public bool ContainsMember(string memberId)
{
    return dbArray.GetArray("members").IndexesAndValues.Count(kvp => (string) kvp.Value == memberId) > 0;
}
Last edited by romeoordos on September 18th, 2013, 7:41 am, edited 1 time in total.
romeoordos
Paid Member
 
Posts: 9
Joined: July 27th, 2013, 10:42 am

Re: DatabaseArray of strings and Contains()

Postby AdamW » September 17th, 2013, 8:44 pm

Hello Romeoordos,

Thanks for the update, I'll see if there's any follow-up in the docs to be made.

Take care,
Adam
Yahoo Games - Forums Moderator
User avatar
AdamW
 
Posts: 18
Joined: May 30th, 2013, 9:03 pm


Return to BigDB



cron