Subversion Repositories oidplus

Rev

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

Rev 1370 Rev 1389
Line 108... Line 108...
108
         * @throws OIDplusException
108
         * @throws OIDplusException
109
         * @throws OIDplusSQLException
109
         * @throws OIDplusSQLException
110
         */
110
         */
111
        protected function doQueryPrepareEmulation(string $sql, array $prepared_args=null): OIDplusQueryResultODBC {
111
        protected function doQueryPrepareEmulation(string $sql, array $prepared_args=null): OIDplusQueryResultODBC {
112
                // For some drivers (e.g. Microsoft Access), we need to do this kind of emulation, because odbc_prepare() does not work
112
                // For some drivers (e.g. Microsoft Access), we need to do this kind of emulation, because odbc_prepare() does not work
-
 
113
                $dummy = find_nonexisting_substr($sql);
113
                $sql = str_replace('?', chr(1), $sql);
114
                $sql = str_replace('?', $dummy, $sql);
114
                foreach ($prepared_args as $arg) {
115
                foreach ($prepared_args as $arg) {
115
                        $needle = chr(1);
116
                        $needle = $dummy;
116
                        if (is_bool($arg)) {
117
                        if (is_bool($arg)) {
117
                                if ($this->slangDetectionDone) {
118
                                if ($this->slangDetectionDone) {
118
                                        $replace = $this->getSlang()->getSQLBool($arg);
119
                                        $replace = $this->getSlang()->getSQLBool($arg);
119
                                } else {
120
                                } else {
120
                                        $replace = $arg ? '1' : '0';
121
                                        $replace = $arg ? '1' : '0';
Line 138... Line 139...
138
                        $pos = strpos($sql, $needle);
139
                        $pos = strpos($sql, $needle);
139
                        if ($pos !== false) {
140
                        if ($pos !== false) {
140
                                $sql = substr_replace($sql, $replace, $pos, strlen($needle));
141
                                $sql = substr_replace($sql, $replace, $pos, strlen($needle));
141
                        }
142
                        }
142
                }
143
                }
143
                $sql = str_replace(chr(1), '?', $sql);
144
                $sql = str_replace($dummy, '?', $sql);
144
                $ps = @odbc_exec($this->conn, $sql);
145
                $ps = @odbc_exec($this->conn, $sql);
145
                if (!$ps) {
146
                if (!$ps) {
146
                        $this->last_error = odbc_errormsg($this->conn);
147
                        $this->last_error = odbc_errormsg($this->conn);
147
                        throw new OIDplusSQLException($sql, _L('Cannot prepare statement').': '.$this->error());
148
                        throw new OIDplusSQLException($sql, _L('Cannot prepare statement').': '.$this->error());
148
                }
149
                }