FreeSWITCH API Documentation
1.7.0
|
Core DB Header. More...
Go to the source code of this file.
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 *) |
Core DB Header.
Definition in file switch_core_db.h.
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 3790 of file switch_core_sqldb.c.
References DBTYPE_MSSQL, switch_runtime::odbc_dbtype, and runtime.