hi everyone. ithis may be a strange request but i'm really curious about this issue(if it can be called like that) that I have.
as a context, I'm reading an input file to make some insertions in the database.
while coding, seemed to me a good idea to read the file and if a line is wrong then skip it giving a warning about what's wrong in which line and read the next one, of it's ok then make the insert. after came the idea "wait, what if there is 500 lines and just one it's ok... (been extreme) that will be confusing for the user about what's ok and what's not or which lines where inserted cause that will show up a really big Infolog... that's gonna be more troublesome than helpful" so it's better to check the file and if something it's wrong then don't insert anything.
but I'm not sure what approach should I use... I mean there is more than one way of doing it, is there any "best practice" of how to make this? a way to see what's more effective? or it doesn't really matter since the size file ain't that big to cause any performance problem at all no matter the way i choose to do the charge.
cause right now i have two ways of doing this in my mind:
the Current way(which i already said it may go wrong in certain circumstances):
read the records from the file, validate the data and if it's ok then insert, if not then go to the next record, the lines that are wrong goes to the info log to be fixed and loaded in another file.
another way 1:
read the records from the File, validate all the lines of the file, if ok then read the file again and make the insert to the database, if there is an error in the data put it in the info log to fix it and reload the file
another way 2:
read the records from the file, validate the data and if it's ok then do the insert, if not, then rollback previous insertions, don't allow inserts for the next lines and continue just checking the file for error so they can be fixed, errors will be thrown in the info log.
another way 3(came to me while writing this, a variation of my current process):
My current Process, just instead of throwing various errors in the info log put them in an output file, which will contain exactly the input line(s) of error, plus one last column with the warning that error that I was displaying in the info log in the first time.
as part of this issue, if iIuse the next syntax:
try
ttsbegin;
while
{
//read current line
//insert info into database with an ax class
}
ttscommit;
catch
{
throw error("bad information");
}
if there is an error let's say on the last line of 100, the 99 inserted records are rollbacked? I'm aware that the "throw error" does a rollback, but I'm not sure if this rollback works correctly if the insertions are been made inside a while loop, I ca't Find an example like this in the documentation.
another thing I'd like to ask (a bit related to this) is
I'm Using classes from ax to make the insertion to the database, (axInventJournalTrans in this case) what's the purpose of this kind of classes in ax? what's the difference between this and a regular insert into SQL clause?
*This post is locked for comments