FreeSWITCH API Documentation  1.7.0
switch_core_db.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
4  *
5  * Version: MPL 1.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
18  *
19  * The Initial Developer of the Original Code is
20  * Anthony Minessale II <anthm@freeswitch.org>
21  * Portions created by the Initial Developer are Copyright (C)
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  * Anthony Minessale II <anthm@freeswitch.org>
27  * Michael Jerris <mike@jerris.com>
28  *
29  * switch_core_db.h -- Sqlite wrapper and extensions Header
30  *
31  */
32 /*! \file switch_core_db.h
33  \brief Core DB Header
34 */
35 #ifndef SWITCH_CORE_DB_H
36 #define SWITCH_CORE_DB_H
37 
39 /**
40  * @defgroup switch_sqlite_top Brought To You By SQLite
41  * @ingroup FREESWITCH
42  * @{
43  */
44 /**
45  * @defgroup switch_core_db Database Routines
46  * @ingroup switch_sqlite_top
47  * @{
48  */
49 /**
50  * Each open database is represented by an instance of the
51  * following opaque structure.
52 */
53  typedef struct sqlite3 switch_core_db_t;
54 typedef struct sqlite3_stmt switch_core_db_stmt_t;
55 
56 typedef int (*switch_core_db_callback_func_t) (void *pArg, int argc, char **argv, char **columnNames);
57 typedef int (*switch_core_db_err_callback_func_t) (void *pArg, const char *errmsg);
58 
59 /*
60 ** These are special value for the destructor that is passed in as the
61 ** final argument to routines like switch_core_db_result_blob(). If the destructor
62 ** argument is SWITCH_CORE_DB_STATIC, it means that the content pointer is constant
63 ** and will never change. It does not need to be destroyed. The
64 ** SWITCH_CORE_DB_TRANSIENT value means that the content will likely change in
65 ** the near future and that the db should make its own private copy of
66 ** the content before returning.
67 **
68 ** The typedef is necessary to work around problems in certain
69 ** C++ compilers.
70 */
71 typedef void (*switch_core_db_destructor_type_t) (void *);
72 #define SWITCH_CORE_DB_STATIC ((switch_core_db_destructor_type_t)0)
73 #define SWITCH_CORE_DB_TRANSIENT ((switch_core_db_destructor_type_t)-1)
74 
75 /**
76  * A function to close the database.
77  *
78  * Call this function with a pointer to a structure that was previously
79  * returned from switch_core_db_open() and the corresponding database will by closed.
80  *
81  * All SQL statements prepared using switch_core_db_prepare()
82  * must be deallocated using switch_core_db_finalize() before
83  * this routine is called. Otherwise, SWITCH_CORE_DB_BUSY is returned and the
84  * database connection remains open.
85  */
87 
88 /**
89  * Open the database file "filename". The "filename" is UTF-8
90  * encoded. A switch_core_db_t* handle is returned in *Db, even
91  * if an error occurs. If the database is opened (or created) successfully,
92  * then SWITCH_CORE_DB_OK is returned. Otherwise an error code is returned. The
93  * switch_core_db_errmsg() routine can be used to obtain
94  * an English language description of the error.
95  *
96  * If the database file does not exist, then a new database is created.
97  * The encoding for the database is UTF-8.
98  *
99  * Whether or not an error occurs when it is opened, resources associated
100  * with the switch_core_db_t* handle should be released by passing it to
101  * switch_core_db_close() when it is no longer required.
102  */
104 
105 /**
106  * The next group of routines returns information about the information
107  * in a single column of the current result row of a query. In every
108  * case the first parameter is a pointer to the SQL statement that is being
109  * executed (the switch_core_db_stmt_t* that was returned from switch_core_db_prepare()) and
110  * the second argument is the index of the column for which information
111  * should be returned. iCol is zero-indexed. The left-most column as an
112  * index of 0.
113  *
114  * If the SQL statement is not currently point to a valid row, or if the
115  * the colulmn index is out of range, the result is undefined.
116  *
117  * These routines attempt to convert the value where appropriate. For
118  * example, if the internal representation is FLOAT and a text result
119  * is requested, sprintf() is used internally to do the conversion
120  * automatically. The following table details the conversions that
121  * are applied:
122  *
123  * Internal Type Requested Type Conversion
124  * ------------- -------------- --------------------------
125  * NULL INTEGER Result is 0
126  * NULL FLOAT Result is 0.0
127  * NULL TEXT Result is an empty string
128  * NULL BLOB Result is a zero-length BLOB
129  * INTEGER FLOAT Convert from integer to float
130  * INTEGER TEXT ASCII rendering of the integer
131  * INTEGER BLOB Same as for INTEGER->TEXT
132  * FLOAT INTEGER Convert from float to integer
133  * FLOAT TEXT ASCII rendering of the float
134  * FLOAT BLOB Same as FLOAT->TEXT
135  * TEXT INTEGER Use atoi()
136  * TEXT FLOAT Use atof()
137  * TEXT BLOB No change
138  * BLOB INTEGER Convert to TEXT then use atoi()
139  * BLOB FLOAT Convert to TEXT then use atof()
140  * BLOB TEXT Add a "\000" terminator if needed
141  *
142  * Return the value as UTF-8 text.
143  */
144 SWITCH_DECLARE(const unsigned char *) switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol);
145 
146 /**
147  * The first parameter is a compiled SQL statement. This function returns
148  * the column heading for the Nth column of that statement, where N is the
149  * second function parameter. The string returned is UTF-8.
150  */
152 
153 /**
154  * Return the number of columns in the result set returned by the compiled
155  * SQL statement. This routine returns 0 if pStmt is an SQL statement
156  * that does not return data (for example an UPDATE).
157  */
159 
160 /**
161  * Return a pointer to a UTF-8 encoded string describing in english the
162  * error condition for the most recent switch_core_db_* API call. The returned
163  * string is always terminated by an 0x00 byte.
164  *
165  * The string "not an error" is returned when the most recent API call was
166  * successful.
167  */
169 
170 /**
171  * A function to executes one or more statements of SQL.
172  *
173  * If one or more of the SQL statements are queries, then
174  * the callback function specified by the 3rd parameter is
175  * invoked once for each row of the query result. This callback
176  * should normally return 0. If the callback returns a non-zero
177  * value then the query is aborted, all subsequent SQL statements
178  * are skipped and the switch_core_db_exec() function returns the SWITCH_CORE_DB_ABORT.
179  *
180  * The 4th parameter is an arbitrary pointer that is passed
181  * to the callback function as its first parameter.
182  *
183  * The 2nd parameter to the callback function is the number of
184  * columns in the query result. The 3rd parameter to the callback
185  * is an array of strings holding the values for each column.
186  * The 4th parameter to the callback is an array of strings holding
187  * the names of each column.
188  *
189  * The callback function may be NULL, even for queries. A NULL
190  * callback is not an error. It just means that no callback
191  * will be invoked.
192  *
193  * If an error occurs while parsing or evaluating the SQL (but
194  * not while executing the callback) then an appropriate error
195  * message is written into memory obtained from malloc() and
196  * *errmsg is made to point to that message. The calling function
197  * is responsible for freeing the memory that holds the error
198  * message. Use switch_core_db_free() for this. If errmsg==NULL,
199  * then no error message is ever written.
200  *
201  * The return value is is SWITCH_CORE_DB_OK if there are no errors and
202  * some other return code if there is an error. The particular
203  * return value depends on the type of error.
204  *
205  * If the query could not be executed because a database file is
206  * locked or busy, then this function returns SWITCH_CORE_DB_BUSY. (This
207  * behavior can be modified somewhat using the sswitch_core_db_busy_handler()
208  * and switch_core_db_busy_timeout() functions below.)
209  */
210 SWITCH_DECLARE(int) switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg);
211 
212 /**
213  * This function is called to delete a compiled
214  * SQL statement obtained by a previous call to switch_core_db_prepare().
215  * If the statement was executed successfully, or
216  * not executed at all, then SWITCH_CORE_DB_OK is returned. If execution of the
217  * statement failed then an error code is returned.
218  *
219  * This routine can be called at any point during the execution of the
220  * virtual machine. If the virtual machine has not completed execution
221  * when this routine is called, that is like encountering an error or
222  * an interrupt. (See switch_core_db_interrupt().) Incomplete updates may be
223  * rolled back and transactions cancelled, depending on the circumstances,
224  * and the result code returned will be SWITCH_CORE_DB_ABORT.
225  */
227 
228 /**
229  * To execute an SQL query, it must first be compiled into a byte-code
230  * program using the following routine.
231  *
232  * The first parameter "db" is an SQLite database handle. The second
233  * parameter "zSql" is the statement to be compiled, encoded as
234  * UTF-8. If the next parameter, "nBytes", is less
235  * than zero, then zSql is read up to the first nul terminator. If
236  * "nBytes" is not less than zero, then it is the length of the string zSql
237  * in bytes (not characters).
238  *
239  * *pzTail is made to point to the first byte past the end of the first
240  * SQL statement in zSql. This routine only compiles the first statement
241  * in zSql, so *pzTail is left pointing to what remains uncompiled.
242  *
243  * *ppStmt is left pointing to a compiled SQL statement that can be
244  * executed using switch_core_db_step(). Or if there is an error, *ppStmt may be
245  * set to NULL. If the input text contained no SQL (if the input is and
246  * empty string or a comment) then *ppStmt is set to NULL.
247  *
248  * On success, SWITCH_CORE_DB_OK is returned. Otherwise an error code is returned.
249  */
250 SWITCH_DECLARE(int) switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail);
251 
252 /**
253  * After an SQL query has been compiled with a call to either
254  * switch_core_db_prepare(), then this function must be
255  * called one or more times to execute the statement.
256  *
257  * The return value will be either SWITCH_CORE_DB_BUSY, SWITCH_CORE_DB_DONE,
258  * SWITCH_CORE_DB_ROW, SWITCH_CORE_DB_ERROR, or SWITCH_CORE_DB_MISUSE.
259  *
260  * SWITCH_CORE_DB_BUSY means that the database engine attempted to open
261  * a locked database and there is no busy callback registered.
262  * Call switch_core_db_step() again to retry the open.
263  *
264  * SWITCH_CORE_DB_DONE means that the statement has finished executing
265  * successfully. switch_core_db_step() should not be called again on this virtual
266  * machine.
267  *
268  * If the SQL statement being executed returns any data, then
269  * SWITCH_CORE_DB_ROW is returned each time a new row of data is ready
270  * for processing by the caller. The values may be accessed using
271  * the switch_core_db_column_*() functions described below. switch_core_db_step()
272  * is called again to retrieve the next row of data.
273  *
274  * SWITCH_CORE_DB_ERROR means that a run-time error (such as a constraint
275  * violation) has occurred. switch_core_db_step() should not be called again on
276  * the VM. More information may be found by calling switch_core_db_errmsg().
277  *
278  * SWITCH_CORE_DB_MISUSE means that the this routine was called inappropriately.
279  * Perhaps it was called on a virtual machine that had already been
280  * finalized or on one that had previously returned SWITCH_CORE_DB_ERROR or
281  * SWITCH_CORE_DB_DONE. Or it could be the case the the same database connection
282  * is being used simulataneously by two or more threads.
283  */
285 
286 /**
287  * The switch_core_db_reset() function is called to reset a compiled SQL
288  * statement obtained by a previous call to switch_core_db_prepare()
289  * back to it's initial state, ready to be re-executed.
290  * Any SQL statement variables that had values bound to them using
291  * the switch_core_db_bind_*() API retain their values.
292  */
294 
295 /**
296  * In the SQL strings input to switch_core_db_prepare(),
297  * one or more literals can be replace by parameters "?" or ":AAA" or
298  * "$VVV" where AAA is an identifer and VVV is a variable name according
299  * to the syntax rules of the TCL programming language.
300  * The value of these parameters (also called "host parameter names") can
301  * be set using the routines listed below.
302  *
303  * In every case, the first parameter is a pointer to the sqlite3_stmt
304  * structure returned from switch_core_db_prepare(). The second parameter is the
305  * index of the parameter. The first parameter as an index of 1. For
306  * named parameters (":AAA" or "$VVV") you can use
307  * switch_core_db_bind_parameter_index() to get the correct index value given
308  * the parameters name. If the same named parameter occurs more than
309  * once, it is assigned the same index each time.
310  *
311  * The switch_core_db_bind_* routine must be called before switch_core_db_step() after
312  * an switch_core_db_prepare() or sqlite3_reset(). Unbound parameterss are
313  * interpreted as NULL.
314  */
315 SWITCH_DECLARE(int) switch_core_db_bind_int(switch_core_db_stmt_t *pStmt, int i, int iValue);
316 
317 /**
318  * In the SQL strings input to switch_core_db_prepare(),
319  * one or more literals can be replace by parameters "?" or ":AAA" or
320  * "$VVV" where AAA is an identifer and VVV is a variable name according
321  * to the syntax rules of the TCL programming language.
322  * The value of these parameters (also called "host parameter names") can
323  * be set using the routines listed below.
324  *
325  * In every case, the first parameter is a pointer to the sqlite3_stmt
326  * structure returned from switch_core_db_prepare(). The second parameter is the
327  * index of the parameter. The first parameter as an index of 1. For
328  * named parameters (":AAA" or "$VVV") you can use
329  * switch_core_db_bind_parameter_index() to get the correct index value given
330  * the parameters name. If the same named parameter occurs more than
331  * once, it is assigned the same index each time.
332  *
333  * The switch_core_db_bind_* routine must be called before switch_core_db_step() after
334  * an switch_core_db_prepare() or sqlite3_reset(). Unbound parameterss are
335  * interpreted as NULL.
336  */
337 SWITCH_DECLARE(int) switch_core_db_bind_int64(switch_core_db_stmt_t *pStmt, int i, int64_t iValue);
338 
339 /**
340  * In the SQL strings input to switch_core_db_prepare(),
341  * one or more literals can be replace by parameters "?" or ":AAA" or
342  * "$VVV" where AAA is an identifer and VVV is a variable name according
343  * to the syntax rules of the TCL programming language.
344  * The value of these parameters (also called "host parameter names") can
345  * be set using the routines listed below.
346  *
347  * In every case, the first parameter is a pointer to the sqlite3_stmt
348  * structure returned from switch_core_db_prepare(). The second parameter is the
349  * index of the parameter. The first parameter as an index of 1. For
350  * named parameters (":AAA" or "$VVV") you can use
351  * switch_core_db_bind_parameter_index() to get the correct index value given
352  * the parameters name. If the same named parameter occurs more than
353  * once, it is assigned the same index each time.
354  *
355  * The fifth parameter to switch_core_db_bind_blob(), switch_core_db_bind_text(), and
356  * switch_core_db_bind_text16() is a destructor used to dispose of the BLOB or
357  * text after SQLite has finished with it. If the fifth argument is the
358  * special value SQLITE_STATIC, then the library assumes that the information
359  * is in static, unmanaged space and does not need to be freed. If the
360  * fifth argument has the value SQLITE_TRANSIENT, then SQLite makes its
361  * own private copy of the data.
362  *
363  * The switch_core_db_bind_* routine must be called before switch_core_db_step() after
364  * an switch_core_db_prepare() or sqlite3_reset(). Unbound parameterss are
365  * interpreted as NULL.
366  */
367 SWITCH_DECLARE(int) switch_core_db_bind_text(switch_core_db_stmt_t *pStmt, int i, const char *zData, int nData, switch_core_db_destructor_type_t xDel);
368 
369 /**
370  * In the SQL strings input to switch_core_db_prepare(),
371  * one or more literals can be replace by parameters "?" or ":AAA" or
372  * "$VVV" where AAA is an identifer and VVV is a variable name according
373  * to the syntax rules of the TCL programming language.
374  * The value of these parameters (also called "host parameter names") can
375  * be set using the routines listed below.
376  *
377  * In every case, the first parameter is a pointer to the sqlite3_stmt
378  * structure returned from switch_core_db_prepare(). The second parameter is the
379  * index of the parameter. The first parameter as an index of 1. For
380  * named parameters (":AAA" or "$VVV") you can use
381  * sqlite3_bind_parameter_index() to get the correct index value given
382  * the parameters name. If the same named parameter occurs more than
383  * once, it is assigned the same index each time.
384  *
385  * The sqlite3_bind_* routine must be called before switch_core_db_step() after
386  * an switch_core_db_prepare() or switch_core_db_reset(). Unbound parameterss are
387  * interpreted as NULL.
388  */
389 SWITCH_DECLARE(int) switch_core_db_bind_double(switch_core_db_stmt_t *pStmt, int i, double dValue);
390 
391 /**
392  * Each entry in a table has a unique integer key. (The key is
393  * the value of the INTEGER PRIMARY KEY column if there is such a column,
394  * otherwise the key is generated at random. The unique key is always
395  * available as the ROWID, OID, or _ROWID_ column.) The following routine
396  * returns the integer key of the most recent insert in the database.
397  *
398  * This function is similar to the mysql_insert_id() function from MySQL.
399  */
401 
402 /**
403  * This next routine is really just a wrapper around switch_core_db_exec().
404  * Instead of invoking a user-supplied callback for each row of the
405  * result, this routine remembers each row of the result in memory
406  * obtained from malloc(), then returns all of the result after the
407  * query has finished.
408  *
409  * As an example, suppose the query result where this table:
410  *
411  * Name | Age
412  * -----------------------
413  * Alice | 43
414  * Bob | 28
415  * Cindy | 21
416  *
417  * If the 3rd argument were &azResult then after the function returns
418  * azResult will contain the following data:
419  *
420  * azResult[0] = "Name";
421  * azResult[1] = "Age";
422  * azResult[2] = "Alice";
423  * azResult[3] = "43";
424  * azResult[4] = "Bob";
425  * azResult[5] = "28";
426  * azResult[6] = "Cindy";
427  * azResult[7] = "21";
428  *
429  * Notice that there is an extra row of data containing the column
430  * headers. But the *nrow return value is still 3. *ncolumn is
431  * set to 2. In general, the number of values inserted into azResult
432  * will be ((*nrow) + 1)*(*ncolumn).
433  *
434  * After the calling function has finished using the result, it should
435  * pass the result data pointer to switch_core_db_free_table() in order to
436  * release the memory that was malloc-ed. Because of the way the
437  * malloc() happens, the calling function must not try to call
438  * free() directly. Only switch_core_db_free_table() is able to release
439  * the memory properly and safely.
440  *
441  * The return value of this routine is the same as from switch_core_db_exec().
442  */
443 SWITCH_DECLARE(int) switch_core_db_get_table(switch_core_db_t *db, /* An open database */
444  const char *sql, /* SQL to be executed */
445  char ***resultp, /* Result written to a char *[] that this points to */
446  int *nrow, /* Number of result rows written here */
447  int *ncolumn, /* Number of result columns written here */
448  char **errmsg /* Error msg written here */
449  );
450 
451 /**
452  * Call this routine to free the memory that sqlite3_get_table() allocated.
453  */
454 SWITCH_DECLARE(void) switch_core_db_free_table(char **result);
455 
456 /**
457  * Call this routine to free the memory that switch_core_db_get_table() allocated.
458  */
459 SWITCH_DECLARE(void) switch_core_db_free(char *z);
460 
461 /**
462  * Call this routine to find the number of rows changed by the last statement.
463  */
465 
466 /**
467  * Call this routine to load an external extension
468  */
469 SWITCH_DECLARE(int) switch_core_db_load_extension(switch_core_db_t *db, const char *extension);
470 
471 /** Return values for switch_core_db_exec() and switch_core_db_step()*/
472 #define SWITCH_CORE_DB_OK 0 /* Successful result */
473 /* beginning-of-error-codes */
474 #define SWITCH_CORE_DB_ERROR 1 /* SQL error or missing database */
475 #define SWITCH_CORE_DB_INTERNAL 2 /* NOT USED. Internal logic error in SQLite */
476 #define SWITCH_CORE_DB_PERM 3 /* Access permission denied */
477 #define SWITCH_CORE_DB_ABORT 4 /* Callback routine requested an abort */
478 #define SWITCH_CORE_DB_BUSY 5 /* The database file is locked */
479 #define SWITCH_CORE_DB_LOCKED 6 /* A table in the database is locked */
480 #define SWITCH_CORE_DB_NOMEM 7 /* A malloc() failed */
481 #define SWITCH_CORE_DB_READONLY 8 /* Attempt to write a readonly database */
482 #define SWITCH_CORE_DB_INTERRUPT 9 /* Operation terminated by switch_core_db_interrupt() */
483 #define SWITCH_CORE_DB_IOERR 10 /* Some kind of disk I/O error occurred */
484 #define SWITCH_CORE_DB_CORRUPT 11 /* The database disk image is malformed */
485 #define SWITCH_CORE_DB_NOTFOUND 12 /* NOT USED. Table or record not found */
486 #define SWITCH_CORE_DB_FULL 13 /* Insertion failed because database is full */
487 #define SWITCH_CORE_DB_CANTOPEN 14 /* Unable to open the database file */
488 #define SWITCH_CORE_DB_PROTOCOL 15 /* Database lock protocol error */
489 #define SWITCH_CORE_DB_EMPTY 16 /* Database is empty */
490 #define SWITCH_CORE_DB_SCHEMA 17 /* The database schema changed */
491 #define SWITCH_CORE_DB_TOOBIG 18 /* NOT USED. Too much data for one row */
492 #define SWITCH_CORE_DB_CONSTRAINT 19 /* Abort due to contraint violation */
493 #define SWITCH_CORE_DB_MISMATCH 20 /* Data type mismatch */
494 #define SWITCH_CORE_DB_MISUSE 21 /* Library used incorrectly */
495 #define SWITCH_CORE_DB_NOLFS 22 /* Uses OS features not supported on host */
496 #define SWITCH_CORE_DB_AUTH 23 /* Authorization denied */
497 #define SWITCH_CORE_DB_FORMAT 24 /* Auxiliary database format error */
498 #define SWITCH_CORE_DB_RANGE 25 /* 2nd parameter to switch_core_db_bind out of range */
499 #define SWITCH_CORE_DB_NOTADB 26 /* File opened that is not a database file */
500 #define SWITCH_CORE_DB_ROW 100 /* switch_core_db_step() has another row ready */
501 #define SWITCH_CORE_DB_DONE 101 /* switch_core_db_step() has finished executing */
502 /* end-of-error-codes */
503 
504 
505 /** @} */
506 /** @} */
507 /**
508  * This routine is a variant of the "sprintf()" from the
509  * standard C library. The resulting string is written into memory
510  * obtained from malloc() so that there is never a possiblity of buffer
511  * overflow. This routine also implement some additional formatting
512  * options that are useful for constructing SQL statements.
513  *
514  * The strings returned by this routine should be freed by calling
515  * switch_core_db_free().
516  *
517  * All of the usual printf formatting options apply. In addition, there
518  * is a "%q" option. %q works like %s in that it substitutes a null-terminated
519  * string from the argument list. But %q also doubles every '\'' character.
520  * %q is designed for use inside a string literal. By doubling each '\''
521  * character it escapes that character and allows it to be inserted into
522  * the string.
523  *
524  * For example, so some string variable contains text as follows:
525  *
526  * char *zText = "It's a happy day!";
527  *
528  * We can use this text in an SQL statement as follows:
529  *
530  * char *z = switch_core_db_mprintf("INSERT INTO TABLES('%q')", zText);
531  * switch_core_db_exec(db, z, callback1, 0, 0);
532  * switch_core_db_free(z);
533  *
534  * Because the %q format string is used, the '\'' character in zText
535  * is escaped and the SQL generated is as follows:
536  *
537  * INSERT INTO table1 VALUES('It''s a happy day!')
538  *
539  * This is correct. Had we used %s instead of %q, the generated SQL
540  * would have looked like this:
541  *
542  * INSERT INTO table1 VALUES('It's a happy day!');
543  *
544  * This second example is an SQL syntax error. As a general rule you
545  * should always use %q instead of %s when inserting text into a string
546  * literal.
547  */
548 
550 
552 #endif
553 /* For Emacs:
554  * Local Variables:
555  * mode:c
556  * indent-tabs-mode:t
557  * tab-width:4
558  * c-basic-offset:4
559  * End:
560  * For VIM:
561  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
562  */
void switch_core_db_free_table(char **result)
const char * switch_core_db_errmsg(switch_core_db_t *db)
char * switch_sql_concat(void)
int switch_core_db_get_table(switch_core_db_t *db, const char *sql, char ***resultp, int *nrow, int *ncolumn, char **errmsg)
#define SWITCH_END_EXTERN_C
Definition: switch.h:43
const char * switch_core_db_column_name(switch_core_db_stmt_t *stmt, int N)
int switch_core_db_close(switch_core_db_t *db)
int(* switch_core_db_callback_func_t)(void *pArg, int argc, char **argv, char **columnNames)
int switch_core_db_finalize(switch_core_db_stmt_t *pStmt)
int switch_core_db_step(switch_core_db_stmt_t *stmt)
int switch_core_db_exec(switch_core_db_t *db, const char *sql, switch_core_db_callback_func_t callback, void *data, char **errmsg)
int(* switch_core_db_err_callback_func_t)(void *pArg, const char *errmsg)
int switch_core_db_bind_text(switch_core_db_stmt_t *pStmt, int i, const char *zData, int nData, switch_core_db_destructor_type_t xDel)
int switch_core_db_load_extension(switch_core_db_t *db, const char *extension)
int switch_core_db_reset(switch_core_db_stmt_t *pStmt)
int switch_core_db_bind_double(switch_core_db_stmt_t *pStmt, int i, double dValue)
int64_t switch_core_db_last_insert_rowid(switch_core_db_t *db)
struct sqlite3 switch_core_db_t
int switch_core_db_open(const char *filename, switch_core_db_t **ppDb)
#define SWITCH_DECLARE(type)
void switch_core_db_free(char *z)
struct sqlite3_stmt switch_core_db_stmt_t
int switch_core_db_changes(switch_core_db_t *db)
int switch_core_db_column_count(switch_core_db_stmt_t *pStmt)
const unsigned char * switch_core_db_column_text(switch_core_db_stmt_t *stmt, int iCol)
int switch_core_db_bind_int64(switch_core_db_stmt_t *pStmt, int i, int64_t iValue)
char * filename
int switch_core_db_prepare(switch_core_db_t *db, const char *zSql, int nBytes, switch_core_db_stmt_t **ppStmt, const char **pzTail)
int switch_core_db_bind_int(switch_core_db_stmt_t *pStmt, int i, int iValue)
void(* switch_core_db_destructor_type_t)(void *)
#define SWITCH_BEGIN_EXTERN_C
Definition: switch.h:42