> what I was looking for. I am extending and enhancing the class
> significantly, so to maintain backward compatibility, I have decided
> to create a new class "FILE.CLS" based on "DICT.TOOLS.CLS" that has
> all of the functionality of DICT.TOOLS.CLS and then some. I also
> fixed some bugs in "DICT.TOOLS.CLS". Here is what I've done so far
> (if you're not familiar w/ DICT.TOOLS.CLS, please look at it before
> continuing):
>
Gary,
I just reread your first paragraph and totally missed a tidbit. I
wouldn't worry too much about backwards compat at this point. It's a
work-in-progress and the Wiki states that under the "wishlist" page. The
only way you can deploy the class is to grab the code from the dev
branch using SVN. If you don't maintain the properties or methods that
are there, then just document it on the list so that everyone knows
what's going to change at commit time.
I would post a poll on class name before digging too deeply into
application test code. FILE.CLS is a bit general for my taste.
DICT.TOOLS.CLS is specific
enough to not step on toes later but it's general enough to encompass
everything dictionary<=>data related. It can be inherited into parent
classes and extended without fear of class name collision or confusion.
I'm not sure if you're planning on doing that or if you are going to
replace the entire class.
If you are going to create something called FILE.CLS then normal
file I/O methods and properties should be applicable. I.E. include
attribute-oriented read/write/readseq/etc methods and plug the
DICT.TOOLS.CLS stuff in along side it. This would be a great time to
toss in automatic operations like making data diffs available between
read/write calls and laying out an I/O user plug-in structure so that
SQL and other external databases can be replicated/compared with one
local data write/read. If a developer doesn't want all of that fluff to
happen, then the plain-vanilla I/O functions are always available in
QMOO and QMBASIC.
Regards,
GlenB
The list select and readnext can be wrapped in methods if you want
cleaner code. The file handle is in memory for the instance of the
object and if you are not doing sort-selecting then after the file is
opened it could be selected by default in the "open" method. An
alternate method for sort-selection can be added so that you can pass
sorting parameters through the open call. The only issue with putting
the select in "open" is, from what I understand, that if you instantiate
multiple file objects within the same code base only the last
instantiation will contain the file in list zero(default). If you
instantiate file1 and then file2, file2's item-ID list will be
active(list zero) and code will break if the readnext loop solely
assumes file1 based on the object pointer name being used. Martin, if
this is wrong please say so.
There are two ways to deal with that, if what I stated was correct:
1) In "open", select the file to a specific list name. The readnext
method will refer to it based on the internal filename variable at
run-time. There should be no confusion as object pointers change the
scope of the I/O at run-time.
2) Implement a select list assignment method, which will be very
expensive if the scope of the I/O flip-flops a lot between files in the
main program.
#1 is doable, but even if we have to do #2 there is still the issue of
the list pointer being reset. When you issue a list selection, I'm
fairly certain that the pointer is reset to the top. So, not only will
the lists have to be managed by filename in globals, but the last
readnext call must be cached in private memory so that subsequent
readnext calls will pick up from the last item-ID within scope of the
file object instance. Consider top-down code with multiple SELECT
statements flipping between several files. It'd be a pain to code in
QMBASIC, but I think it can be done efficiently in QMOO.
If any of this is unclear please ask questions.
Are I-types being used to update data as well? Looks like you've done
a bit of expanding. I think this will be a viable feature to advertise
once it's gone through testing and release approval. I doubt there will
be any friction for release approval. Getting test cases done may be a
bit more challenging, considering there aren't a lot of QMOO users.
Maybe this class, and lots of how-to documentation, will help stimulate
QMOO usage in existing apps.
Regards,
GlenB
I'm happy to help, especially when progress is being made to such a
useful project!
> 1) Added "close" method to close open files
> 2) Added "readu" method to perform readu on data
> 3) Added get method "file" that returns the file pointer
>
> I was hesitant to do the later, but it make many things much easier
> (at the programmer's peril, of course). That makes the first few
> lines of my program read:
>
> IF ADJUST->OPEN("ADJUST") THEN PRINT "WORKED" ELSE PRINT
> "FAILED";STOP
> SELECT ADJUST->FILE ON ERROR PRINT "SELECT FAILED"; STOP
> LOOP:
> READNEXT ADJUST.ID ELSE GO TO DONE
>
> eliminating the need for a second file variable to get the index.
> This actually makes for pretty concise, clean code (I think).
> Actually, I might eliminate the "close" method and put that logic in
> the object destructor.
>
>
Make sure that the "file" method returns null if there is no open
file. I'm sure you've already implemented that, but it drastically
affects the following statements.
Yes, put it in the destructor call. I would agree that a close method
should also be provided for instances where file objects have a short
life and numerous files are being opened and closed in a sequential
order. It is more efficient to reuse the same object instance and clear
the private variables(as is done automatically for the data and
dictionaries) than to create and destroy a bunch of objects for one or
two data hits per file. I would also check, in the "open" method, if the
private file handle is assigned. If it is, the current file should be
closed if the requested file name and the existing file name do not
match. Otherwise, there will be lingering file handles with no variable
assignments to use. They will all be closed when the application
completes, but not dealing with it from all angles could lead to some
performance issues with phantoms and other continuously running code
that gets ignored. IIRC file handles are cached and subsequent opens for
specific files will not be duplicated in memory. As far as multiple
pointer/handle assignments for the same file, I vaguely remember Martin
saying that they're all just memory pointers to the same place. How that
affects a piece of code running 24/7, I'm not sure. The question to
Ladybridge is; if the same file is opened 5,000 times to different
variables, will it impact memory usage? Of course, it won't matter if we
don't put our code in that position. :)
> I'm not exactly sure if I understand your last question... You CANNOT
> make an assignment to an I-type variable. They are essentially 'read
> only'. The ability to resolve these item types are run time was
> ESSENTIAL to my port, because SystemZ makes extensive use of derived
> fields. It solved my "KEY" problem to ease compatibility with the
> ISAM database where my data is now. I make the KEY an I-type field so
> that the KEY value can be used for the record ID and is calculated at
> run time.
>
> Gary
>
It would be possible to use the I-type defs to update data. It has
been mentioned before on the list that this was warranted in some cases,
but I'm still not convinced. My vote is to leave I-type updates out for
the time being. If someone wants to extend their own local copy of the
class then it's fair game on their own server. I will concede that
I-types are 'blind faith' as it is, for reading data and that writing
via the same method is no different.
[chopped due to length]
Regards,
GlenB
It would be possible to use the I-type defs to update data. It has
been mentioned before on the list that this was warranted in some cases,
but I'm still not convinced. My vote is to leave I-type updates out for
the time being. If someone wants to extend their own local copy of the
class then it's fair game on their own server. I will concede that
I-types are 'blind faith' as it is, for reading data and that writing
via the same method is no different.
That should do the trick. I can't think of any other situation where
it wouldn't be null and not be assigned to a file handle.
> I don't really see the need for writing to I-type data items. Note
> that if you change a field that CONTRIBUTES to an I-type calculation,
> the I-type item will change as the contributing fields are changed
> (which is the desirable behavior).
>
>
Hmm. I didn't know that, which is why I didn't do much with the I-type
code. :) I'm still a D3 guy, but I'm slowly picking up things in QM.
> I changed "open" so that if you call "open" when a file is ALREADY
> open, it returns an error. I think this is better because it will
> catch inadvertent re-use of the instance.
>
>
Well, if the file names are identical then there is no error.
Automatic closing on non-null file name change is a feature that could
be useful or it could be considered a bug. Are there other opinions?
> Here are the latest changes to the class (which I renamed
> "DICTFILE.CLS"):
>
> * 20 Jul 09 gdw - Added destructor function with close for file.f
> * 19 Jul 09 gdw - Added get method for "record" that returns the
> current record (item.data)
> * 19 Jul 09 gdw - Check for file already opened in "open" (suggested
> by gcb)
> * 19 Jul 09 gdw - Added "rewrite" method to emulate REWITE verb in
> COBOL
>
> Gary
>
>
I'll grab a copy of the dev code one night this week. It's already
way past my bed time. Got a lot going on this week but I hope to have
time thurs night to review it. So far it sounds like you have a good
grasp of QMBASIC and QMOO. Great job!
GlenB
Ashley,
Thought you'd like to know... I had a chance to use a "C-TYPE" item
and it works with DICTFILE.CLS. If you edit the item with SED, make
sure you force the system to re-compile the dictionary entry before
you try to use it.
> -----Original Message-----
> From: openqm-o...@googlegroups.com [mailto:openqm-
> opens...@googlegroups.com] On Behalf Of Gary
> Sent: 25 July 2009 16:01
> To: OpenQM-OpenSource
> Subject: [OSS] Re: New class(es)
>
>
> To all:
>
> I have uploaded a new version of DICTFILE.CLS. Here are the
> changes:
<snipe>