Hello,
I am new to the list, so please forgive me if this is a stupid user error.
Am I doing something wrong or is there a bug in how postmodern handles non-null fields?
Even very simple dao reports that slot is unbound although according table-description value may be NULL.
This is the message I get:
The slot TRX is unbound in the object #<KOE {11BA1751}>.
I run - Postgres 8.3 - OS X Leopard 10.5.2 - SBCL 1.0.7 - I installed latest postmodern today.
I attached output below.
Best regards,
Mikko Ahonen
--
(asdf:oos 'asdf:load-op :postmodern) (use-package :postmodern)
; loading system definition from ; /usr/local/lib/sbcl/site-systems/postmodern.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :POSTMODERN {11E033B9}> as POSTMODERN ; registering #<SYSTEM :POSTMODERN-TESTS {11F4BC91}> as POSTMODERN-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/bordeaux-threads.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM BORDEAUX-THREADS {120D0031}> as BORDEAUX-THREADS ; registering #<SYSTEM BORDEAUX-THREADS-TEST {11636C29}> as ; BORDEAUX-THREADS-TEST ; loading system definition from /usr/local/lib/sbcl/site-systems/s-sql.asd ; into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :S-SQL {117B6C01}> as S-SQL ; loading system definition from ; /usr/local/lib/sbcl/site-systems/simple-date.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :SIMPLE-DATE {1191A041}> as SIMPLE-DATE ; registering #<SYSTEM :SIMPLE-DATE-TESTS {11A4BFB1}> as SIMPLE-DATE-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/cl-postgres.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :CL-POSTGRES {11BDA379}> as CL-POSTGRES ; registering #<SYSTEM :CL-POSTGRES-TESTS {11D181D1}> as CL-POSTGRES-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/trivial-utf-8.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :TRIVIAL-UTF-8 {11E8E3A1}> as TRIVIAL-UTF-8 ; registering #<SYSTEM :TRIVIAL-UTF-8-TESTS {11FCC3B1}> as TRIVIAL-UTF-8-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/ieee-floats.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :IEEE-FLOATS {1214B319}> as IEEE-FLOATS ; registering #<SYSTEM :IEEE-FLOATS-TESTS {122CFC91}> as IEEE-FLOATS-TESTS ; loading system definition from /usr/local/lib/sbcl/site-systems/usocket.asd ; into #<PACKAGE "ASDF0"> ; registering #<SYSTEM USOCKET {11783E61}> as USOCKET ; loading system definition from ; /usr/local/lib/sbcl/site-systems/split-sequence.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :SPLIT-SEQUENCE {11938B69}> as SPLIT-SEQUENCE ; loading system definition from /usr/local/lib/sbcl/site-systems/md5.asd into ; #<PACKAGE "ASDF0"> ; registering #<SYSTEM MD5 {11ABD991}> as MD5 WARNING: Either there is no Bordeaux-threads support for your implementation, or your implementation does not support threads therefore some features may not work. Feel free to implement it, or bug one of the maintainers to do so if your lisp supports threads at all. STYLE-WARNING: implicitly creating new generic function SOCKET-ACCEPT NIL * T (defparameter *db* "foobar")
*DB* (defparameter *db-user* "mikko")
*DB-USER* (defparameter *db-pwd* "")
*DB-PWD* (defparameter *db-host* "localhost")
*DB-HOST* * (connect-toplevel *db* *db-user* *db-pwd* *db-host*)
(deftable koe () ((data-id :type integer :initarg :data-id :accessor data-id) (ver :type (or integer db-null) :initarg :ver :accessor ver) (trx :type (or integer db-null) :initarg :trx :accessor trx))
(:class-name koe) (:indices data-id))
* (drop-table 'koe)
NIL * (create-table 'koe) WARNING: Postgres warning: CREATE TABLE / PRIMARY KEY will create implicit index "koe_pkey" for table "koe"
NIL * (make-instance 'koe :data-id 1 :ver 3)
#<KOE {11B3EB71}> * (table-description 'koe)
(("data_id" "int4" NIL) ("ver" "int4" T) ("trx" "int4" T)) * (make-instance 'koe :data-id 1 :ver 3)
#<KOE {11BA1751}> * (save-dao *)
debugger invoked on a UNBOUND-SLOT: The slot TRX is unbound in the object #<KOE {11BA1751}>.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name): 0: [USE-VALUE ] Return a value as the slot-value. 1: [STORE-VALUE] Store and return a value as the slot-value. 2: [ABORT ] Exit debugger, returning to top level.
((SB-PCL::FAST-METHOD SLOT-UNBOUND (T T T)) #<unavailable argument> #<unavailable argument> #<unavailable argument> #<KOE {11BA1751}> TRX) 0] 2
If you want trx to be null by default, try changing the slot definition:
(trx :type (or integer db-null) :initarg :trx :accessor trx :initform nil)
HTH,
Ryan Davis Acceleration.net Director of Programming Services 2831 NW 41st street, suite B Gainesville, FL 32606
Office: 352-335-6500 x 124 Fax: 352-335-6506
Mikko Ahonen wrote:
Hello,
I am new to the list, so please forgive me if this is a stupid user error.
Am I doing something wrong or is there a bug in how postmodern handles non-null fields?
Even very simple dao reports that slot is unbound although according table-description value may be NULL.
This is the message I get:
The slot TRX is unbound in the object #<KOE {11BA1751}>.
I run
- Postgres 8.3
- OS X Leopard 10.5.2
- SBCL 1.0.7
- I installed latest postmodern today.
I attached output below.
Best regards,
Mikko Ahonen
--
(asdf:oos 'asdf:load-op :postmodern) (use-package :postmodern)
; loading system definition from ; /usr/local/lib/sbcl/site-systems/postmodern.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :POSTMODERN {11E033B9}> as POSTMODERN ; registering #<SYSTEM :POSTMODERN-TESTS {11F4BC91}> as POSTMODERN-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/bordeaux-threads.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM BORDEAUX-THREADS {120D0031}> as BORDEAUX-THREADS ; registering #<SYSTEM BORDEAUX-THREADS-TEST {11636C29}> as ; BORDEAUX-THREADS-TEST ; loading system definition from /usr/local/lib/sbcl/site-systems/s-sql.asd ; into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :S-SQL {117B6C01}> as S-SQL ; loading system definition from ; /usr/local/lib/sbcl/site-systems/simple-date.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :SIMPLE-DATE {1191A041}> as SIMPLE-DATE ; registering #<SYSTEM :SIMPLE-DATE-TESTS {11A4BFB1}> as SIMPLE-DATE-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/cl-postgres.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :CL-POSTGRES {11BDA379}> as CL-POSTGRES ; registering #<SYSTEM :CL-POSTGRES-TESTS {11D181D1}> as CL-POSTGRES-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/trivial-utf-8.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :TRIVIAL-UTF-8 {11E8E3A1}> as TRIVIAL-UTF-8 ; registering #<SYSTEM :TRIVIAL-UTF-8-TESTS {11FCC3B1}> as TRIVIAL-UTF-8-TESTS ; loading system definition from ; /usr/local/lib/sbcl/site-systems/ieee-floats.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :IEEE-FLOATS {1214B319}> as IEEE-FLOATS ; registering #<SYSTEM :IEEE-FLOATS-TESTS {122CFC91}> as IEEE-FLOATS-TESTS ; loading system definition from /usr/local/lib/sbcl/site-systems/usocket.asd ; into #<PACKAGE "ASDF0"> ; registering #<SYSTEM USOCKET {11783E61}> as USOCKET ; loading system definition from ; /usr/local/lib/sbcl/site-systems/split-sequence.asd into #<PACKAGE "ASDF0"> ; registering #<SYSTEM :SPLIT-SEQUENCE {11938B69}> as SPLIT-SEQUENCE ; loading system definition from /usr/local/lib/sbcl/site-systems/md5.asd into ; #<PACKAGE "ASDF0"> ; registering #<SYSTEM MD5 {11ABD991}> as MD5 WARNING: Either there is no Bordeaux-threads support for your implementation, or your implementation does not support threads therefore some features may not work. Feel free to implement it, or bug one of the maintainers to do so if your lisp supports threads at all. STYLE-WARNING: implicitly creating new generic function SOCKET-ACCEPT NIL
T (defparameter *db* "foobar")
*DB* (defparameter *db-user* "mikko")
*DB-USER* (defparameter *db-pwd* "")
*DB-PWD* (defparameter *db-host* "localhost")
*DB-HOST*
- (connect-toplevel *db* *db-user* *db-pwd* *db-host*)
(deftable koe () ((data-id :type integer :initarg :data-id :accessor data-id) (ver :type (or integer db-null) :initarg :ver :accessor ver) (trx :type (or integer db-null) :initarg :trx :accessor trx))
(:class-name koe) (:indices data-id))
- (drop-table 'koe)
NIL
- (create-table 'koe)
WARNING: Postgres warning: CREATE TABLE / PRIMARY KEY will create implicit index "koe_pkey" for table "koe"
NIL
- (make-instance 'koe :data-id 1 :ver 3)
#<KOE {11B3EB71}>
- (table-description 'koe)
(("data_id" "int4" NIL) ("ver" "int4" T) ("trx" "int4" T))
- (make-instance 'koe :data-id 1 :ver 3)
#<KOE {11BA1751}>
- (save-dao *)
debugger invoked on a UNBOUND-SLOT: The slot TRX is unbound in the object #<KOE {11BA1751}>.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name): 0: [USE-VALUE ] Return a value as the slot-value. 1: [STORE-VALUE] Store and return a value as the slot-value. 2: [ABORT ] Exit debugger, returning to top level.
((SB-PCL::FAST-METHOD SLOT-UNBOUND (T T T)) #<unavailable argument> #<unavailable argument> #<unavailable argument> #<KOE {11BA1751}> TRX) 0] 2 _______________________________________________ postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Hello Mikko,
As Ryan mentioned, you have to use (:or db-null integer) to specify a regular integer field, since it will default to "NOT NULL". Also, if you are just starting to use the library, it is probably a better idea to get the current code from the darcs repository -- I'm about to release a new version with a slightly changed interface, and one of the changes is that the defclass macro is replaced by a dao-class metaclass, which handles unbound slots in a much nicer way. The repository contains docs which are updated for that version, and is not expected to change much before the 1.10 release. (I don't usually break backwards compatibility, but there were a few issues that required cleaning up, so 1.10 will.)
On the subject of 1.10 -- has anyone apart from Attila tried the current code yet?
Cheers, Marijn
Hello,
Actually my definition had (:or integer db-null), but Ryan's suggestion made sense, as he recommended me to use :initform to define default NULL values for fields which I do not want to define manually.
I think just documenting this behavior is fine. If the doc would say something like "all fields must have value when saving object, if you want to have NULL value, please use :initform to set it to NULL by default" it would be OK.
Ryan's tip led me to the solution, but with a twist: "nil" should be ":null". "nil" is parsed (at least for SQL integers but probably others) into boolean value false, while ":null" to NULL.
I also had some problems with deftable with long (over 80 characters long) lines.
I will try the darcs version.
Thanks for the help!
Best regards,
Mikko Ahonen
On Tue, Mar 18, 2008 at 8:43 PM, Marijn Haverbeke marijnh@gmail.com wrote:
Hello Mikko,
As Ryan mentioned, you have to use (:or db-null integer) to specify a regular integer field, since it will default to "NOT NULL". Also, if you are just starting to use the library, it is probably a better idea to get the current code from the darcs repository -- I'm about to release a new version with a slightly changed interface, and one of the changes is that the defclass macro is replaced by a dao-class metaclass, which handles unbound slots in a much nicer way. The repository contains docs which are updated for that version, and is not expected to change much before the 1.10 release. (I don't usually break backwards compatibility, but there were a few issues that required cleaning up, so 1.10 will.)
On the subject of 1.10 -- has anyone apart from Attila tried the current code yet?
Cheers, Marijn
postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
postmodern-devel@common-lisp.net