| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * @package VikWP - Libraries |
| 4 | 4 | * @subpackage adapter.database |
| 5 | 5 | * @author E4J s.r.l. |
| 6 | - * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. | |
| 6 | + * @copyright Copyright (C) 2023 E4J s.r.l. All Rights Reserved. | |
| 7 | 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | 8 | * @link https://vikwp.com |
| 9 | 9 | */ |
| 10 | 10 | |
| @@ -203,10 +203,10 @@ | ||
| 203 | 203 | // save the query with the real db prefix |
| 204 | 204 | $this->q = $this->replacePrefix($q); |
| 205 | 205 | |
| 206 | 206 | // register offset and limit (always override previous values) |
| 207 | - $this->offset = abs($offset); | |
| 208 | - $this->limit = abs($limit); | |
| 207 | + $this->offset = abs((int) $offset); | |
| 208 | + $this->limit = abs((int) $limit); | |
| 209 | 209 | |
| 210 | 210 | return $this; |
| 211 | 211 | } |
| 212 | 212 | |
| @@ -253,8 +253,15 @@ | ||
| 253 | 253 | if (preg_match("/^(SELECT|SHOW)/i", $sql)) |
| 254 | 254 | { |
| 255 | 255 | // result should contain an array |
| 256 | 256 | $this->result = $this->db->get_results($sql); |
| 257 | + | |
| 258 | + /** | |
| 259 | + * Flush result after executing the query to free disk space. | |
| 260 | + * | |
| 261 | + * @since 10.1.73 | |
| 262 | + */ | |
| 263 | + $this->db->flush(); | |
| 257 | 264 | } |
| 258 | 265 | // otherwise we can launch a generic query |
| 259 | 266 | else |
| 260 | 267 | { |
| @@ -323,9 +330,17 @@ | ||
| 323 | 330 | } |
| 324 | 331 | |
| 325 | 332 | if (is_array($this->result)) |
| 326 | 333 | { |
| 327 | - return $this->result; | |
| 334 | + /** | |
| 335 | + * Copy result on a local variable and flush the cached value. | |
| 336 | + * | |
| 337 | + * @since 10.1.73 | |
| 338 | + */ | |
| 339 | + $result = $this->result; | |
| 340 | + $this->result = null; | |
| 341 | + | |
| 342 | + return $result; | |
| 328 | 343 | } |
| 329 | 344 | |
| 330 | 345 | return array(); |
| 331 | 346 | } |
| @@ -668,8 +683,20 @@ | ||
| 668 | 683 | return $affected !== false; |
| 669 | 684 | } |
| 670 | 685 | |
| 671 | 686 | /** |
| 687 | + * Returns the error faced (if any) during the last query execution. | |
| 688 | + * | |
| 689 | + * @return string The error message. | |
| 690 | + * | |
| 691 | + * @since 10.1.58 | |
| 692 | + */ | |
| 693 | + public function getLastError() | |
| 694 | + { | |
| 695 | + return $this->db->last_error; | |
| 696 | + } | |
| 697 | + | |
| 698 | + /** | |
| 672 | 699 | * Returns a PHP date() function compliant date format for the database driver. |
| 673 | 700 | * |
| 674 | 701 | * @return string The format string. |
| 675 | 702 | */ |
| @@ -725,9 +752,14 @@ | ||
| 725 | 752 | * @since 10.1.19 |
| 726 | 753 | */ |
| 727 | 754 | public function getTableColumns($table, $typeOnly = true) |
| 728 | 755 | { |
| 729 | - $q = "SHOW FULL COLUMNS FROM " . $this->qn($table); | |
| 756 | + /** | |
| 757 | + * Do not escape the table name to support SQLite too. | |
| 758 | + * | |
| 759 | + * @since 10.1.53 | |
| 760 | + */ | |
| 761 | + $q = "SHOW FULL COLUMNS FROM " . $table; | |
| 730 | 762 | |
| 731 | 763 | // set the query to get the table fields statement |
| 732 | 764 | $this->setQuery($q); |
| 733 | 765 | $this->execute(); |
| @@ -733,8 +765,10 @@ | ||
| 733 | 765 | $this->execute(); |
| 734 | 766 | |
| 735 | 767 | $fields = $this->loadObjectList(); |
| 736 | 768 | |
| 769 | + $result = []; | |
| 770 | + | |
| 737 | 771 | // if we only want the type as the value add just that to the list. |
| 738 | 772 | if ($typeOnly) |
| 739 | 773 | { |
| 740 | 774 | foreach ($fields as $field) |
| @@ -746,8 +780,20 @@ | ||
| 746 | 780 | else |
| 747 | 781 | { |
| 748 | 782 | foreach ($fields as $field) |
| 749 | 783 | { |
| 784 | + /** | |
| 785 | + * With SQLite the Extra column might not be included. | |
| 786 | + * Simulate the same result by checking whether the column | |
| 787 | + * is equal to `id` and force the "auto_increment" rule. | |
| 788 | + * | |
| 789 | + * @since 10.1.53 | |
| 790 | + */ | |
| 791 | + if (!isset($field->Extra)) | |
| 792 | + { | |
| 793 | + $field->Extra = $field->Field === 'id' ? 'auto_increment' : ''; | |
| 794 | + } | |
| 795 | + | |
| 750 | 796 | $result[$field->Field] = $field; |
| 751 | 797 | } |
| 752 | 798 | } |
| 753 | 799 | |