Rev 1225 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1225 | Rev 1240 | ||
---|---|---|---|
Line 116... | Line 116... | ||
116 | /** |
116 | /** |
117 | * @param string $sql |
117 | * @param string $sql |
118 | * @return string |
118 | * @return string |
119 | */ |
119 | */ |
120 | public function filterQuery(string $sql): string { |
120 | public function filterQuery(string $sql): string { |
121 | - | ||
122 | // "select 1" is not valid. You need to add "from dual" |
- | |
123 | if ((stripos($sql,'select') !== false) && (stripos($sql,'from') === false)) { |
- | |
124 | $sql .= ' from dual'; |
121 | $sql = trim($sql); |
125 | } |
- | |
126 | 122 | ||
127 | // SQL-Queries MUST NOT end with a ";", otherwise error "SQL command not property ended" |
123 | // SQL-Queries MUST NOT end with a ";", otherwise error "SQL command not property ended" |
128 | $sql = rtrim(trim($sql), "; \n\r\t\v\x00"); |
124 | $sql = rtrim($sql, "; \n\r\t\v\x00"); |
129 | // SQL/PL-Programs MUST end with a ";" |
125 | // SQL/PL-Programs MUST end with a ";" |
130 | if (strtolower(substr($sql,-3)) == 'end') $sql .= ';'; |
126 | if (strtolower(substr($sql,-3)) == 'end') $sql .= ';'; |
131 | 127 | ||
- | 128 | // "select 1" is not valid. You need to add "from dual" |
|
- | 129 | if (str_starts_with(trim(strtolower($sql)),'select') && (stripos($sql,'from') === false)) { |
|
- | 130 | $sql .= ' from dual'; |
|
- | 131 | } |
|
- | 132 | ||
132 | // Dirty hack!!! We need the name of the last inserted table so that insert_id() |
133 | // Dirty hack!!! We need the name of the last inserted table so that insert_id() |
133 | // works. This is a dirty hack, because the invokation of filterQuery() does |
134 | // works. This is a dirty hack, because the invokation of filterQuery() does |
134 | // not guarantee that the query was actually executed... |
135 | // not guarantee that the query was actually executed... |
135 | if (preg_match("@insert into (.+) @ismU", $sql, $m)) { |
136 | if (preg_match("@insert into (.+) @ismU", $sql, $m)) { |
136 | $this->last_insert_table = $m[1]; |
137 | $this->last_insert_table = $m[1]; |