tag:blogger.com,1999:blog-8677649049588007585.post7542421012124927247..comments2023-06-18T16:15:22.432+01:00Comments on PL/SQL Challenge: Infinite files? REALLY? (2205)Steven Feuersteinhttp://www.blogger.com/profile/16619706770920320550noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-8677649049588007585.post-14026386990831255942011-04-20T13:00:48.323+01:002011-04-20T13:00:48.323+01:00Jeff: "Days since last correction" - I h...Jeff: "Days since last correction" - I have thought of doing that myself. I think it would be "cute" - but I hate to draw attention to mistakes. :-) I have added it to the ER list.<br /><br />Wim and "trick": I should have clarified that by "trick" I meant that it was a test case that didn't really have anything to do with the point of the question. It was, however, a perfect learning opportunity - and thanks to Michal for that!Steven Feuersteinhttps://www.blogger.com/profile/16619706770920320550noreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-20850494005779357682011-04-20T07:08:29.045+01:002011-04-20T07:08:29.045+01:00About the "trick" answer from Michal. I ...About the "trick" answer from Michal. I think it is wrong to consider it a trick answer. Such things can happen in real life and can lead to unexpected problems. I once had an application which creates a file with the codename of the customer and only [A-Z][0-9] allowed. And then there was this customer with the name 'COM4'. Which is a device name (it still is). So if you call something a file, it suddenly could be something else. Important lesson here.<br /><br />I'm glad that Michal got a price for making this statement.Wim de Langehttps://www.blogger.com/profile/05505341375827859005noreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-67493110936408670692011-04-20T03:39:46.517+01:002011-04-20T03:39:46.517+01:00Feature request for the next version: a "Days...Feature request for the next version: a "Days since last correction" count, much like the "Days since last accident" signs at construction sites :)<br /><br />/tongue-in-cheekJeff Kemphttp://jeffkemponoracle.comnoreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-42156764786273762542011-04-19T12:55:41.717+01:002011-04-19T12:55:41.717+01:00I must admit to feeling a little bit torn on this ...I must admit to feeling a little bit torn on this topic, regarding whether or not to change the score for the point raised by Michal. <br /><br />I am supposed to avoid "trick" questions....and this, I would say, is a "trick" answer. This "device" pointed out to us by Michal is not a file, but then I do not specify in my choice that the "thing" pointed to by the "valid file handle" is actually a file!<br /><br />In addition, I am impressed to see that Michal actually knew at the time he took the quiz that you could define a device like this - or at least he answered that this choice could cause an infinite loop.<br /><br />So a correction must be made! I will give everyone credit for a correct answer on this choice, change the text to make clear that we are talking about FILES and not arbitrary kinds of devices that you can attach to a file handle, and add some explanation on this point to the answer for that choice.<br /><br />Thanks, Michal, for bringing this to our attention. You will receive a free O'Reilly ebook as your prize.<br /><br />By the way, this correction comes after about 45 days of mistake-free playing on the PL/SQL Challenge. <br /><br />I am very proud of and thankful to my reviewers, and the players who have submitted so many excellent quizzes, for the very high quality of our quizzes through this period.<br /><br />Cheers, StevenSteven Feuersteinhttps://www.blogger.com/profile/16619706770920320550noreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-31699752595475552172011-04-19T10:11:51.469+01:002011-04-19T10:11:51.469+01:00Hi guys,
I have tested it and seems to be working...Hi guys,<br /><br />I have tested it and seems to be working as expected.<br /><br />My test code:<br />DECLARE<br /> l_file UTL_FILE.file_type;<br /> l_buf VARCHAR2 (32767);<br /> l_counter PLS_INTEGER := 0;<br />BEGIN<br /> l_file := UTL_FILE.fopen ('MYDIR', 'urandom', 'r', 32767);<br /> LOOP<br /> UTL_FILE.get_line (l_file, l_buf);<br /> l_counter := l_counter + 1;<br /> EXIT WHEN l_counter >= 1000000;<br /> END LOOP;<br /> UTL_FILE.fclose (l_file);<br /> DBMS_OUTPUT.put_line (TO_CHAR (l_counter));<br />EXCEPTION<br /> WHEN OTHERS<br /> THEN<br /> IF UTL_FILE.is_open (l_file)<br /> THEN<br /> UTL_FILE.fclose (l_file);<br /> END IF;<br /> RAISE;<br />END;<br /><br />Finished successfully after 1M loops.<br />The exit clause is used just because I don't want to have it infinite. ;)<br /><br />Michal CvanAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-7751383849940109462011-04-19T03:42:17.511+01:002011-04-19T03:42:17.511+01:00> I'd be interested in what UTL_FILE.FGETAT...> I'd be interested in what UTL_FILE.FGETATTR returned as the file length for such a file.<br /><br />I tried. fGetAttr returned "Tricky. I'll have to think about it." I'm still waiting for the final answer :)Jeff Kemphttp://jeffkemponoracle.comnoreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-83163641377300244932011-04-18T23:32:53.943+01:002011-04-18T23:32:53.943+01:00If you were reviewing code from a security point o...If you were reviewing code from a security point of view, then I think you would say that an attacker COULD abuse the code by providing a pointer to a file that wouldn't end.<br />I'd be interested in what UTL_FILE.FGETATTR returned as the file length for such a file.SydOraclehttps://www.blogger.com/profile/08828771074492585943noreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-57238974646123369822011-04-18T20:54:26.101+01:002011-04-18T20:54:26.101+01:00This comment has been removed by the author.Unknownhttps://www.blogger.com/profile/14825145087220292840noreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-68509127585057852172011-04-18T17:29:14.762+01:002011-04-18T17:29:14.762+01:00The player’s objection to the explanation is valid...The player’s objection to the explanation is valid: it is possible to have a file that is unbounded in size. Jeff Kemp mentioned one case, the use of special files. Another case would be the use of pipes to connect an output of one process to an input of another.<br /><br />The potential for a file to be unbounded in size does not; however, change the correctness of the choice given the provided definition of infinite loop. There is a condition for terminating the loop (the end of data in the file), this condition can be met (although when it will is indeterminate), and the loop is not being restarted.jhall62https://www.blogger.com/profile/10339038131928463003noreply@blogger.comtag:blogger.com,1999:blog-8677649049588007585.post-76212275380797380712011-04-18T14:17:20.138+01:002011-04-18T14:17:20.138+01:00Barring unexpected problems such as memory leaks, ...Barring unexpected problems such as memory leaks, bugs in the underlying OS, or hardware failure, I'd expect special files like dev/random will continue to provide lines for as long as the Oracle session cares to read from it.<br /><br />Obviously it is impossible to prove that any given process will run forever - after all, the universe will end well before an infinite time has passed - so the only reasonable thing to say is that we "expect" it to run forever, as long as nothing external to the code causes it to stop (such as the operator killing the session or pulling the plug on the server).<br /><br />It is more reasonable to say that under "normal" conditions (i.e. when reading an ordinary file), this code will terminate eventually.Jeffrey Kemphttp://jeffkemponoracle.comnoreply@blogger.com