Recent

Author Topic: No support for JSON type with MySQL 8 ?  (Read 510 times)

MarcP

  • New Member
  • *
  • Posts: 21
No support for JSON type with MySQL 8 ?
« on: June 03, 2024, 08:10:26 am »
Hi,
With FPC version 3.2.2+dfsg-32 I'm connecting to a MySQL 8 database, however it seems to ignore a field if it's type is JSON. ( https://dev.mysql.com/doc/refman/8.0/en/json.html )
Accessing the field's name with query.FieldByName('MyJSONData').AsString results in a "field not found" exception.
Listing all the fields in a request like this :

Code: Pascal  [Select][+][-]
  1. Query.SQL.Text := 'SELECT * FROM MyTable';
  2.     Query.Open;
  3.     try
  4.       for i := 0 to Query.FieldCount - 1 do
  5.         WriteLn('Field ', i + 1, ': ', Query.Fields[i].FieldName);
  6.     finally
  7.       Query.Close;
  8.     end;

Will just ignore the JSON one.
Is support planned, even if working only with a .AsString ?

(If other people run into the same issue, I was able to get my data with this, but it's not pretty) :
Code: SQL  [Select][+][-]
  1. SELECT JSON_UNQUOTE(JSON_EXTRACT(JSONData, "$")) AS JSONData

Thanks for any help !

Zvoni

  • Hero Member
  • *****
  • Posts: 2620
Re: No support for JSON type with MySQL 8 ?
« Reply #1 on: June 03, 2024, 08:51:38 am »
As far as i understood the official MySQL-Docs:
Probably no support planned, since even MySQL doesn't ship an "official" JSON-Datatype when calling "mysql_fetch_field_direct"
https://dev.mysql.com/doc/c-api/8.0/en/c-api-data-structures.html

https://dev.mysql.com/doc/refman/8.4/en/json.html
Quote
Optimized storage format. JSON documents stored in JSON columns are converted to an internal format that permits quick read access to document elements. When the server later must read a JSON value stored in this binary format, the value need not be parsed from a text representation. The binary format is structured to enable the server to look up subobjects or nested values directly by key or array index without reading all values before or after them in the document.

That said: It's still a guess on my side without being able to actually directly test/debug what mysql_fetch_field_direct actually returns
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018