Mstdlib-1.24.0
m_sql_table.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_TABLE_H__
25#define __M_SQL_TABLE_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
33/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
34
35__BEGIN_DECLS
36
37/*! \addtogroup m_sql_schema SQL Table/Schema Management
38 * \ingroup m_sql
39 *
40 * SQL Table/Schema Management
41 *
42 * @{
43 */
44
45
46/*! Structure holding table definition */
47struct M_sql_table;
48/*! Type holding table definition */
49typedef struct M_sql_table M_sql_table_t;
50
51
52/*! Structure holding index definition */
53struct M_sql_index;
54/*! Type holding index definition */
55typedef struct M_sql_index M_sql_index_t;
56
57
58/*! Flags passed to M_sql_table_add_col() for a column */
59typedef enum {
60 M_SQL_TABLE_COL_FLAG_NONE = 0, /*!< Default, no special flags */
61 M_SQL_TABLE_COL_FLAG_NOTNULL = 1 << 0, /*!< Column is not allowed to be NULL */
63
64
65/*! Index creation flags used by M_sql_table_add_index() */
66typedef enum {
67 M_SQL_INDEX_FLAG_NONE = 0, /*!< Default, no special flags */
68 M_SQL_INDEX_FLAG_UNIQUE = 1 << 0 /*!< Index enforces a unique constraint */
70
71
72/*! Check to see if a table exists by name.
73 *
74 * \param[in] pool Initialized #M_sql_connpool_t object
75 * \param[in] name Table name to check for
76 * \return M_TRUE if table exists, M_FALSE otherwise
77 */
78M_API M_bool M_sql_table_exists(M_sql_connpool_t *pool, const char *name);
79
80
81/*! Create a table object which aids in creating a table definition, including
82 * indexes to be added to a database.
83 *
84 * Table names must start with an alpha character or underscore, and can only
85 * contain alpha-numerics and underscores.
86 *
87 * \warning Table names have a maximum length of 58 bytes, however if there are any indexes
88 * also created, then this maximum length cannot be used as the length of the table
89 * name and the length of the index name combined are limited to 58 bytes. Some older
90 * databases (like Oracle before 12c R2 [March 2017]) were limited to much smaller sizes (30),
91 * it is therefore recommended to keep table names as short as possible, as a rule of thumb,
92 * 15 or fewer characters should be safe.
93 *
94 * \note All tables require primary keys (added via M_sql_table_add_pk_col()) and failure
95 * will occur if one tries to add a table without a primary key.
96 *
97 * The table will not be created until M_sql_table_execute() is called.
98 *
99 * \param[in] name Table name to create
100 * \return Table object, or NULL on error. Use M_sql_table_destroy() to free the object.
101 */
102M_API M_sql_table_t *M_sql_table_create(const char *name);
103
104
105/*! Destroy a table object created with M_sql_table_create().
106 *
107 * \param[in] table Table object initialized by M_sql_table_create()
108 */
110
111
112/*! Add a column to a table.
113 *
114 * Column names have a maximum length of 63 characters and must start with
115 * an alpha character or underscore, and can only contain alpha-numerics and
116 * underscores. However, some older databases might have shorter limits, such
117 * as versions of Oracle prior to 12c R2 (March 2017), were limited to 30 characters.
118 *
119 * \param[in] table Table object initialized by M_sql_table_create()
120 * \param[in] flags Bitmap of #M_sql_table_col_flags_t flags
121 * \param[in] col_name Column name to create.
122 * \param[in] datatype Datatype of column
123 * \param[in] max_len Maximum length of column (meant for text or binary columns). Use 0 for
124 * the maximum size supported by the database for the data type. It is
125 * strongly recommended to specify a reasonable maximum size as it may
126 * have a significant impact on performance of some databases. Typically
127 * databases have maximum row sizes, and data over these limits will be
128 * stored separately (meaning the sum of all columns also matters).
129 * \param[in] default_value Default value to assign to column. There is little to no
130 * validation performed on this value, use caution as it is
131 * inserted directly into the create statement. Strings must
132 * be quoted with single quotes.
133 * \return M_TRUE on success, M_FALSE on error (most likely usage, bad name or type)
134 */
135M_API M_bool M_sql_table_add_col(M_sql_table_t *table, M_uint32 flags, const char *col_name, M_sql_data_type_t datatype, size_t max_len, const char *default_value);
136
137
138/*! Add a column in the table to the primary key.
139 *
140 * The order in which the columns are added to the primary key is how the
141 * primary key will be indexed/created.
142 *
143 * The column name specified must exist in the table object.
144 *
145 * \param[in] table Table object initialized by M_sql_table_create()
146 * \param[in] col_name Column name to add to the primary key
147 * \return M_TRUE on success, M_FALSE on error (such as misuse)
148 */
149M_API M_bool M_sql_table_add_pk_col(M_sql_table_t *table, const char *col_name);
150
151
152/*! Add an index to the table
153 *
154 * \warning Index names have a maximum length of 58 bytes minus the table name
155 * length
156 *
157 * \param[in] table Table object initialized by M_sql_table_create()
158 * \param[in] flags Bitmap of #M_sql_table_index_flags_t flags
159 * \param[in] idx_name User-chosen index name. This should be as short as reasonably possible.
160 * \return Index object on success, NULL on failure (misuse)
161 */
162M_API M_sql_index_t *M_sql_table_add_index(M_sql_table_t *table, M_uint32 flags, const char *idx_name);
163
164
165/*! Add a column to an index
166 *
167 * The order in which the columns are added to the index is how the
168 * it will be indexed/created.
169 *
170 * The referenced column name must exist in the table definition.
171 *
172 * \param[in] idx Index object initialized by M_sql_table_add_index()
173 * \param[in] col_name Column name to add to index
174 * \return M_TRUE on success, M_FALSE on failure/misuse.
175 */
176M_API M_bool M_sql_index_add_col(M_sql_index_t *idx, const char *col_name);
177
178
179/*! Simplified method to add an index to a table using a comma-delimited string of column names.
180 *
181 * Identical to M_sql_table_add_index() followed by M_sql_index_add_col() for each
182 * column in the comma-separated string.
183 *
184 * \param[in] table Table object initialized by M_sql_table_create()
185 * \param[in] flags Bitmap of #M_sql_table_index_flags_t flags
186 * \param[in] idx_name User-chosen index name. This should be as short as reasonably possible.
187 * \param[in] idx_cols_csv Comma separated list of column names to add to the index. The columns
188 * must already exist in the table object.
189 * \return M_TRUE on success, M_FALSE on error/misuse
190 */
191M_API M_bool M_sql_table_add_index_str(M_sql_table_t *table, M_uint32 flags, const char *idx_name, const char *idx_cols_csv);
192
193
194/*! Apply the table object definition to the database.
195 *
196 * \note This does not destroy the table object. Use M_sql_table_destroy() for that.
197 *
198 * \param[in] pool Initialized #M_sql_connpool_t object
199 * \param[in] table Table object initialized by M_sql_table_create() and populated with columns/indexes and primary keys.
200 * \param[out] error User-supplied error buffer to output error message.
201 * \param[in] error_size Size of user-supplied error buffer
202 * \return #M_SQL_ERROR_SUCCESS on success, or one of the #M_sql_error_t return values on failure.
203 */
204M_API M_sql_error_t M_sql_table_execute(M_sql_connpool_t *pool, M_sql_table_t *table, char *error, size_t error_size);
205
206/*! @} */
207
208/*! \addtogroup m_sql_tabledata SQL Table Data Management
209 * \ingroup m_sql
210 *
211 * SQL Table Data Management
212 *
213 * @{
214 */
215
216
217/*! Opaque structure holding field data. */
218struct M_sql_tabledata_field;
219
220/*! Opaque structure holding field data. Use corresponding setters/getters to manipulate. */
221typedef struct M_sql_tabledata_field M_sql_tabledata_field_t;
222
223/*! Opaque Data structure holding add/edit request transaction data. */
224struct M_sql_tabledata_txn;
225
226/*! Opaque Data structure holding add/edit request transaction data. Use the M_sql_tabledata_txn_*() functions to access/modify */
227typedef struct M_sql_tabledata_txn M_sql_tabledata_txn_t;
228
229/*! Flags for processing table data fields / columns */
230typedef enum {
231 M_SQL_TABLEDATA_FLAG_NONE = 0, /*!< No Flags */
232 M_SQL_TABLEDATA_FLAG_VIRTUAL = 1 << 0, /*!< Field is a virtual column, multiple serialized virtual columns can be stored in a single 'real' database column under 'table_column'. Any data type except binary may be used. */
233 M_SQL_TABLEDATA_FLAG_EDITABLE = 1 << 1, /*!< Field is allowed to be edited, not add-only */
234 M_SQL_TABLEDATA_FLAG_NOTNULL = 1 << 2, /*!< Field must be specified and is not allowed to be NULL */
235 M_SQL_TABLEDATA_FLAG_ID = 1 << 3, /*!< Field is an ID column (meaning it is used for lookups). Can be assigned on add,
236 * but cannot be used with M_SQL_TABLEDATA_FLAG_EDITABLE or M_SQL_TABLEDATA_FLAG_VIRTUAL. */
237 M_SQL_TABLEDATA_FLAG_ID_GENERATE = 1 << 4, /*!< Auto-generate the ID on the user's behalf. Must be an ID field. Only one allowed per field definition list. */
238 M_SQL_TABLEDATA_FLAG_ID_REQUIRED = 1 << 5, /*!< On edits, this ID must be specified. On some DBs, you may not have any required IDs
239 * as there may be multiple lookup indexes */
240 M_SQL_TABLEDATA_FLAG_TIMESTAMP = 1 << 6, /*!< Field is an auto-generated unix timestamp. Must be INT64. Cannot be specified with ID. Field fetcher will never be called. If M_SQL_TABLEDATA_FLAG_EDITABLE is specified, will update on edit */
241 M_SQL_TABLEDATA_FLAG_ALLOW_NONPRINT_SEP = 1 << 7, /*!< Allow non-printable characters designated as separators (e.g. 0x1C, 0x1D, 0x1E) */
243
244
245/*! A callback to perform basic filtering and transformation of a user-input field to how it needs to be
246 * stored within the database. This can also reject the data and return an error if it does
247 * not meet the requirements.
248 *
249 * This callback is called only when new user data is provided. It will not be called if a field isn't
250 * passed in. For instance, on an edit operation, this callback will NOT be called if the user did not
251 * supply the field as the only data we have is the data from the database which is already sanitized.
252 * This also goes for an add operation, if not provided by the user, this callback is NOT called.
253 *
254 * \param[in] txn Transaction data. May be used to retrieve other useful information that may be needed for proper validation.
255 * \param[in] field_name Name of field
256 * \param[in,out] field Current data in field. This should be modified in-place if needed to be transformed.
257 * \param[out] error Buffer to hold error message
258 * \param[in] error_len Length of error buffer
259 * \return M_TRUE on success, M_FALSE on failure (set error buffer!)
260 */
261typedef M_bool (*M_sql_tabledata_filtertransform_cb)(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
262
263/*! Implementation of M_sql_tabledata_filtertransform_cb to validate and transform a decimal value with 2 places to an integer with 2 implied decimal places */
264M_API M_bool M_sql_tabledata_filter_int2dec_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
265
266/*! Implementation of M_sql_tabledata_filtertransform_cb to validate and transform a decimal value with 5 places to an integer with 5 implied decimal places */
267M_API M_bool M_sql_tabledata_filter_int5dec_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
268
269/*! Implementation of M_sql_tabledata_filtertransform_cb to validate a string is alpha numeric */
270M_API M_bool M_sql_tabledata_filter_alnum_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
271
272/*! Implementation of M_sql_tabledata_filtertransform_cb to validate a string is alpha numeric with possible spaces */
273M_API M_bool M_sql_tabledata_filter_alnumsp_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
274
275/*! Implementation of M_sql_tabledata_filtertransform_cb to validate a string is alpha only */
276M_API M_bool M_sql_tabledata_filter_alpha_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
277
278/*! Implementation of M_sql_tabledata_filtertransform_cb to validate a string is graph only */
279M_API M_bool M_sql_tabledata_filter_graph_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len);
280
281
282/*! A callback to perform intensive validation of the data field, which may require performing additional SQL queries.
283 *
284 * This callback is always called for the field, regardless of if it has changed. This includes on add even if a field
285 * isn't specified as it may be required to validate if maybe the field really should have been provided.
286 * Recommended to call M_sql_tabledata_txn_field_changed() if only need to perform operations when the field has changed.
287 *
288 * The field data is not provided and must be fetched via M_sql_tabledata_txn_field_get() as it is not known which variant
289 * of the data may be needed.
290 *
291 * The field data may be manipulated or transformed by this callback if desired.
292 *
293 * \param[in] sqltrans SQL transaction to use for any external queries needed.
294 * \param[in] txn Transaction data. May be used to retrieve other useful information that may be needed for proper validation.
295 * \param[in] field_name Name of field
296 * \param[out] error Buffer to hold error message
297 * \param[in] error_len Length of error buffer
298 * \return M_SQL_ERROR_SUCCESS or M_SQL_ERROR_USER_SUCCESS if validationsucceeded, other error otherwise (possibly retryable).
299 */
300typedef M_sql_error_t (*M_sql_tabledata_validate_cb)(M_sql_trans_t *sqltrans, M_sql_tabledata_txn_t *txn, const char *field_name, char *error, size_t error_len);
301
302
303/*! Structure to be used to define the various fields and columns stored in a table */
304typedef struct {
305 const char *table_column; /*!< Database column name */
306 const char *field_name; /*!< Field name to fetch in order to retrieve column data. For virtual columns, this field name is also used as the tag name. If NULL or blank, means field not used. Reserved for external modification. */
307 size_t max_column_len; /*!< Maximum text or binary length of column allowed. For M_SQL_TABLEDATA_FLAG_ID_GENERATE fields, it is the desired number of digits to generate */
308 M_sql_data_type_t type; /*!< Column data type */
309 M_sql_tabledata_flags_t flags; /*!< Flags controlling behavior */
310 M_sql_tabledata_filtertransform_cb filter_cb; /*!< Callback to filter or transform input data. Called only on new user-specified params. */
311 M_sql_tabledata_validate_cb validate_cb; /*!< Callback for in-depth validation of input data that may require external SQL queries. */
313
314
315/* -------------------------------------------------------------------------- */
316
317/*! FOR EXTERNAL USE ONLY. Create a new #M_sql_tabledata_field_t
318 *
319 * This is only for use outside of M_sql_tabledata_* functions.
320 *
321 * \return new allocated tabledata field
322 */
324
325/*! FOR EXTERNAL USE ONLY. Destroys a #M_sql_tabledata_field_t explicitly allocated by M_sql_tabledata_field_create_ext()
326 *
327 * This is only for use outside of M_sql_tabledata_* functions.
328 * NEVER call this on a handle provided by #M_sql_tabledata_fetch_cb or retrieved by M_sql_tabledata_txn_field_get()
329 *
330 * \param[in] field Field to be destroyed
331 */
333
334/*! Set the field pointer to a boolean value.
335 * Will override existing value and deallocate any prior memory consumed if necessary
336 * \param[in,out] field Field to set
337 * \param[in] val Value to set. May be NULL if just error ch
338 */
340
341/*! Set the field pointer to a 16bit integer
342 * Will override existing value and deallocate any prior memory consumed if necessary
343 * \param[in,out] field Field to set
344 * \param[in] val Value to set
345 */
347
348/*! Set the field pointer to a 32bit integer
349 * Will override existing value and deallocate any prior memory consumed if necessary
350 * \param[in,out] field Field to set
351 * \param[in] val Value to set
352 */
354
355/*! Set the field pointer to a 64bit integer.
356 * Will override existing value and deallocate any prior memory consumed if necessary
357 * \param[in,out] field Field to set
358 * \param[in] val Value to set
359 */
361
362/*! Set the field pointer to a text value and will take ownership of pointer passed (will be freed automatically).
363 * Will override existing value and deallocate any prior memory consumed if necessary
364 * \param[in,out] field Field to set
365 * \param[in] val Value to set
366 */
368
369/*! Set the field pointer to a text value and will duplicate the pointer passed.
370 * Will override existing value and deallocate any prior memory consumed if necessary
371 * \param[in,out] field Field to set
372 * \param[in] val Value to set
373 */
375
376/*! Set the field pointer to a text value and will treat the pointer as const, it must be valid until field is deallocated.
377 * Will override existing value and deallocate any prior memory consumed if necessary
378 * \param[in,out] field Field to set
379 * \param[in] val Value to set
380 */
382
383/*! Set the field pointer to a binary value and will duplicate the pointer passed.
384 * Will override existing value and deallocate any prior memory consumed if necessary
385 * \param[in,out] field Field to set
386 * \param[in] val Value to set
387 * \param[in] len Length of value
388 */
389M_API void M_sql_tabledata_field_set_binary_own(M_sql_tabledata_field_t *field, unsigned char *val, size_t len);
390
391/*! Set the field pointer to a binary value and will duplicate the pointer passed.
392 * Will override existing value and deallocate any prior memory consumed if necessary
393 * \param[in,out] field Field to set
394 * \param[in] val Value to set
395 * \param[in] len Length of value
396 */
397M_API void M_sql_tabledata_field_set_binary_dup(M_sql_tabledata_field_t *field, const unsigned char *val, size_t len);
398
399/*! Set the field pointer to a binary value and will treat the pointer as const, it must be valid until field is deallocated.
400 * Will override existing value and deallocate any prior memory consumed if necessary
401 * \param[in,out] field Field to set
402 * \param[in] val Value to set
403 * \param[in] len Length of value
404 */
405M_API void M_sql_tabledata_field_set_binary_const(M_sql_tabledata_field_t *field, const unsigned char *val, size_t len);
406
407/*! Set the field to NULL.
408 * Will override existing value and deallocate any prior memory consumed if necessary
409 * \param[in,out] field Field to set
410 */
412
413/*! Retrieve field data as a boolean. If type conversion is necessary, it will be performed such that integer values
414 * are treated as true if non-zero and false if zero. Text values must have a valid boolean string and evaluate as
415 * appropriate or return failure. Any other conversion will return failure.
416 *
417 * Once a field is fetched successfully as a bool, it is internally converted to a bool.
418 * \param[in,out] field Field to retrieve data from
419 * \param[out] val Boolean output value. May be NULL if just error checking.
420 * \return M_FALSE if conversion was not possible, M_TRUE if successful.
421 */
423
424/*! Retrieve field data as a 16bit integer. If type conversion is necessary, it will be performed such that integer values
425 * are truncated if possible, and boolean values are set to 1 or 0. Text values will be passed through a string conversion
426 * if numeric. Any other conversion will return failure.
427 *
428 * Once a field is fetched successfully as an int32, it is internally converted to an int32.
429 * \param[in,out] field Field to retrieve data from
430 * \param[out] val Int32 output value. May be NULL if just error checking.
431 * \return M_FALSE if conversion was not possible, M_TRUE if successful.
432 */
434
435/*! Retrieve field data as a 32bit integer. If type conversion is necessary, it will be performed such that integer values
436 * are truncated if possible, and boolean values are set to 1 or 0. Text values will be passed through a string conversion
437 * if numeric. Any other conversion will return failure.
438 *
439 * Once a field is fetched successfully as an int32, it is internally converted to an int32.
440 * \param[in,out] field Field to retrieve data from
441 * \param[out] val Int32 output value. May be NULL if just error checking.
442 * \return M_FALSE if conversion was not possible, M_TRUE if successful.
443 */
445
446/*! Retrieve field data as a 64bit integer. If type conversion is necessary, it will be performed such that integer values
447 * are expanded, and boolean values are set to 1 or 0. Text values will be passed through a string conversion
448 * if numeric. Any other conversion will return failure.
449 *
450 * Once a field is fetched successfully as an int64, it is internally converted to an int64
451 * \param[in,out] field Field to retrieve data from
452 * \param[out] val Int64 output value. May be NULL if just error checking.
453 * \return M_FALSE if conversion was not possible, M_TRUE if successful.
454 */
456
457/*! Retrieve field data as text. If type conversion is necessary, it will be performed such that integer values
458 * are converted to base10 strings, and boolean values are converted into "yes" and "no". ny other conversion will return failure.
459 *
460 * Once a field is fetched successfully as text, it is internally converted to text
461 * \param[in,out] field Field to retrieve data from
462 * \param[out] val Pointer to text value that is valid until another conversion occurs or is freed or out of scope. May return NULL if value is NULL. Input may be NULL if just error checking.
463 * \return M_FALSE if conversion was not possible, M_TRUE if successful.
464 */
465M_API M_bool M_sql_tabledata_field_get_text(M_sql_tabledata_field_t *field, const char **val);
466
467/*! Retrieve field data as binary.
468 *
469 * Binary fields are not eligible for conversion.
470 * \param[in,out] field Field to retrieve data from
471 * \param[out] val Pointer to binary value until freed or out of scope. May return NULL if value is NULL. Input may be NULL if just error checking.
472 * \param[out] len Length of value. May be NULL if just error checking, unless val is non-NULL.
473 * \return M_FALSE if conversion was not possible, M_TRUE if successful.
474 */
475M_API M_bool M_sql_tabledata_field_get_binary(M_sql_tabledata_field_t *field, const unsigned char **val, size_t *len);
476
477/*! Determine if field is NULL or not.
478 *
479 * \param[in] field Field to determine if value is NULL.
480 * \return M_TRUE if NULL, M_FALSE otherwise.
481 */
483
484/*! Determine if field is duplicated (non-const), meaning data will not survive once mutated or field is destroyed.
485 *
486 * \param[in] field Field to determine if is duplicated.
487 * \return M_TRUE if duplicated, M_FALSE if const.
488 */
490
491/*! Determine current field type. May change if setter or another getter is called.
492 *
493 * \param[in] field Field to retrieve type of.
494 * \return field type.
495 */
497
498
499/* -------------------------------------------------------------------------- */
500
501/*! Retrieve thunk parameter passed into transaction
502 *
503 * \param[in] txn Transaction provided to callback.
504 * \return thunk parameter or NULL if none
505 */
507
508/*! Retrieve table name parameter passed into transaction
509 *
510 * \param[in] txn Transaction provided to callback.
511 * \return table name, or NULL on error
512 */
514
515/*! Retrieve generated id during add operation
516 *
517 * \param[in] txn Transaction provided to callback.
518 * \return generated id or 0 on error
519 */
521
522/*! Retrieve if transaction is add (vs edit)
523 *
524 * \param[in] txn Transaction provided to callback.
525 * \return M_TRUE if is add, M_FALSE if is_edit (or misuse)
526 */
528
529
530/*! When fetching a field from a transaction, the manner in which to fetch */
531typedef enum {
532 M_SQL_TABLEDATA_TXN_FIELD_MERGED = 1, /*!< Grab the current specified value of the field, if not found, grab the prior value. On add, equivalent to M_SQL_TABLEDATA_TXN_FIELD_CURRENT. */
533 M_SQL_TABLEDATA_TXN_FIELD_MERGED_NODUPLICATE = 2, /*!< Grab the current specified value of the field, if not found, grab the prior value and duplicate it as the current value for editing. */
534 M_SQL_TABLEDATA_TXN_FIELD_PRIOR = 3, /*!< Grab the prior value of the field. On add, this is always NULL. */
535 M_SQL_TABLEDATA_TXN_FIELD_CURRENT_READONLY = 4, /*!< Grab the current specified value of the field. May not exist on edit if value is unchanged. */
536 M_SQL_TABLEDATA_TXN_FIELD_CURRENT = 5, /*!< Grab the current specified value of the field. If not found, create a new NULL field and return it for modification (field_name specified must be valid) */
538
539
540/*! Retrieve the field data associated with the field name in the current transaction.
541 *
542 * \param[in] txn Transaction provided to callback.
543 * \param[in] field_name Name of field
544 * \param[in] fselect Manner in which to select the field
545 * \return M_sql_tabledata_field_t on success, NULL on failure (not found, or invalid field name)
546 */
548
549
550/*! Retrieve if the field has changed. Text fields are evaluated case sensitive.
551 *
552 * \param[in] txn Transaction provided to callback.
553 * \param[in] field_name Name of field
554 * \return M_TRUE if the field is found and on an add, or has changed on an edit, M_FALSE otherwise
555 */
556M_API M_bool M_sql_tabledata_txn_field_changed(M_sql_tabledata_txn_t *txn, const char *field_name);
557
558
559/*! Retrieve if the field has changed. Text fields are evaluated case insensitively.
560 *
561 * \param[in] txn Transaction provided to callback.
562 * \param[in] field_name Name of field
563 * \return M_TRUE if the field is found and on an add, or has changed on an edit, M_FALSE otherwise
564 */
565M_API M_bool M_sql_tabledata_txn_field_changed_ci(M_sql_tabledata_txn_t *txn, const char *field_name);
566
567/*! Retrieve the field definition for a field name from the current transaction.
568 *
569 * \param[in] txn Transaction provided to callback.
570 * \param[in] field_name Name of field
571 * \return pointer to field definition, or NULL if not found
572 */
574
575
576/* -------------------------------------------------------------------------- */
577
578
579/*! Callback for fetching a table field.
580 *
581 * \param[out] out Pointer to M_sql_tabledata_field_t to be filled in. MUST allow NULL as it may be called during a 'test' operation.
582 * \param[in] field_name Field name being fetched
583 * \param[in] is_add M_TRUE if this is called during an add operation, M_FALSE otherwise.
584 * \param[in] thunk Thunk parameter for custom state tracking passed to parent function.
585 * \return M_FALSE if field was not found, M_TRUE otherwise */
586typedef M_bool (*M_sql_tabledata_fetch_cb)(M_sql_tabledata_field_t *out, const char *field_name, M_bool is_add, void *thunk);
587
588/*! Callback that is called at completion of an add/edit. Both the prior and new field data are available for the entire
589 * table. It may be necessary to do cross-table modifications based on a change, so this facilitates that ability. If
590 * making linked changes, you must use the passed in sqltrans parameter to ensure it is treated as a single atomic operation.
591 * On edit, this registered callback will be called on any successful condition, including no changed fields.
592 *
593 * \param[in] sqltrans SQL Transaction for chaining atomic actions
594 * \param[in] txn Tabledata transaction pointer to grab field data
595 * \param[in,out] error Buffer to hold error if any
596 * \param[in] error_len Size of error buffer
597 * \return one of the M_sql_error_t codes. Use M_SQL_ERROR_USER_SUCCESS if nothing changed, and M_SQL_ERROR_SUCCESS if this
598 * callback caused a change. Otherwise one of the error codes.
599 */
600typedef M_sql_error_t (*M_sql_tabledata_notify_cb)(M_sql_trans_t *sqltrans, M_sql_tabledata_txn_t *txn, char *error, size_t error_len);
601
602/*! Add a row to a table based on the table definition. If there are key conflicts, it will retry up to 10 times if an auto-generated ID column exists.
603 *
604 * Use M_sql_tabledata_trans_add() if inside of a transaction.
605 *
606 * \param[in] pool Required if sqltrans not passed. The handle to the SQL pool in use.
607 * \param[in] table_name Name of the table
608 * \param[in] fields List of fields (columns) in the table.
609 * \param[in] num_fields Number of fields in the list
610 * \param[in] fetch_cb Callback to be called to fetch each field/column.
611 * \param[in] notify_cb Optional. Callback to be called to be notified on successful completion.
612 * \param[in] thunk Thunk parameter for custom state tracking, will be passed to fetch_cb.
613 * \param[out] generated_id If a column had specified M_SQL_TABLEDATA_FLAG_ID_GENERATE, then this will return that id
614 * \param[in,out] error Buffer to hold error if any
615 * \param[in] error_len Size of error buffer
616 * \return one of the M_sql_error_t codes. Will return M_SQL_ERROR_USER_FAILURE on invalid usage of this function
617 */
618M_API M_sql_error_t M_sql_tabledata_add(M_sql_connpool_t *pool, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, M_int64 *generated_id, char *error, size_t error_len);
619
620
621/*! Add a row to a table based on the table definition. If there are key conflicts, it will retry up to 10 times if an auto-generated ID column exists.
622 *
623 * Use M_sql_tabledata_add() if not already in a transaction.
624 *
625 * \param[in] sqltrans Required if pool not passed. If run within a transaction, this must be passed.
626 * \param[in] table_name Name of the table
627 * \param[in] fields List of fields (columns) in the table.
628 * \param[in] num_fields Number of fields in the list
629 * \param[in] fetch_cb Callback to be called to fetch each field/column.
630 * \param[in] notify_cb Optional. Callback to be called to be notified on successful completion.
631 * \param[in] thunk Thunk parameter for custom state tracking, will be passed to fetch_cb.
632 * \param[out] generated_id If a column had specified M_SQL_TABLEDATA_FLAG_ID_GENERATE, then this will return that id
633 * \param[in,out] error Buffer to hold error if any
634 * \param[in] error_len Size of error buffer
635 * \return one of the M_sql_error_t codes. Will return M_SQL_ERROR_USER_FAILURE on invalid usage of this function
636 */
637M_API M_sql_error_t M_sql_tabledata_trans_add(M_sql_trans_t *sqltrans, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, M_int64 *generated_id, char *error, size_t error_len);
638
639
640/*! Edit an existing row in a table based on the field definitions. Not all fields need to be available on edit, only
641 * fields that are able to be fetched will be modified. It is valid to fetch a NULL value to explicitly set a column
642 * to NULL. The ID(s) specified must match exactly one row or a failure will be emitted.
643 *
644 * Use M_sql_tabledata_trans_edit() if already in a transaction.
645 *
646 * \param[in] pool Required if sqltrans not passed. The handle to the SQL pool in use.
647 * \param[in] table_name Name of the table
648 * \param[in] fields List of fields (columns) in the table.
649 * \param[in] num_fields Number of fields in the list
650 * \param[in] fetch_cb Callback to be called to fetch each field/column.
651 * \param[in] notify_cb Optional. Callback to be called to be notified on successful completion. (Even if no data changed)
652 * \param[in] thunk Thunk parameter for custom state tracking, will be passed to fetch_cb.
653 * \param[in,out] error Buffer to hold error if any
654 * \param[in] error_len Size of error buffer
655 * \return one of the M_sql_error_t codes. Will return M_SQL_ERROR_USER_FAILURE on invalid usage of this function.
656 * Will return M_SQL_ERROR_USER_SUCCESS when no updates were performed (passed in data matches on file data).
657 * M_SQL_ERROR_SUCCESS means a single row was changed.
658 */
659M_API M_sql_error_t M_sql_tabledata_edit(M_sql_connpool_t *pool, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len);
660
661/*! Edit an existing row in a table based on the field definitions. Not all fields need to be available on edit, only
662 * fields that are able to be fetched will be modified. It is valid to fetch a NULL value to explicitly set a column
663 * to NULL. The ID(s) specified must match exactly one row or a failure will be emitted.
664 *
665 * Use M_sql_tabledata_edit() if not already in a transaction.
666 *
667 * \param[in] sqltrans Required if pool not passed. If run within a transaction, this must be passed.
668 * \param[in] table_name Name of the table
669 * \param[in] fields List of fields (columns) in the table.
670 * \param[in] num_fields Number of fields in the list
671 * \param[in] fetch_cb Callback to be called to fetch each field/column.
672 * \param[in] notify_cb Optional. Callback to be called to be notified on successful completion. (Even if no data changed)
673 * \param[in] thunk Thunk parameter for custom state tracking, will be passed to fetch_cb.
674 * \param[in,out] error Buffer to hold error if any
675 * \param[in] error_len Size of error buffer
676 * \return one of the M_sql_error_t codes. Will return M_SQL_ERROR_USER_FAILURE on invalid usage of this function.
677 * Will return M_SQL_ERROR_USER_SUCCESS when no updates were performed (passed in data matches on file data).
678 * M_SQL_ERROR_SUCCESS means a single row was changed.
679 */
680M_API M_sql_error_t M_sql_tabledata_trans_edit(M_sql_trans_t *sqltrans, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len);
681
682/*! Edit an existing row, or if not found, insert in a table based on the field definitions. All fields should be sent.
683 * It is valid to fetch a NULL value to explicitly set a column to NULL. The ID(s) specified must match exactly one row
684 * or a failure will be emitted.
685 *
686 * Use M_sql_tabledata_trans_upsert() if already in a transaction.
687 *
688 * \param[in] pool Required if sqltrans not passed. The handle to the SQL pool in use.
689 * \param[in] table_name Name of the table
690 * \param[in] fields List of fields (columns) in the table.
691 * \param[in] num_fields Number of fields in the list
692 * \param[in] fetch_cb Callback to be called to fetch each field/column.
693 * \param[in] notify_cb Optional. Callback to be called to be notified on successful completion. (Only if data changed)
694 * \param[in] thunk Thunk parameter for custom state tracking, will be passed to fetch_cb.
695 * \param[in,out] error Buffer to hold error if any
696 * \param[in] error_len Size of error buffer
697 * \return one of the M_sql_error_t codes. Will return M_SQL_ERROR_USER_FAILURE on invalid usage of this function.
698 * Will return M_SQL_ERROR_USER_SUCCESS when no updates were performed (passed in data matches on file data).
699 * M_SQL_ERROR_SUCCESS means a single row was changed.
700 */
701M_API M_sql_error_t M_sql_tabledata_upsert(M_sql_connpool_t *pool, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len);
702
703/*! Edit an existing row, or if not found, insert in a table based on the field definitions. All fields should be sent.
704 * It is valid to fetch a NULL value to explicitly set a column to NULL. The ID(s) specified must match exactly one row
705 * or a failure will be emitted.
706 *
707 * Use M_sql_tabledata_upsert() if not already in a transaction.
708 *
709 * \param[in] sqltrans Required if pool not passed. If run within a transaction, this must be passed.
710 * \param[in] table_name Name of the table
711 * \param[in] fields List of fields (columns) in the table.
712 * \param[in] num_fields Number of fields in the list
713 * \param[in] fetch_cb Callback to be called to fetch each field/column.
714 * \param[in] notify_cb Optional. Callback to be called to be notified on successful completion. (Only if data changed)
715 * \param[in] thunk Thunk parameter for custom state tracking, will be passed to fetch_cb.
716 * \param[in,out] error Buffer to hold error if any
717 * \param[in] error_len Size of error buffer
718 * \return one of the M_sql_error_t codes. Will return M_SQL_ERROR_USER_FAILURE on invalid usage of this function.
719 * Will return M_SQL_ERROR_USER_SUCCESS when no updates were performed (passed in data matches on file data).
720 * M_SQL_ERROR_SUCCESS means a single row was changed.
721 */
722M_API M_sql_error_t M_sql_tabledata_trans_upsert(M_sql_trans_t *sqltrans, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len);
723
724
725/*! Convenience function to expand a list of tabledata fields base on an M_list_str_t list of
726 * virtual column names tied to a single table column that share the same attributes. All
727 * virtual columns are always stored as text.
728 *
729 * IMPORTANT: The passed in "table_column" and "field_names" MUST persist until the tabledata
730 * structure is no longer needed as they are used as const values internally.
731 *
732 * \param[in] fields Field list to expand. Original input is NOT modified.
733 * \param[in,out] num_fields On input, the size of the fields table passed in. On return, the new size.
734 * \param[in] table_column Name of real table column virtual columns are tied to. NOTE: Pointer must
735 * persist until returned table is no longer needed.
736 * \param[in] field_names List of virtual column names used to expand table. NOTE: Pointer must
737 * persist until returned table is no longer needed.
738 * \param[in] max_len Maximum field value length for each field name.
739 * \param[in] flags Shared field flags. M_SQL_TABLEDATA_FLAG_VIRTUAL is automatically added if not specified.
740 * \return Allocated tabledata structure. Must be M_free()'d when no longer needed.
741 */
742M_API M_sql_tabledata_t *M_sql_tabledata_append_virtual_list(const M_sql_tabledata_t *fields, size_t *num_fields, const char *table_column, const M_list_str_t *field_names, size_t max_len, M_sql_tabledata_flags_t flags);
743
744
745/*! Convenience function to try to auto-generate the table columns for table creation based on the same tabledata used
746 * to add/edit.
747 *
748 * NOTE: This does NOT create the primary key or index, it is expected to be handled externally.
749 *
750 * \param[in,out] table Initialized table to be populated with column data
751 * \param[in] fields Field list to generate columns from
752 * \param[in] num_fields Number of fields in the field list
753 *
754 * \return M_TRUE on success, M_FALSE on error
755 */
756M_API M_bool M_sql_tabledata_to_table(M_sql_table_t *table, const M_sql_tabledata_t *fields, size_t num_fields);
757
758/*! @} */
759
760
761__END_DECLS
762
763#endif /* __M_SQL_TABLE_H__ */
struct M_list_str M_list_str_t
Definition: m_list_str.h:80
struct M_sql_connpool M_sql_connpool_t
Definition: m_sql.h:335
M_sql_error_t
Definition: m_sql.h:190
M_sql_data_type_t
Definition: m_sql.h:256
M_bool M_sql_table_exists(M_sql_connpool_t *pool, const char *name)
struct M_sql_table M_sql_table_t
Definition: m_sql_table.h:49
M_sql_error_t M_sql_table_execute(M_sql_connpool_t *pool, M_sql_table_t *table, char *error, size_t error_size)
void M_sql_table_destroy(M_sql_table_t *table)
M_sql_table_index_flags_t
Definition: m_sql_table.h:66
M_bool M_sql_index_add_col(M_sql_index_t *idx, const char *col_name)
M_sql_table_t * M_sql_table_create(const char *name)
M_sql_index_t * M_sql_table_add_index(M_sql_table_t *table, M_uint32 flags, const char *idx_name)
struct M_sql_index M_sql_index_t
Definition: m_sql_table.h:55
M_bool M_sql_table_add_col(M_sql_table_t *table, M_uint32 flags, const char *col_name, M_sql_data_type_t datatype, size_t max_len, const char *default_value)
M_bool M_sql_table_add_pk_col(M_sql_table_t *table, const char *col_name)
M_bool M_sql_table_add_index_str(M_sql_table_t *table, M_uint32 flags, const char *idx_name, const char *idx_cols_csv)
M_sql_table_col_flags_t
Definition: m_sql_table.h:59
@ M_SQL_INDEX_FLAG_UNIQUE
Definition: m_sql_table.h:68
@ M_SQL_INDEX_FLAG_NONE
Definition: m_sql_table.h:67
@ M_SQL_TABLE_COL_FLAG_NONE
Definition: m_sql_table.h:60
@ M_SQL_TABLE_COL_FLAG_NOTNULL
Definition: m_sql_table.h:61
const char * table_column
Definition: m_sql_table.h:305
const char * field_name
Definition: m_sql_table.h:306
size_t max_column_len
Definition: m_sql_table.h:307
M_sql_tabledata_validate_cb validate_cb
Definition: m_sql_table.h:311
M_sql_tabledata_filtertransform_cb filter_cb
Definition: m_sql_table.h:310
M_sql_data_type_t type
Definition: m_sql_table.h:308
M_sql_tabledata_flags_t flags
Definition: m_sql_table.h:309
void M_sql_tabledata_field_set_binary_dup(M_sql_tabledata_field_t *field, const unsigned char *val, size_t len)
M_bool M_sql_tabledata_field_get_text(M_sql_tabledata_field_t *field, const char **val)
M_bool M_sql_tabledata_filter_int2dec_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
M_sql_error_t(* M_sql_tabledata_validate_cb)(M_sql_trans_t *sqltrans, M_sql_tabledata_txn_t *txn, const char *field_name, char *error, size_t error_len)
Definition: m_sql_table.h:300
void M_sql_tabledata_field_set_text_const(M_sql_tabledata_field_t *field, const char *val)
M_sql_error_t M_sql_tabledata_trans_add(M_sql_trans_t *sqltrans, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, M_int64 *generated_id, char *error, size_t error_len)
M_bool M_sql_tabledata_field_get_int32(M_sql_tabledata_field_t *field, M_int32 *val)
void M_sql_tabledata_field_set_null(M_sql_tabledata_field_t *field)
void M_sql_tabledata_field_set_binary_const(M_sql_tabledata_field_t *field, const unsigned char *val, size_t len)
void * M_sql_tabledata_txn_get_thunk(M_sql_tabledata_txn_t *txn)
M_int64 M_sql_tabledata_txn_get_generated_id(M_sql_tabledata_txn_t *txn)
M_bool M_sql_tabledata_field_get_int16(M_sql_tabledata_field_t *field, M_int16 *val)
M_bool M_sql_tabledata_txn_is_add(M_sql_tabledata_txn_t *txn)
M_sql_error_t M_sql_tabledata_trans_edit(M_sql_trans_t *sqltrans, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len)
M_sql_tabledata_txn_field_select_t
Definition: m_sql_table.h:531
M_sql_tabledata_field_t * M_sql_tabledata_txn_field_get(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_txn_field_select_t fselect)
void M_sql_tabledata_field_set_int32(M_sql_tabledata_field_t *field, M_int32 val)
M_bool M_sql_tabledata_field_is_null(const M_sql_tabledata_field_t *field)
const M_sql_tabledata_t * M_sql_tabledata_txn_fetch_fielddef(M_sql_tabledata_txn_t *txn, const char *field_name)
M_bool M_sql_tabledata_field_get_binary(M_sql_tabledata_field_t *field, const unsigned char **val, size_t *len)
void M_sql_tabledata_field_set_text_own(M_sql_tabledata_field_t *field, char *val)
M_sql_error_t M_sql_tabledata_upsert(M_sql_connpool_t *pool, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len)
M_bool M_sql_tabledata_filter_alnum_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
struct M_sql_tabledata_txn M_sql_tabledata_txn_t
Definition: m_sql_table.h:227
M_sql_error_t M_sql_tabledata_trans_upsert(M_sql_trans_t *sqltrans, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len)
M_sql_error_t M_sql_tabledata_edit(M_sql_connpool_t *pool, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, char *error, size_t error_len)
M_bool(* M_sql_tabledata_filtertransform_cb)(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
Definition: m_sql_table.h:261
void M_sql_tabledata_field_set_int64(M_sql_tabledata_field_t *field, M_int64 val)
M_bool M_sql_tabledata_field_get_bool(M_sql_tabledata_field_t *field, M_bool *val)
M_sql_error_t(* M_sql_tabledata_notify_cb)(M_sql_trans_t *sqltrans, M_sql_tabledata_txn_t *txn, char *error, size_t error_len)
Definition: m_sql_table.h:600
void M_sql_tabledata_field_set_bool(M_sql_tabledata_field_t *field, M_bool val)
struct M_sql_tabledata_field M_sql_tabledata_field_t
Definition: m_sql_table.h:221
void M_sql_tabledata_field_set_binary_own(M_sql_tabledata_field_t *field, unsigned char *val, size_t len)
M_bool M_sql_tabledata_txn_field_changed(M_sql_tabledata_txn_t *txn, const char *field_name)
M_bool M_sql_tabledata_filter_int5dec_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
M_sql_tabledata_field_t * M_sql_tabledata_field_create_ext(void)
void M_sql_tabledata_field_set_int16(M_sql_tabledata_field_t *field, M_int16 val)
void M_sql_tabledata_field_destroy_ext(M_sql_tabledata_field_t *field)
M_bool M_sql_tabledata_filter_alnumsp_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
const char * M_sql_tabledata_txn_get_tablename(M_sql_tabledata_txn_t *txn)
M_sql_data_type_t M_sql_tabledata_field_type(const M_sql_tabledata_field_t *field)
M_bool M_sql_tabledata_field_get_int64(M_sql_tabledata_field_t *field, M_int64 *val)
M_sql_error_t M_sql_tabledata_add(M_sql_connpool_t *pool, const char *table_name, const M_sql_tabledata_t *fields, size_t num_fields, M_sql_tabledata_fetch_cb fetch_cb, M_sql_tabledata_notify_cb notify_cb, void *thunk, M_int64 *generated_id, char *error, size_t error_len)
void M_sql_tabledata_field_set_text_dup(M_sql_tabledata_field_t *field, const char *val)
M_bool M_sql_tabledata_field_is_alloc(const M_sql_tabledata_field_t *field)
M_bool M_sql_tabledata_to_table(M_sql_table_t *table, const M_sql_tabledata_t *fields, size_t num_fields)
M_bool M_sql_tabledata_filter_alpha_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
M_bool M_sql_tabledata_filter_graph_cb(M_sql_tabledata_txn_t *txn, const char *field_name, M_sql_tabledata_field_t *field, char *error, size_t error_len)
M_bool(* M_sql_tabledata_fetch_cb)(M_sql_tabledata_field_t *out, const char *field_name, M_bool is_add, void *thunk)
Definition: m_sql_table.h:586
M_bool M_sql_tabledata_txn_field_changed_ci(M_sql_tabledata_txn_t *txn, const char *field_name)
M_sql_tabledata_flags_t
Definition: m_sql_table.h:230
M_sql_tabledata_t * M_sql_tabledata_append_virtual_list(const M_sql_tabledata_t *fields, size_t *num_fields, const char *table_column, const M_list_str_t *field_names, size_t max_len, M_sql_tabledata_flags_t flags)
@ M_SQL_TABLEDATA_TXN_FIELD_PRIOR
Definition: m_sql_table.h:534
@ M_SQL_TABLEDATA_TXN_FIELD_MERGED
Definition: m_sql_table.h:532
@ M_SQL_TABLEDATA_TXN_FIELD_MERGED_NODUPLICATE
Definition: m_sql_table.h:533
@ M_SQL_TABLEDATA_TXN_FIELD_CURRENT_READONLY
Definition: m_sql_table.h:535
@ M_SQL_TABLEDATA_TXN_FIELD_CURRENT
Definition: m_sql_table.h:536
@ M_SQL_TABLEDATA_FLAG_EDITABLE
Definition: m_sql_table.h:233
@ M_SQL_TABLEDATA_FLAG_NONE
Definition: m_sql_table.h:231
@ M_SQL_TABLEDATA_FLAG_ID
Definition: m_sql_table.h:235
@ M_SQL_TABLEDATA_FLAG_ID_GENERATE
Definition: m_sql_table.h:237
@ M_SQL_TABLEDATA_FLAG_NOTNULL
Definition: m_sql_table.h:234
@ M_SQL_TABLEDATA_FLAG_ID_REQUIRED
Definition: m_sql_table.h:238
@ M_SQL_TABLEDATA_FLAG_TIMESTAMP
Definition: m_sql_table.h:240
@ M_SQL_TABLEDATA_FLAG_VIRTUAL
Definition: m_sql_table.h:232
@ M_SQL_TABLEDATA_FLAG_ALLOW_NONPRINT_SEP
Definition: m_sql_table.h:241
Definition: m_sql_table.h:304
struct M_sql_trans M_sql_trans_t
Definition: m_sql_trans.h:50