RTS API Documentation  1.10.11
Data Structures | Macros | Typedefs | Functions
switch_core_db.h File Reference

Core DB Header. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  switch_coredb_handle
 

Macros

#define SWITCH_CORE_DB_STATIC   ((switch_core_db_destructor_type_t)0)
 
#define SWITCH_CORE_DB_TRANSIENT   ((switch_core_db_destructor_type_t)-1)
 
#define SWITCH_CORE_DB_OK   0 /* Successful result */
 
#define SWITCH_CORE_DB_ERROR   1 /* SQL error or missing database */
 
#define SWITCH_CORE_DB_INTERNAL   2 /* NOT USED. Internal logic error in SQLite */
 
#define SWITCH_CORE_DB_PERM   3 /* Access permission denied */
 
#define SWITCH_CORE_DB_ABORT   4 /* Callback routine requested an abort */
 
#define SWITCH_CORE_DB_BUSY   5 /* The database file is locked */
 
#define SWITCH_CORE_DB_LOCKED   6 /* A table in the database is locked */
 
#define SWITCH_CORE_DB_NOMEM   7 /* A malloc() failed */
 
#define SWITCH_CORE_DB_READONLY   8 /* Attempt to write a readonly database */
 
#define SWITCH_CORE_DB_INTERRUPT   9 /* Operation terminated by switch_core_db_interrupt() */
 
#define SWITCH_CORE_DB_IOERR   10 /* Some kind of disk I/O error occurred */
 
#define SWITCH_CORE_DB_CORRUPT   11 /* The database disk image is malformed */
 
#define SWITCH_CORE_DB_NOTFOUND   12 /* NOT USED. Table or record not found */
 
#define SWITCH_CORE_DB_FULL   13 /* Insertion failed because database is full */
 
#define SWITCH_CORE_DB_CANTOPEN   14 /* Unable to open the database file */
 
#define SWITCH_CORE_DB_PROTOCOL   15 /* Database lock protocol error */
 
#define SWITCH_CORE_DB_EMPTY   16 /* Database is empty */
 
#define SWITCH_CORE_DB_SCHEMA   17 /* The database schema changed */
 
#define SWITCH_CORE_DB_TOOBIG   18 /* NOT USED. Too much data for one row */
 
#define SWITCH_CORE_DB_CONSTRAINT   19 /* Abort due to contraint violation */
 
#define SWITCH_CORE_DB_MISMATCH   20 /* Data type mismatch */
 
#define SWITCH_CORE_DB_MISUSE   21 /* Library used incorrectly */
 
#define SWITCH_CORE_DB_NOLFS   22 /* Uses OS features not supported on host */
 
#define SWITCH_CORE_DB_AUTH   23 /* Authorization denied */
 
#define SWITCH_CORE_DB_FORMAT   24 /* Auxiliary database format error */
 
#define SWITCH_CORE_DB_RANGE   25 /* 2nd parameter to switch_core_db_bind out of range */
 
#define SWITCH_CORE_DB_NOTADB   26 /* File opened that is not a database file */
 
#define SWITCH_CORE_DB_ROW   100 /* switch_core_db_step() has another row ready */
 
#define SWITCH_CORE_DB_DONE   101 /* switch_core_db_step() has finished executing */
 

Typedefs

typedef struct sqlite3 switch_core_db_t
 
typedef struct sqlite3_stmt switch_core_db_stmt_t
 
typedef int(* switch_core_db_callback_func_t) (void *pArg, int argc, char **argv, char **columnNames)
 
typedef int(* switch_core_db_err_callback_func_t) (void *pArg, const char *errmsg)
 
typedef void(* switch_core_db_destructor_type_t) (void *)
 

Functions

int switch_core_db_close (switch_core_db_t *db)
 
int switch_core_db_open (const char *filename, switch_core_db_t **ppDb)
 
int switch_core_db_open_v2 (const char *filename, switch_core_db_t **ppDb)
 
const unsigned char * switch_core_db_column_text (switch_core_db_stmt_t *stmt, int iCol)
 
const char * switch_core_db_column_name (switch_core_db_stmt_t *stmt, int N)
 
int switch_core_db_column_count (switch_core_db_stmt_t *pStmt)
 
const char * switch_core_db_errmsg (switch_core_db_t *db)
 
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_finalize (switch_core_db_stmt_t *pStmt)
 
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_step (switch_core_db_stmt_t *stmt)
 
int switch_core_db_reset (switch_core_db_stmt_t *pStmt)
 
int switch_core_db_bind_int (switch_core_db_stmt_t *pStmt, int i, int iValue)
 
int switch_core_db_bind_int64 (switch_core_db_stmt_t *pStmt, int i, int64_t iValue)
 
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_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)
 
int switch_core_db_get_table (switch_core_db_t *db, const char *sql, char ***resultp, int *nrow, int *ncolumn, char **errmsg)
 
void switch_core_db_free_table (char **result)
 
void switch_core_db_free (char *z)
 
int switch_core_db_changes (switch_core_db_t *db)
 
int switch_core_db_load_extension (switch_core_db_t *db, const char *extension)
 
char * switch_sql_concat (void)
 

Detailed Description

Core DB Header.

Definition in file switch_core_db.h.

Function Documentation

◆ switch_sql_concat()

char* switch_sql_concat ( void  )

This routine is a variant of the "sprintf()" from the standard C library. The resulting string is written into memory obtained from malloc() so that there is never a possiblity of buffer overflow. This routine also implement some additional formatting options that are useful for constructing SQL statements.

The strings returned by this routine should be freed by calling switch_core_db_free().

All of the usual printf formatting options apply. In addition, there is a "%q" option. q works like s in that it substitutes a null-terminated string from the argument list. But q also doubles every '\'' character. q is designed for use inside a string literal. By doubling each '\'' character it escapes that character and allows it to be inserted into the string.

For example, so some string variable contains text as follows:

 char *zText = "It's a happy day!";

We can use this text in an SQL statement as follows:

 char *z = switch_core_db_mprintf("INSERT INTO TABLES('%q')", zText);
 switch_core_db_exec(db, z, callback1, 0, 0);
 switch_core_db_free(z);

Because the q format string is used, the '\'' character in zText is escaped and the SQL generated is as follows:

 INSERT INTO table1 VALUES('It''s a happy day!')

This is correct. Had we used s instead of q, the generated SQL would have looked like this:

 INSERT INTO table1 VALUES('It's a happy day!');

This second example is an SQL syntax error. As a general rule you should always use q instead of s when inserting text into a string literal.

Definition at line 4009 of file switch_core_sqldb.c.

References DBTYPE_MSSQL, switch_runtime::odbc_dbtype, and runtime.

4010 {
4012  return "+";
4013 
4014  return "||";
4015 }
struct switch_runtime runtime
Definition: switch_core.c:86
switch_dbtype_t odbc_dbtype