Working on it some more, I am more convinced that this is a bug. Since, you 
would not be able to simulate this problem if you have more than one column 
like so:
   ht=: Create__db 'tblTest';0 : 0
Field1 int
Field2 varchar
)
   Insert__db 'tblTest';<0;'a'
   Reads__db 'from tblTest'
+------+------+
|Field1|Field2|
+------+------+
|0     |a     |
+------+------+
   Insert__db 'tblTest';<0 1 ;<;:'aa bb'
   Reads__db 'from tblTest'
+------+------+
|Field1|Field2|
+------+------+
|0     |a     |
|0     |aa    |
|1     |bb    |
+------+------+

NB. Now we try to make insert fail:
   Insert__db 'tblTest';<'aa bb'
|Insert rows required items: 2, given items: 1: throw
|       throw msg
   Insert__db 'tblTest';<'aa'
|Insert rows required items: 2, given items: 1: throw
|       throw msg
   Reads__db 'from tblTest'
+------+------+
|Field1|Field2|
+------+------+
|0     |a     |
|0     |aa    |
|1     |bb    |
+------+------+
+------+------+
|Field1|Field2|
+------+------+
|0     |a     |
|0     |aa    |
|1     |bb    |
+------+------+
   Insert__db 'tblTest';<10;<;:'xy e4 dty'
|assertion failure: validate
|   1=#~.(#@".)&>'active';Tcolmap
   Reads__db 'from tblTest'
+------+------+
|Field1|Field2|
+------+------+
| 0    |a     |
| 0    |aa    |
| 1    |bb    |
|10    |xy    |
+------+------+
   
As you can see from above, the code was able to handle columns insert of 
different sizes by only handling the first "valid" rows. 


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Alex Rufon
Sent: Thursday, December 17, 2009 5:47 PM
To: Programming forum
Subject: [Jprogramming] JDB Error Handling Bug? (WAS: RE: Newbie JDB problem: 
inserting chars in a 1 column char table gives 'assertion failure')

I've been trying out Chris Collins code and I believe there may be a bug.  So 
here is my J session.
NB. =========================================================
NB. Start of J session
   load 'data/jdb'
   [ffd=: Open_jdb_ jpath '~temp'
+-+
|1|
+-+
   Drop__ffd 'testdb'
   [db=: Create__ffd 'testdb'
+-+
|2|
+-+
   ht=: Create__db 'tblVarChar';0 : 0
field1 varchar
)
   ht
+-+
|3|
+-+
   
NB. At this point, we know that my server locale is 1, my database locale is 2 
and the table 'tblVarChar' is in locale 3.
NB. I'm going to insert a sequence of data and read the table immediately
   Insert__db 'tblVarChar';'a'
   Read__db 'from tblVarChar'
+------+---+
|field1|+-+|
|      ||a||
|      |+-+|
+------+---+
   ;:'bb ccc dddd eeeee ffffff'
+--+---+----+-----+------+
|bb|ccc|dddd|eeeee|ffffff|
+--+---+----+-----+------+
   Insert__db 'tblVarChar';<<;:'bb ccc dddd eeeee ffffff'
   Read__db 'from tblVarChar'
+------+----------------------------+
|field1|+-+--+---+----+-----+------+|
|      ||a|bb|ccc|dddd|eeeee|ffffff||
|      |+-+--+---+----+-----+------+|
+------+----------------------------+
NB. Up to this point, everything is going well, not I am going to force the JDB 
Insert method to fail by inserting 
NB. data in a format that it did not expect
   Insert__db 'tblVarChar';<'zz'
|assertion failure: validate
|   1=#~.(#@".)&>'active';Tcolmap
   Read__db 'from tblVarChar'
|index error: readbase1
|       (rws{".)&.>cls

NB. End of J Session
NB. =========================================================

I believe that the data itself is not corrupted because the data can still be 
seen there (note that 'zz' was saved)
   c2__ht 
+-+--+---+----+-----+------+--+
|a|bb|ccc|dddd|eeeee|ffffff|zz|
+-+--+---+----+-----+------+--+
   
>From what I remember from the discussions, JDB is transactional ... is there a 
>way to rollback?

I feel that this should be considered a bug.

r/Alex
 

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of christopher collins
Sent: Thursday, December 17, 2009 2:12 PM
To: [email protected]
Subject: [Jprogramming] Newbie JDB problem: inserting chars in a 1 column char 
table gives 'assertion failure'

Thanks to all for your help, especially Mr. Lam.
Your response, Mr. Lam,  was very instructive.
I used your input to explore a bit more, with a couple of questions arising.

See the questions embedded below:

*****************************
load 'data/jdb'

ffd =: Open_jdb_ jpath , '~temp'

Drop__ffd 'testdb'
db =: Create__ffd 'testdb'

ht=: Create__db 'tblChar';0 : 0
c1 char
)

NB. JDB doc says a 'char' column is stored as a character matrix
NB. The next sentence works, even though it inserts a scalar, 'a'
NB. QUESTION: Is this contrary to the JDB doc?
Insert__db 'tblChar';'a'
]shape =. $'a'
NB. Inserts a list of shape 1
Insert__db 'tblChar';,'b'
]shape =. $ ,'b'
NB. Inserts a list of shape 3 1
Insert__db 'tblChar';,.'def'
]shape =. $ ,.'def'
NB. Inserts a list of shape 1 4
Insert__db 'tblChar';,:'ghih'
]shape =. $ ,:'ghih'
Insert__db 'tblChar';3 5 $'123457'
Insert__db 'tblChar';,:'012345678901234567890'
]shape=.$ ,:'012345678901234567890'
NB. A JDB 'char' column allows chars of varying lengths to be inserted
Insert__db 'tblChar';2 100$'1234567890'
Reads__db 'from tblChar'

NB. The insert below causes a failure
NB. After this the table can no longer be read.
NB. QUESTION: Is that behavior intended?
NB. If so, JDB seems a little fragile for the rough, unskilled hands
of newbies like me
NB. This insert, where '01' is a list of shape 2, fails even though an
insert of 'b', a list of shape 1 worked above.
NB. QUESTION: Is this behavior consistent in a way that I am not understanding?
Insert__db 'tblChar';'01'
Reads__db 'from tblChar'

Thanks again for the high quality help & instruction.
--chris--
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to