MySQL Forums
Forum List  »  Connector/ODBC

Re: How do I access JSON datatype from ODBC?
Posted by: Bogdan Degtyariov
Date: October 03, 2016 12:22AM

Hi Dann,

Unfortunately, Connector/ODBC has very limited support for JSON.
However, it still allows you to get JSON data from collections (that actually are tables in MySQL with two columns, _id and doc).

With ODBC API it will look as follows:

char buf[1024];
SQLINTEGER data_len = 0;

SQLExecDirect(hstmt, "SELECT doc FROM my_db.my_collection", SQL_NTS);
SQLGetData(hstmt, 1, SQL_C_BINARY, &buf, sizeof(buf), &data_len);

Also, note that with the binary data the JSON string will not be NULL-terminated. Therefore, it is essential to get the data_len and terminate the buffer like

buf[data_len] = 0;

Then it can be printed. The result would look as this:

{"_id": "5A1674BA04A12D1144544FD64089E9B8", "my_key": 222}

Options: ReplyQuote

Written By
Re: How do I access JSON datatype from ODBC?
October 03, 2016 12:22AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.