PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.3.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.3.2
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | classes/Visualizer/Source/Query.php +16 -21 3.1.13.3.2 View file →
@@ -35,16 +35,8 @@
35 35 */
36 36 protected $_query;
37 37
38 38 /**
39 - * The error message.
40 - *
41 - * @access protected
42 - * @var string
43 - */
44 - protected $_error;
45 -
46 - /**
47 39 * Constructor.
48 40 *
49 41 * @access public
50 42 * @param string $query The query.
@@ -56,28 +48,41 @@
56 48 /**
57 49 * Fetches information from source, parses it and builds series and data arrays.
58 50 *
59 51 * @param bool $as_html Should the result be fetched as an HTML table or as an object.
52 + * @param bool $results_as_numeric_array Should the result be fetched as ARRAY_N instead of ARRAY_A.
53 + * @param bool $raw_results Should the result be returned without processing.
60 54 * @access public
61 55 * @return boolean TRUE on success, otherwise FALSE.
62 56 */
63 - public function fetch( $as_html = false ) {
57 + public function fetch( $as_html = false, $results_as_numeric_array = false, $raw_results = false ) {
64 58 if ( empty( $this->_query ) ) {
65 59 return false;
66 60 }
67 61
62 + // only select queries allowed.
63 + if ( preg_match( '/^\s*(insert|delete|update|replace|create|alter|drop|truncate)\s/i', $this->_query ) ) {
64 + $this->_error = __( 'Only SELECT queries are allowed', 'visualizer' );
65 + return false;
66 + }
67 +
68 68 // impose a limit if no limit clause is provided.
69 69 if ( strpos( strtolower( $this->_query ), ' limit ' ) === false ) {
70 - $this->_query .= ' LIMIT ' . apply_filters( 'visualizer_sql_query_limit', 300 );
70 + $this->_query .= ' LIMIT ' . apply_filters( 'visualizer_sql_query_limit', 1000 );
71 71 }
72 72
73 73 global $wpdb;
74 74 $wpdb->hide_errors();
75 75 // @codingStandardsIgnoreStart
76 - $rows = $wpdb->get_results( $this->_query, ARRAY_A );
76 + $rows = $wpdb->get_results( $this->_query, $results_as_numeric_array ? ARRAY_N : ARRAY_A );
77 + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Firing query %s to get results %s with error %s', $this->_query, print_r( $rows, true ), print_r( $wpdb->last_error, true ) ), 'debug', __FILE__, __LINE__ );
77 78 // @codingStandardsIgnoreEnd
78 79 $wpdb->show_errors();
79 80
81 + if ( $raw_results ) {
82 + return $rows;
83 + }
84 +
80 85 if ( $rows ) {
81 86 $results = array();
82 87 $headers = array();
83 88 if ( $rows ) {
@@ -168,18 +173,8 @@
168 173 }
169 174 $this->_data = $data;
170 175
171 176 return true;
172 - }
173 -
174 - /**
175 - * Returns the error, if any.
176 - *
177 - * @access public
178 - * @return string
179 - */
180 - public function get_error() {
181 - return $this->_error;
182 177 }
183 178
184 179 /**
185 180 * Returns the final query.