Subversion Repositories oidplus

Rev

Rev 1461 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1461 Rev 1471
Line 70... Line 70...
70
         */
70
         */
71
        public final function num_rows(): int {
71
        public final function num_rows(): int {
72
                if (!$this->containsResultSet()) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)'));
72
                if (!$this->containsResultSet()) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)'));
73
 
73
 
74
                if (!is_null($this->prefetchedArray)) {
74
                if (!is_null($this->prefetchedArray)) {
75
                        return count($this->prefetchedArray) + $this->countAlreadyFetched;
75
                        return count($this->prefetchedArray);
76
                }
76
                }
77
 
77
 
78
                $ret = $this->do_num_rows();
78
                $ret = $this->do_num_rows();
79
 
79
 
80
                if ($ret === -1) throw new OIDplusException(_L('The database driver has problems with "%1"','num_rows'));
80
                if ($ret === -1) throw new OIDplusException(_L('The database driver has problems with "%1"','num_rows'));
Line 134... Line 134...
134
         */
134
         */
135
        public final function fetch_array()/*: ?array*/ {
135
        public final function fetch_array()/*: ?array*/ {
136
                if (!$this->containsResultSet()) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)'));
136
                if (!$this->containsResultSet()) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)'));
137
                if (!is_null($this->prefetchedArray)) {
137
                if (!is_null($this->prefetchedArray)) {
138
                        // Prefetched value exists. Use it.
138
                        // Prefetched value exists. Use it.
139
                        //$ary = array_shift($this->prefetchedArray);
-
 
140
                        $ary = $this->prefetchedArray[$this->countAlreadyFetched] ?? null; // Performance is better this way
139
                        $ary = $this->prefetchedArray[$this->countAlreadyFetched] ?? null;
141
                } else {
140
                } else {
142
                        $reflector = new \ReflectionMethod($this, 'do_fetch_array');
141
                        $reflector = new \ReflectionMethod($this, 'do_fetch_array');
143
                        $isImplemented = ($reflector->getDeclaringClass()->getName() !== self::class);
142
                        $isImplemented = ($reflector->getDeclaringClass()->getName() !== self::class);
144
                        if ($isImplemented) {
143
                        if ($isImplemented) {
145
                                // do_fetch_array() is implemented. Use it.
144
                                // do_fetch_array() is implemented. Use it.
Line 179... Line 178...
179
         */
178
         */
180
        public final function fetch_object()/*: ?\stdClass*/ {
179
        public final function fetch_object()/*: ?\stdClass*/ {
181
                if (!$this->containsResultSet()) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)'));
180
                if (!$this->containsResultSet()) throw new OIDplusException(_L('The query has returned no result set (i.e. it was not a SELECT query)'));
182
                if (!is_null($this->prefetchedArray)) {
181
                if (!is_null($this->prefetchedArray)) {
183
                        // Prefetched value exists (as array). Convert and use it.
182
                        // Prefetched value exists (as array). Convert and use it.
184
                        //$ary = array_shift($this->prefetchedArray);
-
 
185
                        $ary = $this->prefetchedArray[$this->countAlreadyFetched] ?? null; // Performance is better this way
183
                        $ary = $this->prefetchedArray[$this->countAlreadyFetched] ?? null;
186
                        $obj = is_null($ary) ? null : array_to_stdobj($ary);
184
                        $obj = is_null($ary) ? null : array_to_stdobj($ary);
187
                } else {
185
                } else {
188
                        $reflector = new \ReflectionMethod($this, 'do_fetch_object');
186
                        $reflector = new \ReflectionMethod($this, 'do_fetch_object');
189
                        $isImplemented = ($reflector->getDeclaringClass()->getName() !== self::class);
187
                        $isImplemented = ($reflector->getDeclaringClass()->getName() !== self::class);
190
                        if ($isImplemented) {
188
                        if ($isImplemented) {