fukamachi / cl-dbi

Database independent interface for Common Lisp
206 stars 28 forks source link

Json Field Support #88

Open hauter opened 4 months ago

hauter commented 4 months ago

Select any records with Json field can produce the error:

245 is not defined as a value for enum type #<CFFI::FOREIGN-ENUM COM.HACKINGHAT.CL-MYSQL-SYSTEM::ENUM-FIELD-TYPES>.
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [RETRY] Retry SLY mREPL evaluation request.
 1: [*ABORT] Return to SLY's top level.
 2: [ABORT] abort thread (#<THREAD tid=5891 "sly-channel-1-mrepl-remote-1" RUNNING {7004F40803}>)

Backtrace:
 0: (CFFI::%FOREIGN-ENUM-KEYWORD #<CFFI::FOREIGN-ENUM COM.HACKINGHAT.CL-MYSQL-SYSTEM::ENUM-FIELD-TYPES> 245 :ERRORP T)
 1: ((:METHOD COM.HACKINGHAT.CL-MYSQL-SYSTEM::SET-FIELD-NAMES-AND-TYPES (COM.HACKINGHAT.CL-MYSQL-SYSTEM:CONNECTION)) #<COM.HACKINGHAT.CL-MYSQL-SYSTEM:CONNECTION {700976D5C3}>) [fast-method]
 2: ((:METHOD COM.HACKINGHAT.CL-MYSQL-SYSTEM:NEXT-RESULT-SET (COM.HACKINGHAT.CL-MYSQL-SYSTEM:CONNECTION)) #<COM.HACKINGHAT.CL-MYSQL-SYSTEM:CONNECTION {700976D5C3}> :DONT-RELEASE NIL :STORE NIL) [fast-meth..
 3: ((:METHOD DBI.DRIVER:EXECUTE-USING-CONNECTION (DBD.MYSQL:DBD-MYSQL-CONNECTION DBD.MYSQL:DBD-MYSQL-QUERY T)) #<DBD.MYSQL:DBD-MYSQL-CONNECTION {70093E0DB3}> #<DBD.MYSQL:DBD-MYSQL-QUERY {70085BC603}> ("1..
 4: (SELECT "select ext_info FROM xxxxx where xxxx = ? LIMIT 1" ("xxxx"))
 5: (SB-INT:SIMPLE-EVAL-IN-LEXENV (SELECT "select ext_info FROM driver_violation where violation_id = ? LIMIT 1" (QUOTE ("1214522242"))) #<NULL-LEXENV>)
 6: (EVAL (SELECT "select ext_info FROM driver_violation where violation_id = ? LIMIT 1" (QUOTE ("1214522242"))))
 7: ((LAMBDA NIL :IN SLYNK-MREPL::MREPL-EVAL-1))

CREATE TABLE `xxxxx` (
    -- ....
  `ext_info` json DEFAULT NULL
    --  ...
) ENGINE=InnoDB
;

Thank you.

hauter commented 4 months ago

The alternative solution is to use the CAST function, but it‘s indeed a bug that needs resolution.

SELECT CAST(ext_info AS CHAR) FROM xxxxx WHERE xxxx = ?
fukamachi commented 4 months ago

It's because of the lack of JSON support in cl-mysql. You may want to go to https://github.com/hackinghat/cl-mysql/issues/21.