{"id":91,"date":"2007-04-10T17:39:42","date_gmt":"2007-04-10T16:39:42","guid":{"rendered":"http:\/\/bar-solutions.com\/wordpress\/?p=91"},"modified":"2007-04-10T17:39:43","modified_gmt":"2007-04-10T16:39:43","slug":"a-boolean-property-thats-really-an-integer","status":"publish","type":"post","link":"https:\/\/blog.bar-solutions.com\/?p=91","title":{"rendered":"A boolean property that&#8217;s really an integer&#8230;"},"content":{"rendered":"<p align=\"left\">In my <a title=\"Delphi like properties in packages\" href=\"http:\/\/bar-solutions.com\/wordpress\/?p=90\" target=\"_blank\">previous post<\/a> I have been writing about how you can mimic properties in a PL\/SQL package. One of the ideas I wrote about was a boolean property that internally is an integer value. How can this be useful. If, for instance, you want to turn logging on and of during the program, wouldn&#8217;t it be nice not to have to worry about it&#8217;s previous state when turning it on (for instance when calling sub-programs).<\/p>\n<p align=\"left\">Suppose I have the following package spec:<\/p>\n<blockquote>\n<p><font size=\"1\">CREATE OR REPLACE PACKAGE bar<br \/>IS<br \/>&#8212; Author : PBAREL<br \/>&#8212; Purpose : demonstrate properties<br \/>&nbsp; PROCEDURE LOG(log_in IN BOOLEAN ); <br \/>&nbsp; FUNCTION LOG RETURN BOOLEAN;<br \/>END bar;<\/font><\/p>\n<\/blockquote>\n<p align=\"left\">There&nbsp;appears to be a boolean property to turn the logging on and off. If I turn on logging at one point in the execution of the program and turn if off later on, I would have to preserve&nbsp;the&nbsp;original state to see if logging was&nbsp;already turned on before I turned it on (again). If however, I would implement the property that would do the checking for me, it would be a big help. But, I wouldn&#8217;t know how many times it would be consecutively be turned on. That could be endless.<\/p>\n<p align=\"left\">I can implement the internal variable as an integer, that is raised when turning logging on and lowered when logging is turned off. When checking the state of the property it&nbsp;will return a boolean value based on the value of the internal variable. <\/p>\n<blockquote>\n<p align=\"left\"><font size=\"1\">CREATE OR REPLACE PACKAGE BODY bar<br \/>IS<br \/>&nbsp; flog PLS_INTEGER; <br \/><\/font><font size=\"1\">&nbsp; PROCEDURE LOG(log_in IN BOOLEAN )<br \/>&nbsp; IS<br \/>&nbsp; BEGIN<br \/>&nbsp;&nbsp;&nbsp; IF log_in THEN<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flog := flog + 1;<br \/>&nbsp;&nbsp;&nbsp; ELSE<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flog := flog &#8211; 1;<br \/>&nbsp;&nbsp;&nbsp; END IF;<br \/>&nbsp;&nbsp;&nbsp; <\/font><font size=\"1\">IF flog &lt; 0 THEN<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flog := 0;<br \/>&nbsp;&nbsp;&nbsp; END IF;<br \/>&nbsp; END LOG;&nbsp;<br \/>&nbsp; <\/font><font size=\"1\">FUNCTION LOG RETURN BOOLEAN<br \/>&nbsp; IS<br \/>&nbsp; BEGIN<br \/>&nbsp;&nbsp;&nbsp; RETURN( flog &gt; 0 );<br \/>&nbsp; END LOG;<br \/>END bar;<\/font><\/p>\n<\/blockquote>\n<p align=\"left\">Since we have more control over the property than just&nbsp;a package variable, this has become pretty straight forward and we can easily change the internal behavior of the property, while the signature wouldn&#8217;t change to the outside world.<\/p>\n<p align=\"left\">\n","protected":false},"excerpt":{"rendered":"<p>In my previous post I have been writing about how you can mimic properties in a PL\/SQL package. One of the ideas I wrote about was a boolean property that internally is an integer value. How can this be useful. If, for instance, you want to turn logging on and of during the program, wouldn&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-91","post","type-post","status-publish","format-standard","hentry","category-oracle","category-plsql"],"_links":{"self":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/91","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=91"}],"version-history":[{"count":0,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}