racquel icon indicating copy to clipboard operation
racquel copied to clipboard

`select-data-objects` doesn't work if `data-class` has required init variables.

Open kurinoku opened this issue 5 years ago • 1 comments

Here's an example:

#lang racket

(require racquel
         db)

(define conn (sqlite3-connect #:database 'memory))

(query-exec conn
            "create table test(a integer, b text, c text);")

(define test%
  (data-class object%
    (table-name "test")
    (init-column [a "a"]
                 [b #f "b"]
                 [c #f "c"])
    (super-new)))

(define test (new test% [a 12]))

(query-exec conn "insert into test(a, b, c) values (?, ?, ?);" 1 "hello" "world")

(query-rows conn "select * from test;")

(define tests (select-data-objects conn test%))

throws:

C:\Program Files\Racket\collects\racket\private\class-internal.rkt:1268:70: instantiate: no argument for required init variable
  init variable name: a
  instantiated class name: test%

The error is here. It should use make-object instead of new. For that I guess every time create-data-object gets called it will have to have another parameter where the row index of the columns gets specified, and also maybe limit class creation to not be able to use init or init-field? I'd like to help but I'm still trying to understand the code.

kurinoku avatar Aug 24 '20 00:08 kurinoku

I'll take a look at it. It's been a while since I've worked on this code, so it may take me a bit to familiarize myself again.

brown131 avatar Aug 24 '20 17:08 brown131