Mstdlib-1.24.0
m_sql_report.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2017 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_SQL_REPORT_H__
25#define __M_SQL_REPORT_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_types.h>
31#include <mstdlib/sql/m_sql.h>
32#include <mstdlib/sql/m_sql_stmt.h>
33#include <mstdlib/formats/m_json.h>
34
35/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37__BEGIN_DECLS
38
39/*! \addtogroup m_sql_report SQL Report Generation
40 * \ingroup m_sql
41 *
42 * SQL Report Generation
43 *
44 * @{
45 */
46
47typedef enum {
48 M_SQL_REPORT_FLAG_NONE = 0, /*!< No special flags */
49 M_SQL_REPORT_FLAG_ALWAYS_ENCAP = 1 << 0, /*!< CSV: Always encapsulate the fields, even if there are no conflicting characters.
50 * However, NULL fields will still never be encapsulated so NULL vs empty
51 * strings can be determined by the output. Ignored for JSON. */
52 M_SQL_REPORT_FLAG_OMIT_HEADERS = 1 << 1, /*!< CSV: Do not output the first row as headers. Ignored for JSON. */
53 M_SQL_REPORT_FLAG_PASSTHRU_UNLISTED = 1 << 2 /*!< By default, all columns in the output report must be specified. This flag
54 will use the column name returned from the SQL server as the header and
55 pass the data thru with no manipulation. Other columns may be overwritten
56 or added, or even suppressed. When set, columns will be output in the order
57 returned from the SQL server, additional added columns will be appended to
58 the end. */
60
61
62/*! Error conditions returned by #M_sql_report_fetch_cb_t */
63typedef enum {
64 M_SQL_REPORT_ERROR = 0, /*!< Error, abort report generation */
65 M_SQL_REPORT_SUCCESS = 1, /*!< Success */
66 M_SQL_REPORT_SKIP_ROW = 2 /*!< Do not output this row, but continue */
68
69
70struct M_sql_report;
71/*! Object holding the definition for report processing */
72typedef struct M_sql_report M_sql_report_t;
73
74struct M_sql_report_state;
75/*! Object holding state data for M_sql_report_process_partial() */
76typedef struct M_sql_report_state M_sql_report_state_t;
77
78
79/*! Create a report object for processing SQL query results into a delimited data form.
80 *
81 * Report processing is often used to turn SQL query results into delimited data
82 * like CSV.
83 *
84 * Each column to be output must be defined, or set #M_SQL_REPORT_FLAG_PASSTHRU_UNLISTED
85 * to pass through the data elements in their native form.
86 *
87 * \param[in] flags Bitmap of #M_sql_report_flags_t values to control behavior.
88 * \return Initialized report object
89 */
90M_API M_sql_report_t *M_sql_report_create(M_uint32 flags);
91
92
93/*! Destroy the report object.
94 *
95 * \param[in] report Report object to be destroyed.
96 */
98
99/*! Set desired CSV delimiters, encapsulation, and escaping sequences to be used for the
100 * output data. Ignored for JSON.
101 *
102 * If this function is not called, the defaults are used.
103 *
104 * \param[in] report Initialized report object.
105 * \param[in] field_delim Delimiter to use between fields, default is a comma (,). NULL to not change.
106 * \param[in] field_delim_size Number of characters used in field delimiter. Max size 8.
107 * \param[in] row_delim Delimiter to use between rows, default is a new line (\\r\\n - CRLF). NULL to not change.
108 * \param[in] row_delim_size Number of characters used in row delimiter. Max size 8.
109 * \param[in] field_encaps Encapsulation character to use for field data that may
110 * contain the field_delim or row_delim, default is a double quote. NULL to not change.
111 * \param[in] field_encaps_size Number of characters used in field encapsulation. Max size 8.
112 * \param[in] field_escape Escape character to use if the field contains the encapsulation char,
113 * default is the same as the encapsulation, a double quote ("), as this is
114 * what is defined by RFC4180 (CSV)
115 * \param[in] field_escape_size Number of characters used in field escaping. Max size 8.
116 * \return M_TRUE on success, M_FALSE on usage error.
117 */
118M_API M_bool M_sql_report_set_delims(M_sql_report_t *report, const unsigned char *field_delim, size_t field_delim_size, const unsigned char *row_delim, size_t row_delim_size, const unsigned char *field_encaps, size_t field_encaps_size, const unsigned char *field_escape, size_t field_escape_size);
119
120
121/*! Prototype for fetch callback registered with M_sql_report_set_fetch_cb()
122 *
123 * \param[in] stmt Statement handle object after fetch
124 * \param[in] arg Argument passed to M_sql_report_process() or M_sql_report_process_partial().
125 *
126 * \return M_TRUE on success or M_FALSE on failure which will cause report processing to stop
127
128 */
129typedef M_bool (*M_sql_report_fetch_cb_t)(M_sql_stmt_t *stmt, void *arg);
130
131/*! Register a callback to be automatically called any time M_sql_stmt_fetch() is
132 * called successfully from within M_sql_report_process() or M_sql_report_process_partial().
133 *
134 * This may be used if some bulk operation needs to process the data just fetched
135 * prior to processing the individual rows that were fetched.
136 *
137 * \param[in] report Initialized report object
138 * \param[in] fetch_cb Callback to run every time M_sql_stmt_fetch() is successfully called.
139 * \return M_TRUE on success, or M_FALSE on error
140 */
142
143/*! Function callback prototype to use for cell formatting.
144 *
145 * This function signature is used to process every column in a report, the output buffer
146 * is passed in by reference of a certain length. If the buffer is insufficient for the
147 * needs of the formatting function, the caller should allocate a new pointer instead
148 * and set it to the new buffer location. The report generation function will automatically
149 * free the callback's buffer.
150 *
151 * \param[in] stmt Pointer to statement object being processed.
152 * \param[in] arg Custom user-supplied argument for registered callbacks.
153 * \param[in] name Assigned report name of column being processed (not necessarily the name of the SQL column returned)
154 * \param[in] row Row of result set currently being processed.
155 * \param[in] col Index of result set column being processed, or -1 if no specific column is referenced.
156 * \param[out] buf Pre-allocated #M_buf_t buffer is provided to write column output. The provided buffer is empty,
157 * it is not pre-filled with column data as 'col' may be -1 or otherwise not a 1:1 mapping between
158 * input and output columns. It is up to the person implementing the callback to use the normal
159 * \link m_sql_stmt_result M_sql_stmt_result_*() \endlink functions to get the desired data.
160 * \param[out] is_null Output parameter that if set to M_TRUE, will ignore any contents in buf. It will also prevent
161 * quoting of the output cell so the output differentiates a blank cell (quoted) vs a NULL cell
162 * (unquoted).
163 * \return \return #M_SQL_REPORT_SUCCESS on success or #M_SQL_REPORT_ERROR on failure which will cause report processing to stop
164 * or to just skip the row, return #M_SQL_REPORT_SKIP_ROW.
165 */
166typedef M_sql_report_cberror_t (*M_sql_report_cell_cb_t)(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null);
167
168/*! Callback template for column passthru.
169 *
170 * Any data on file will be passed-thru as-is, except for Binary data which will be automatically
171 * base64 encoded as the report output mandates string data only. If the cell is NULL, it will
172 * be output as blank.
173 */
174M_API M_sql_report_cberror_t M_sql_report_cell_cb_passthru(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null);
175
176/*! Callback template for outputting an integer column stored with a 2-digit implied decimal point as an actual
177 * decimal with 2 decimal places. E.g.:
178 * - 1 -> 0.01
179 * - 100 -> 1.00
180 * If the cell is NULL, a blank column will be output instead of 0.00
181 */
182M_API M_sql_report_cberror_t M_sql_report_cell_cb_int2dec(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null);
183
184/*! Callback template for outputting an integer column stored with a 5-digit implied decimal point as an actual
185 * decimal with 5 decimal places. E.g.:
186 * - 1 -> 0.00001
187 * - 100000 -> 1.00000
188 * If the cell is NULL, a blank column will be output instead of 0.00000
189 */
190M_API M_sql_report_cberror_t M_sql_report_cell_cb_int5dec(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null);
191
192/*! Callback template for outputting an integer column stored with a 5-digit implied decimal point as an actual
193 * decimal with between 2 and 5 decimal places. E.g.:
194 * - 1 -> 0.00001
195 * - 123000 -> 1.23
196 * - 111111 -> 1.11111
197 * If the cell is NULL, a blank column will be output instead of 0.00000
198 */
199M_API M_sql_report_cberror_t M_sql_report_cell_cb_int5min2dec(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null);
200
201/*! Callback template for outputting a boolean value column with yes or no.
202 *
203 * If the cell is NULL, a blank column will be output instead of yes or no.
204 */
205M_API M_sql_report_cberror_t M_sql_report_cell_cb_boolyesno(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null);
206
207/*! Register column to be output in report.
208 *
209 * If #M_SQL_REPORT_FLAG_PASSTHRU_UNLISTED was used to initialize the report object, then
210 * if the sql_col_name or sql_col_idx matches a column (rather than being NULL and -1, respectively),
211 * then instead of adding a column, it overwrites its behavior ... either output column name, or the
212 * default callback can be changed from the default of passthrough.
213 *
214 * \param[in] report Initialized report object.
215 * \param[in] name Name of column (used for headers in report)
216 * \param[in] cb Callback to use for formatting the column.
217 * \param[in] sql_col_name Optional, use NULL if not provieded. Retuned SQL column name returned with the
218 * data from the SQL server. This will be dereferenced and passed to the callback.
219 * \param[in] sql_col_idx Optional, use -1 if not provided. Returned SQL column index returned with the
220 * data from the SQL server. This will be passed to the callback.
221 * \return M_TRUE on success, M_FALSE on failure (misuse) */
222M_API M_bool M_sql_report_add_column(M_sql_report_t *report, const char *name, M_sql_report_cell_cb_t cb, const char *sql_col_name, ssize_t sql_col_idx);
223
224/*! Hide a column from a report if #M_SQL_REPORT_FLAG_PASSTHRU_UNLISTED was set.
225 *
226 * When #M_SQL_REPORT_FLAG_PASSTHRU_UNLISTED all columns in a report will be listed. This can
227 * be used to hide specific columns.
228 *
229 * \param[in] report Initialized report object.
230 * \param[in] sql_col_name Conditional. Name of column to hide, or NULL. Must be set if sql_col_idx is -1.
231 * \param[in] sql_col_idx Conditional. Index of column to hide, or -1. Must be set if sql_col_name is NULL.
232 * \return M_TRUE on success, M_FALSE on misuse.
233 */
234M_API M_bool M_sql_report_hide_column(M_sql_report_t *report, const char *sql_col_name, ssize_t sql_col_idx);
235
236
237struct M_sql_report_filter;
238/*! Filter object created by M_sql_report_filter_create() */
239typedef struct M_sql_report_filter M_sql_report_filter_t;
240
241typedef enum {
242 M_SQL_REPORT_FILTER_TYPE_OR = 1, /*!< Rules for filter will be treated as OR */
243 M_SQL_REPORT_FILTER_TYPE_AND = 2 /*!< Rules for filter will be treated as AND */
245
246/*! Create filter object
247 *
248 * \param[in] type Type of filter to create
249 * \return filter object on success
250 */
252
253/*! Destroy filter object
254 *
255 * \note Do NOT call if passed to M_sql_report_add_filter() as it takes ownership
256 *
257 * \param[in] filter Initialized filter object by M_sql_report_filter_create()
258 */
260
261typedef enum {
262 M_SQL_REPORT_FILTER_RULE_MATCHES = 1, /*!< Data matches */
263 M_SQL_REPORT_FILTER_RULE_NOT_MATCHES, /*!< Data does not match */
264 M_SQL_REPORT_FILTER_RULE_CONTAINS, /*!< Data contains (sub string) */
265 M_SQL_REPORT_FILTER_RULE_NOT_CONTAINS, /*!< Data does not contain (sub string) */
266 M_SQL_REPORT_FILTER_RULE_BEGINS_WITH, /*!< Data begins with */
267 M_SQL_REPORT_FILTER_RULE_NOT_BEGINS_WITH, /*!< Data does not begin with */
269 M_SQL_REPORT_FILTER_RULE_NOT_ENDS_WITH, /*!< Data does not end with */
270 M_SQL_REPORT_FILTER_RULE_EMPTY, /*!< Data is empty */
271 M_SQL_REPORT_FILTER_RULE_NOT_EMPTY /*!< Data is not empty */
273
274/*! Add filter rule
275 *
276 * \note when using OR type filters, you can specify the same column more than once
277 *
278 * \param[in] filter Initialized filter object from M_sql_report_filter_create()
279 * \param[in] column Name of column in report
280 * \param[in] rule Type of rule
281 * \param[in] case_insensitive For rules with data, whether the data should match case insensitive or not
282 * \param[in] data Data for matching
283 * \return M_TRUE on success, M_FALSE on failure
284 *
285 */
286M_API M_bool M_sql_report_filter_add_rule(M_sql_report_filter_t *filter, const char *column, M_sql_report_filter_rule_t rule, M_bool case_insensitive, const char *data);
287
288
289/*! Attach a filter to a report. Only a single filter can be added to a report.
290 *
291 * \note in the future filters will be allowed to add subfilters to do complex logic, but that is not yet supported
292 *
293 * This function will take ownership of the filter object
294 * \param[in] report Initialized report object
295 * \param[in] filter Initialized filter object with at least one rule
296 * \return M_TRUE on success, M_FALSE on failure (such as bad arguments)
297 */
299
300
301/*! Process the results from the SQL statement based on the report template configured.
302 *
303 * This function will call the registered report output generation functions to output
304 * each desired column of the report. If row fetching is used due to M_sql_stmt_set_max_fetch_rows(),
305 * this will automatically call M_sql_stmt_fetch() until all rows are returned.
306 *
307 * No state is tracked in the report handle, it may be reused, and used concurrently if
308 * the implementor decides to cache the handle.
309 *
310 * \param[in] report Initialized report object.
311 * \param[in] stmt Executed statement handle.
312 * \param[in] arg Custom user-supplied argument to be passed through to registered callbacks for column formatting.
313 * \param[out] out Formatted report data is returned in this variable and must be free'd by the caller.
314 * \param[out] out_len Optional. Returned length of output data. Should be equivalent to M_str_len(out), but
315 * on huge reports may be more efficient to already know the size.
316 * \param[out] error Buffer to hold error message.
317 * \param[in] error_size Size of error buffer passed in.
318 * \return #M_SQL_ERROR_SUCCESS on success, or one of the #M_sql_error_t error conditions. If an internal error is
319 * generated, the text from the error can be found in the statement handle's error buffer via
320 * M_sql_stmt_get_error_string().
321 */
322M_API M_sql_error_t M_sql_report_process(const M_sql_report_t *report, M_sql_stmt_t *stmt, void *arg, char **out, size_t *out_len, char *error, size_t error_size);
323
324
325/*! Process the results from the SQL statement based on the report template configured and
326 * append to the provided JSON array.
327 *
328 * This function will call the registered report output generation functions to output
329 * each desired column of the report. If row fetching is used due to M_sql_stmt_set_max_fetch_rows(),
330 * this will automatically call M_sql_stmt_fetch() until all rows are returned.
331 *
332 * No state is tracked in the report handle, it may be reused, and used concurrently if
333 * the implementor decides to cache the handle.
334 *
335 * \param[in] report Initialized report object.
336 * \param[in] stmt Executed statement handle.
337 * \param[in] arg Custom user-supplied argument to be passed through to registered callbacks for column formatting.
338 * \param[in,out] json Passed in initialized json array node that each row will be appended to.
339 * \param[out] error Buffer to hold error message.
340 * \param[in] error_size Size of error buffer passed in.
341 * \return #M_SQL_ERROR_SUCCESS on success, or one of the #M_sql_error_t error conditions. If an internal error is
342 * generated, the text from the error can be found in the statement handle's error buffer via
343 * M_sql_stmt_get_error_string().
344 */
345M_API M_sql_error_t M_sql_report_process_json(const M_sql_report_t *report, M_sql_stmt_t *stmt, void *arg, M_json_node_t *json, char *error, size_t error_size);
346
347
348/*! Process a chunk of report data rather than the whole report.
349 *
350 * This function is useful if it is necessary to send a report in pieces either to a file
351 * or via a network connection, especially if the report may become extremely large and
352 * exceed the memory capabilities of the machine.
353 *
354 * This function will be called in a loop until the return value is NOT #M_SQL_ERROR_SUCCESS_ROW,
355 * it will fill in the user-supplied #M_buf_t with the data. It is up to the user to clear
356 * the data from this buffer if the same buffer handle is passed in, or create a new handle,
357 * otherwise data will be appended.
358 *
359 * \warning The caller MUST call this repeatedly until a return value other than #M_SQL_ERROR_SUCCESS_ROW is
360 * returned or otherwise risk memory leaks, or possibly holding a lock on an SQL connection.
361 *
362 * \param[in] report Initialized report object.
363 * \param[in] stmt Executed statement handle.
364 * \param[in] max_rows Maximum number of rows to output per pass. Or 0 to output all. Typically it makes
365 * more sense to just call M_sql_report_process() if you want to use 0 for this value.
366 * \param[in] arg Custom user-supplied argument to be passed through to registered callbacks for column formatting.
367 * \param[in,out] buf User-supplied buffer to append report data to.
368 * \param[in,out] state Pointer to an #M_sql_report_state_t * object, initialized to NULL on first pass. When there
369 * are more rows available, pass the same returned pointer back in. When the report generation
370 * is complete (last pass), this pointer will be automatically cleaned up.
371 * \param[out] error Buffer to hold error message.
372 * \param[in] error_size Size of error buffer passed in.
373 * \return #M_SQL_ERROR_SUCCESS on successful completion of the report, or #M_SQL_ERROR_SUCCESS_ROW if this function
374 * must be called again to get the remaining report data. On failure, one of the #M_sql_error_t errors may
375 * be returned
376 */
377M_API M_sql_error_t M_sql_report_process_partial(const M_sql_report_t *report, M_sql_stmt_t *stmt, size_t max_rows, void *arg, M_buf_t *buf, M_sql_report_state_t **state, char *error, size_t error_size);
378
379/*! If for some reason a report must be aborted when using partial processing, this will clear up the memory associated
380 * with the state handle
381 *
382 * \param[in] state #M_sql_report_state_t * object populated from M_sql_report_process_partial() or M_sql_report_process_partial_json()
383 */
385
386/*! Process a chunk of report data rather than the whole report and append to the provided JSON array.
387 *
388 * This function is useful if it is necessary to send a report in pieces either to a file
389 * or via a network connection, especially if the report may become extremely large and
390 * exceed the memory capabilities of the machine.
391 *
392 * This function will be called in a loop until the return value is NOT #M_SQL_ERROR_SUCCESS_ROW,
393 * it will fill in the user-supplied #M_buf_t with the data. It is up to the user to clear
394 * the data from this buffer if the same buffer handle is passed in, or create a new handle,
395 * otherwise data will be appended.
396 *
397 * \warning The caller MUST call this repeatedly until a return value other than #M_SQL_ERROR_SUCCESS_ROW is
398 * returned or otherwise risk memory leaks, or possibly holding a lock on an SQL connection.
399 *
400 * \param[in] report Initialized report object.
401 * \param[in] stmt Executed statement handle.
402 * \param[in] max_rows Maximum number of rows to output per pass. Or 0 to output all. Typically it makes
403 * more sense to just call M_sql_report_process() if you want to use 0 for this value.
404 * \param[in] arg Custom user-supplied argument to be passed through to registered callbacks for column formatting.
405 * \param[in,out] json Passed in initialized json array node that each row will be appended to.
406 * \param[in,out] state Pointer to an #M_sql_report_state_t * object, initialized to NULL on first pass. When there
407 * are more rows available, pass the same returned pointer back in. When the report generation
408 * is complete (last pass), this pointer will be automatically cleaned up.
409 * \param[out] error Buffer to hold error message.
410 * \param[in] error_size Size of error buffer passed in.
411 * \return #M_SQL_ERROR_SUCCESS on successful completion of the report, or #M_SQL_ERROR_SUCCESS_ROW if this function
412 * must be called again to get the remaining report data. On failure, one of the #M_sql_error_t errors may
413 * be returned
414 */
415M_API M_sql_error_t M_sql_report_process_partial_json(const M_sql_report_t *report, M_sql_stmt_t *stmt, size_t max_rows, void *arg, M_json_node_t *json, M_sql_report_state_t **state, char *error, size_t error_size);
416
417
418/*! @} */
419
420__END_DECLS
421
422#endif /* __M_SQL_REPORT_H__ */
struct M_buf M_buf_t
Definition: m_buf.h:77
struct M_json_node M_json_node_t
Definition: m_json.h:95
M_sql_error_t
Definition: m_sql.h:190
struct M_sql_report_state M_sql_report_state_t
Definition: m_sql_report.h:76
M_sql_report_filter_t * M_sql_report_filter_create(M_sql_report_filter_type_t type)
M_sql_report_flags_t
Definition: m_sql_report.h:47
M_sql_report_cberror_t M_sql_report_cell_cb_passthru(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null)
M_sql_error_t M_sql_report_process_partial_json(const M_sql_report_t *report, M_sql_stmt_t *stmt, size_t max_rows, void *arg, M_json_node_t *json, M_sql_report_state_t **state, char *error, size_t error_size)
M_sql_report_filter_type_t
Definition: m_sql_report.h:241
M_sql_report_cberror_t M_sql_report_cell_cb_int5dec(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null)
M_bool M_sql_report_set_fetch_cb(M_sql_report_t *report, M_sql_report_fetch_cb_t fetch_cb)
struct M_sql_report_filter M_sql_report_filter_t
Definition: m_sql_report.h:239
M_sql_error_t M_sql_report_process_partial(const M_sql_report_t *report, M_sql_stmt_t *stmt, size_t max_rows, void *arg, M_buf_t *buf, M_sql_report_state_t **state, char *error, size_t error_size)
M_sql_report_cberror_t M_sql_report_cell_cb_int5min2dec(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null)
void M_sql_report_filter_destroy(M_sql_report_filter_t *filter)
M_bool M_sql_report_add_filter(M_sql_report_t *report, M_sql_report_filter_t *filter)
void M_sql_report_destroy(M_sql_report_t *report)
M_bool M_sql_report_filter_add_rule(M_sql_report_filter_t *filter, const char *column, M_sql_report_filter_rule_t rule, M_bool case_insensitive, const char *data)
M_sql_report_cberror_t M_sql_report_cell_cb_int2dec(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null)
M_sql_report_cberror_t(* M_sql_report_cell_cb_t)(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null)
Definition: m_sql_report.h:166
M_sql_report_t * M_sql_report_create(M_uint32 flags)
M_bool M_sql_report_set_delims(M_sql_report_t *report, const unsigned char *field_delim, size_t field_delim_size, const unsigned char *row_delim, size_t row_delim_size, const unsigned char *field_encaps, size_t field_encaps_size, const unsigned char *field_escape, size_t field_escape_size)
struct M_sql_report M_sql_report_t
Definition: m_sql_report.h:72
M_sql_report_filter_rule_t
Definition: m_sql_report.h:261
M_bool M_sql_report_add_column(M_sql_report_t *report, const char *name, M_sql_report_cell_cb_t cb, const char *sql_col_name, ssize_t sql_col_idx)
M_bool(* M_sql_report_fetch_cb_t)(M_sql_stmt_t *stmt, void *arg)
Definition: m_sql_report.h:129
void M_sql_report_state_cancel(M_sql_report_state_t *state)
M_sql_report_cberror_t M_sql_report_cell_cb_boolyesno(M_sql_stmt_t *stmt, void *arg, const char *name, size_t row, ssize_t col, M_buf_t *buf, M_bool *is_null)
M_sql_error_t M_sql_report_process(const M_sql_report_t *report, M_sql_stmt_t *stmt, void *arg, char **out, size_t *out_len, char *error, size_t error_size)
M_sql_error_t M_sql_report_process_json(const M_sql_report_t *report, M_sql_stmt_t *stmt, void *arg, M_json_node_t *json, char *error, size_t error_size)
M_bool M_sql_report_hide_column(M_sql_report_t *report, const char *sql_col_name, ssize_t sql_col_idx)
M_sql_report_cberror_t
Definition: m_sql_report.h:63
@ M_SQL_REPORT_FLAG_OMIT_HEADERS
Definition: m_sql_report.h:52
@ M_SQL_REPORT_FLAG_PASSTHRU_UNLISTED
Definition: m_sql_report.h:53
@ M_SQL_REPORT_FLAG_NONE
Definition: m_sql_report.h:48
@ M_SQL_REPORT_FLAG_ALWAYS_ENCAP
Definition: m_sql_report.h:49
@ M_SQL_REPORT_FILTER_TYPE_AND
Definition: m_sql_report.h:243
@ M_SQL_REPORT_FILTER_TYPE_OR
Definition: m_sql_report.h:242
@ M_SQL_REPORT_FILTER_RULE_CONTAINS
Definition: m_sql_report.h:264
@ M_SQL_REPORT_FILTER_RULE_NOT_CONTAINS
Definition: m_sql_report.h:265
@ M_SQL_REPORT_FILTER_RULE_NOT_EMPTY
Definition: m_sql_report.h:271
@ M_SQL_REPORT_FILTER_RULE_BEGINS_WITH
Definition: m_sql_report.h:266
@ M_SQL_REPORT_FILTER_RULE_NOT_BEGINS_WITH
Definition: m_sql_report.h:267
@ M_SQL_REPORT_FILTER_RULE_NOT_MATCHES
Definition: m_sql_report.h:263
@ M_SQL_REPORT_FILTER_RULE_ENDS_WITH
Definition: m_sql_report.h:268
@ M_SQL_REPORT_FILTER_RULE_MATCHES
Definition: m_sql_report.h:262
@ M_SQL_REPORT_FILTER_RULE_EMPTY
Definition: m_sql_report.h:270
@ M_SQL_REPORT_FILTER_RULE_NOT_ENDS_WITH
Definition: m_sql_report.h:269
@ M_SQL_REPORT_SUCCESS
Definition: m_sql_report.h:65
@ M_SQL_REPORT_SKIP_ROW
Definition: m_sql_report.h:66
@ M_SQL_REPORT_ERROR
Definition: m_sql_report.h:64
struct M_sql_stmt M_sql_stmt_t
Definition: m_sql_stmt.h:46