Zoclee / xojo-mongodb

MongoDB driver for Xojo.
15 stars 5 forks source link

Single quote issue #3

Closed ghost closed 10 years ago

ghost commented 10 years ago

The current driver is getting troubles with single quote.

Here some examples:

db.driver.insert({"test","me"}); db.driver.find({}); {"_id":"527e1d5b6dfb532dda88e720","test":"me"}

The client provides double quotes to the key and the value: the inserted document is found unmodified - so far so good.

db.driver.insert({test:"me"}); db.driver.find({}); {"_id":"527e1c136dfb532dda88e71e","test":"me"}

This one is fine too - in pure JSON the key should be quoted but this is not a requirement for MongoDB : it works fine too.

db.driver.insert({'test':'me'}); db.driver.find({}); {"_id":"527e1c876dfb532dda88e71f","'test'":0}

Here come the troubles: there is an issue with single quotes - which are common practice for MongoDB: 1 - the single quote was inserted around the key string 2 - the value was set to 0

Here you'll have 2 options:

1 - single quote are not supported by this driver: in that case you should remove them before inserting

2 - single quote are suppored by this driver: in that case you should replace them to double quote before inserting

Side issue but probably the same: from my testing you don't escape single quote and the like before inserting a document in collection:

db.driver.insert({test,"let's go"})

will raise an OutOfBound exception in encodeObject() method.

alwyn1024 commented 10 years ago

I think option 2 is the best option... supporting single quotes. If MongoDB supports single quotes, it only makes sense to develop the driver consistent with MongoDB practices. Looking into this.

alwyn1024 commented 10 years ago

This bug is fixed, and the latest version of BSONSerializer is comitted.

ghost commented 10 years ago

I need to send you a xojo file: how could I do that?

alwyn1024 commented 10 years ago

You can commit your file directly into git if you want, or if it's easier... you can send the file as an email attachment to mail@chessconquest.com.

alwyn1024 commented 10 years ago

I've also created a shared DropBox folder (sent you an invite via email), to make file sharing easy.