Skip to content

Commit 6c94ccd

Browse files
authored
Merge pull request #1580 from mambax7/feature/replace_query(),_queryF()_with_exec()
Feature/replace query(), query f() with exec()
2 parents 82ed42b + 12b42ed commit 6c94ccd

File tree

58 files changed

+219
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+219
-212
lines changed

htdocs/banners.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function change_banner_url_by_client($cid, $bid, $url)
327327
[$passwd] = $xoopsDB->fetchRow($result);
328328
if ($_SESSION['banner_pass'] == $passwd) {
329329
$sql = sprintf('UPDATE %s SET clickurl=%s WHERE bid=%u AND cid=%u', $xoopsDB->prefix('banner'), $xoopsDB->quote($url), $bid, $cid);
330-
if ($xoopsDB->query($sql)) {
330+
if ($xoopsDB->exec($sql)) {
331331
redirect_header('banners.php?op=Ok', 3, _BANNERS_DBUPDATED);
332332
}
333333
}
@@ -356,7 +356,7 @@ function clickbanner($bid)
356356
[$clickurl] = $xoopsDB->fetchRow($result);
357357
if ($clickurl) {
358358
if ($GLOBALS['xoopsSecurity']->checkReferer()) {
359-
$xoopsDB->queryF('UPDATE ' . $xoopsDB->prefix('banner') . " SET clicks=clicks+1 WHERE bid=$bid");
359+
$xoopsDB->exec('UPDATE ' . $xoopsDB->prefix('banner') . " SET clicks=clicks+1 WHERE bid=$bid");
360360
header('Location: ' . $clickurl);
361361
} else {
362362
//No valid referer found so some javascript error or direct access found

htdocs/class/database/mysqldatabase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ public function isResultSet($result)
534534
return is_a($result, 'mysqli_result');
535535
}
536536

537+
/**
538+
* Perform a mutating statement (INSERT/UPDATE/DELETE/DDL).
539+
*
540+
* @param string $sql
541+
* @return bool
542+
* @throws \mysqli_sql_exception If a MySQLi error occurs and MySQLi is configured to throw exceptions.
543+
*/
537544
public function exec(string $sql): bool
538545
{
539546
// Dev-only guard: exec() should be write-like

htdocs/class/logger/xoopslogger.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ public function stopTime($name = 'XOOPS')
143143
* Log a database query
144144
*
145145
* @param string $sql SQL string
146-
* @param string $error error message (if any)
147-
* @param int $errno error number (if any)
148-
* @param null $query_time
146+
* @param string|null $error error message (if any)
147+
* @param int|null $errno error number (if any)
148+
* @param float|null $query_time
149149
*/
150150
public function addQuery($sql, $error = null, $errno = null, $query_time = null)
151151
{

htdocs/class/model/joint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function updateByLink($data, ?CriteriaElement $criteria = null)
205205
$sql .= ' ' . $criteria->renderWhere();
206206
}
207207

208-
return $this->handler->db->query($sql);
208+
return $this->handler->db->exec($sql);
209209
}
210210

211211
/**
@@ -224,6 +224,6 @@ public function deleteByLink(?CriteriaElement $criteria = null)
224224
$sql .= ' ' . $criteria->renderWhere();
225225
}
226226

227-
return $this->handler->db->query($sql);
227+
return $this->handler->db->exec($sql);
228228
}
229229
}

htdocs/class/model/sync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function cleanOrphan($table_link = '', $field_link = '', $field_object =
7272
// for 4.0+
7373
$sql = "DELETE `{$this->handler->table}` FROM `{$this->handler->table}`" . " LEFT JOIN `{$this->handler->table_link}` AS aa ON `{$this->handler->table}`.`{$this->handler->field_object}` = aa.`{$this->handler->field_link}`" . " WHERE (aa.`{$this->handler->field_link}` IS NULL)";
7474
}
75-
if (!$result = $this->handler->db->queryF($sql)) {
75+
if (!$result = $this->handler->db->exec($sql)) {
7676
return false;
7777
}
7878

htdocs/class/model/write.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function insert($object, $force = true)
248248

249249
return $object->getVar($this->handler->keyName);
250250
}
251-
$queryFunc = empty($force) ? 'query' : 'queryF';
251+
$queryFunc = empty($force) ? 'query' : 'exec';
252252

253253
if ($object->isNew()) {
254254
$sql = 'INSERT INTO `' . $this->handler->table . '`';
@@ -301,7 +301,7 @@ public function delete($object, $force = false)
301301
$whereclause = '`' . $this->handler->keyName . '` = ' . $this->handler->db->quote($object->getVar($this->handler->keyName));
302302
}
303303
$sql = 'DELETE FROM `' . $this->handler->table . '` WHERE ' . $whereclause;
304-
$queryFunc = empty($force) ? 'query' : 'queryF';
304+
$queryFunc = empty($force) ? 'query' : 'exec';
305305
$result = $this->handler->db->{$queryFunc}($sql);
306306

307307
return empty($result) ? false : true;
@@ -327,7 +327,7 @@ public function deleteAll(?CriteriaElement $criteria = null, $force = true, $asO
327327

328328
return $num;
329329
}
330-
$queryFunc = empty($force) ? 'query' : 'queryF';
330+
$queryFunc = empty($force) ? 'query' : 'exec';
331331
$sql = 'DELETE FROM ' . $this->handler->table;
332332
if (!empty($criteria)) {
333333
if (is_subclass_of($criteria, 'CriteriaElement')) {
@@ -366,7 +366,7 @@ public function updateAll($fieldname, $fieldvalue, ?CriteriaElement $criteria =
366366
if (isset($criteria) && \method_exists($criteria, 'renderWhere')) {
367367
$sql .= ' ' . $criteria->renderWhere();
368368
}
369-
$queryFunc = empty($force) ? 'query' : 'queryF';
369+
$queryFunc = empty($force) ? 'query' : 'exec';
370370
$result = $this->handler->db->{$queryFunc}($sql);
371371

372372
return empty($result) ? false : true;

htdocs/class/xoopscomments.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function store()
133133
} else {
134134
$sql = sprintf("UPDATE %s SET subject = '%s', comment = '%s', nohtml = %u, nosmiley = %u, noxcode = %u, icon = '%s' WHERE comment_id = %u", $this->ctable, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon, $comment_id);
135135
}
136-
if (!$result = $this->db->query($sql)) {
136+
if (!$result = $this->db->exec($sql)) {
137137
//echo $sql;
138138
return false;
139139
}
@@ -142,7 +142,7 @@ public function store()
142142
}
143143
if ($isnew != false) {
144144
$sql = sprintf('UPDATE %s SET posts = posts+1 WHERE uid = %u', $this->db->prefix('users'), $user_id);
145-
if (!$result = $this->db->query($sql)) {
145+
if (!$result = $this->db->exec($sql)) {
146146
echo 'Could not update user posts.';
147147
}
148148
}
@@ -158,11 +158,11 @@ public function store()
158158
public function delete()
159159
{
160160
$sql = sprintf('DELETE FROM %s WHERE comment_id = %u', $this->ctable, $this->getVar('comment_id'));
161-
if (!$result = $this->db->query($sql)) {
161+
if (!$result = $this->db->exec($sql)) {
162162
return false;
163163
}
164164
$sql = sprintf('UPDATE %s SET posts = posts-1 WHERE uid = %u', $this->db->prefix('users'), $this->getVar('user_id'));
165-
if (!$result = $this->db->query($sql)) {
165+
if (!$result = $this->db->exec($sql)) {
166166
echo 'Could not update user posts.';
167167
}
168168
$mytree = new XoopsTree($this->ctable, 'comment_id', 'pid');
@@ -171,11 +171,11 @@ public function delete()
171171
if ($size > 0) {
172172
for ($i = 0; $i < $size; ++$i) {
173173
$sql = sprintf('DELETE FROM %s WHERE comment_bid = %u', $this->ctable, $arr[$i]['comment_id']);
174-
if (!$result = $this->db->query($sql)) {
174+
if (!$result = $this->db->exec($sql)) {
175175
echo 'Could not delete comment.';
176176
}
177177
$sql = sprintf('UPDATE %s SET posts = posts-1 WHERE uid = %u', $this->db->prefix('users'), $arr[$i]['user_id']);
178-
if (!$result = $this->db->query($sql)) {
178+
if (!$result = $this->db->exec($sql)) {
179179
echo 'Could not update user posts.';
180180
}
181181
}

htdocs/class/xoopseditor/tinymce/tinymce/jscripts/tiny_mce/plugins/xoopsemotions/xoopsemotions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
$smile_display = (int) $_POST['smile_display'] > 0 ? 1 : 0;
7272
$newid = $db->genId($db->prefix('smilies') . '_id_seq');
7373
$sql = sprintf('INSERT INTO %s (id, code, smile_url, emotion, display) VALUES (%d, %s, %s, %s, %d)', $db->prefix('smiles'), $newid, $db->quote($smile_code), $db->quote($smile_url), $db->quote($smile_desc), $smile_display);
74-
if (!$db->query($sql)) {
74+
if (!$db->exec($sql)) {
7575
$err = 'Failed storing smiley data into the database';
7676
}
7777
}

htdocs/class/xoopsstory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function store($approved = false)
255255
}
256256
$newstoryid = $this->storyid;
257257
}
258-
if (!$result = $this->db->query($sql)) {
258+
if (!$result = $this->db->exec($sql)) {
259259
return false;
260260
}
261261
if (empty($newstoryid)) {
@@ -300,7 +300,7 @@ public function makeStory($array)
300300
public function delete()
301301
{
302302
$sql = sprintf('DELETE FROM %s WHERE storyid = %u', $this->table, $this->storyid);
303-
if (!$result = $this->db->query($sql)) {
303+
if (!$result = $this->db->exec($sql)) {
304304
return false;
305305
}
306306

@@ -313,7 +313,7 @@ public function delete()
313313
public function updateCounter()
314314
{
315315
$sql = sprintf('UPDATE %s SET counter = counter+1 WHERE storyid = %u', $this->table, $this->storyid);
316-
if (!$result = $this->db->queryF($sql)) {
316+
if (!$result = $this->db->exec($sql)) {
317317
return false;
318318
}
319319

@@ -328,7 +328,7 @@ public function updateCounter()
328328
public function updateComments($total)
329329
{
330330
$sql = sprintf('UPDATE %s SET comments = %u WHERE storyid = %u', $this->table, $total, $this->storyid);
331-
if (!$result = $this->db->queryF($sql)) {
331+
if (!$result = $this->db->exec($sql)) {
332332
return false;
333333
}
334334

htdocs/class/xoopstopic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function store()
142142
} else {
143143
$sql = sprintf("UPDATE %s SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id);
144144
}
145-
if (!$result = $this->db->query($sql)) {
145+
if (!$result = $this->db->exec($sql)) {
146146
ErrorHandler::show('0022');
147147
}
148148
if ($this->use_permission == true) {
@@ -220,7 +220,7 @@ public function store()
220220
public function delete()
221221
{
222222
$sql = sprintf('DELETE FROM %s WHERE topic_id = %u', $this->table, $this->topic_id);
223-
$this->db->query($sql);
223+
$this->db->exec($sql);
224224
}
225225

226226
/**

0 commit comments

Comments
 (0)