Subversion Repositories oidplus

Rev

Rev 1152 | Rev 1232 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1152 Rev 1156
Line 34... Line 34...
34
         * @var mixed
34
         * @var mixed
35
         */
35
         */
36
        protected $res;
36
        protected $res;
37
 
37
 
38
        /**
38
        /**
39
         * @var array|null
-
 
40
         */
-
 
41
        private $prefetchedArray = null;
-
 
42
 
-
 
43
        /**
-
 
44
         * @var int
-
 
45
         */
-
 
46
        private $countAlreadyFetched = 0;
-
 
47
 
-
 
48
        /**
-
 
49
         * @param mixed $res
39
         * @param mixed $res
50
         */
40
         */
51
        public function __construct($res) {
41
        public function __construct($res) {
52
                $this->no_resultset = is_bool($res);
42
                $this->no_resultset = is_bool($res);
53
 
43
 
Line 71... Line 61...
71
        public function containsResultSet(): bool {
61
        public function containsResultSet(): bool {
72
                return !$this->no_resultset;
62
                return !$this->no_resultset;
73
        }
63
        }
74
 
64
 
75
        /**
65
        /**
76
         * @return int
66
         * @return void
77
         */
67
         */
78
        protected function do_num_rows(): int {
68
        public function prefetchAll() {
79
                if (!is_null($this->prefetchedArray)) {
69
                if (!is_null($this->prefetchedArray)) return;
-
 
70
                $this->prefetchedArray = array();
80
                        return count($this->prefetchedArray) + $this->countAlreadyFetched;
71
                oci_fetch_all($this->res, $this->prefetchedArray, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
81
                }
72
        }
82
 
73
 
-
 
74
        /**
-
 
75
         * @return int
-
 
76
         */
-
 
77
        protected function do_num_rows(): int {
83
                // This function does not return number of rows selected! For SELECT statements this function will return the number of rows, that were fetched to the buffer with oci_fetch*() functions.
78
                // This function does not return number of rows selected! For SELECT statements this function will return the number of rows, that were fetched to the buffer with oci_fetch*() functions.
84
                //return oci_num_rows($this->res);
79
                //return oci_num_rows($this->res);
85
 
80
 
86
                $this->prefetchedArray = array();
81
                if (is_null($this->prefetchedArray)) {
87
                oci_fetch_all($this->res, $this->prefetchedArray, 0, -1, OCI_FETCHSTATEMENT_BY_ROW);
82
                        $this->prefetchAll();
-
 
83
                }
-
 
84
 
88
                return count($this->prefetchedArray) + $this->countAlreadyFetched;
85
                return count($this->prefetchedArray) + $this->countAlreadyFetched;
89
        }
86
        }
90
 
87
 
91
        /**
88
        /**
92
         * @return array|mixed|null
89
         * @return array|null
93
         */
90
         */
94
        protected function do_fetch_array()/*: ?array*/ {
91
        protected function do_fetch_array()/*: ?array*/ {
95
                if (!is_null($this->prefetchedArray)) {
-
 
96
                        $ret = array_shift($this->prefetchedArray);
-
 
97
                } else {
-
 
98
                        $ret = oci_fetch_array($this->res);
92
                $ret = oci_fetch_array($this->res);
99
                        if ($ret === false) $ret = null;
93
                if ($ret === false) $ret = null;
100
                }
-
 
101
                if ($ret) $this->countAlreadyFetched++;
-
 
102
 
-
 
103
                // Oracle returns $ret['VALUE'] because unquoted column-names are always upper-case
-
 
104
                // We can't quote every single column throughout the whole program, so we use this workaround...
-
 
105
                if ($ret) {
-
 
106
                        $keys = array_keys($ret);
-
 
107
                        foreach($keys as $key) {
-
 
108
                                $ret[strtolower($key)]=$ret[$key];
-
 
109
                                $ret[strtoupper($key)]=$ret[$key];
-
 
110
                        }
-
 
111
                }
-
 
112
 
-
 
113
                return $ret;
94
                return $ret;
114
        }
95
        }
115
 
96
 
116
        /**
97
        /**
117
         * @param array $ary
-
 
118
         * @return \stdClass
98
         * @return object|null
119
         */
-
 
120
        private static function array_to_stdobj(array $ary): \stdClass {
-
 
121
                $obj = new \stdClass;
-
 
122
                foreach ($ary as $name => $val) {
-
 
123
                        $obj->$name = $val;
-
 
124
 
-
 
125
                        // Oracle returns $ret['VALUE'] because unquoted column-names are always upper-case
-
 
126
                        // We can't quote every single column throughout the whole program, so we use this workaround...
-
 
127
                        $name = strtolower($name);
-
 
128
                        $obj->$name = $val;
-
 
129
                        $name = strtoupper($name);
-
 
130
                        $obj->$name = $val;
-
 
131
                }
-
 
132
                return $obj;
-
 
133
        }
-
 
134
 
-
 
135
        /**
-
 
136
         * @return false|object|\stdClass|null
-
 
137
         */
99
         */
138
        protected function do_fetch_object()/*: ?object*/ {
100
        protected function do_fetch_object()/*: ?object*/ {
139
                if (!is_null($this->prefetchedArray)) {
-
 
140
                        $ary = array_shift($this->prefetchedArray);
-
 
141
                        $ret = is_null($ary) ? null : self::array_to_stdobj($ary);
-
 
142
                } else {
-
 
143
                        $ret = oci_fetch_object($this->res);
101
                $ret = oci_fetch_object($this->res);
144
                        if ($ret === false) $ret = null;
102
                if ($ret === false) $ret = null;
145
                }
-
 
146
                if ($ret) $this->countAlreadyFetched++;
-
 
147
 
-
 
148
                // Oracle returns $ret['VALUE'] because unquoted column-names are always upper-case
-
 
149
                // We can't quote every single column throughout the whole program, so we use this workaround...
-
 
150
                if ($ret) {
-
 
151
                        foreach ($ret as $name => $val) {
-
 
152
                                $ret->{strtoupper($name)} = $val;
-
 
153
                                $ret->{strtolower($name)} = $val;
-
 
154
                        }
-
 
155
                }
-
 
156
 
-
 
157
                return $ret;
103
                return $ret;
158
        }
104
        }
159
}
105
}