Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Database Functions
[Core Library]


Defines

#define SWITCH_CORE_DB   "core"
#define switch_core_db_handle()   switch_core_db_open_file(SWITCH_CORE_DB)
 Open the default system database.

Functions

switch_core_db_tswitch_core_db_open_file (char *filename)
 Open a core db (SQLite) file.
switch_status_t switch_core_db_persistant_execute (switch_core_db_t *db, char *sql, uint32_t retries)
 Execute a sql stmt until it is accepted.
void switch_core_db_test_reactive (switch_core_db_t *db, char *test_sql, char *drop_sql, char *reactive_sql)
 perform a test query then perform a reactive query if the first one fails


Define Documentation

#define SWITCH_CORE_DB   "core"
 

 
#define switch_core_db_handle  )     switch_core_db_open_file(SWITCH_CORE_DB)
 

Open the default system database.


Function Documentation

switch_core_db_t* switch_core_db_open_file char *  filename  ) 
 

Open a core db (SQLite) file.

Parameters:
filename the path to the db file to open
Returns:
the db handle
00184 {
00185         switch_core_db_t *db;
00186         char path[1024];
00187 
00188         db_pick_path(filename, path, sizeof(path));
00189         if (switch_core_db_open(path, &db)) {
00190                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
00191                 switch_core_db_close(db);
00192                 db = NULL;
00193         }
00194         return db;
00195 }

Here is the call graph for this function:

switch_status_t switch_core_db_persistant_execute switch_core_db_t db,
char *  sql,
uint32_t  retries
 

Execute a sql stmt until it is accepted.

Parameters:
db the db handle
sql the sql to execute
retries the number of retries to use
Returns:
SWITCH_STATUS_SUCCESS if successful
00118 {
00119         char *errmsg;
00120         switch_status_t status = SWITCH_STATUS_FALSE;
00121         uint8_t forever = 0;
00122 
00123         if (!retries) {
00124                 forever = 1;
00125                 retries = 1000;
00126         }
00127 
00128         while (retries > 0) {
00129                 switch_core_db_exec(db, sql, NULL, NULL, &errmsg);
00130                 if (errmsg) {
00131                         //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
00132                         switch_core_db_free(errmsg);
00133                         switch_yield(100000);
00134                         retries--;
00135                         if (retries == 0 && forever) {
00136                                 retries = 1000;
00137                                 continue;
00138                         }
00139                 } else {
00140                         status = SWITCH_STATUS_SUCCESS;
00141                         break;
00142                 }
00143         }
00144 
00145         return status;
00146 }

Here is the call graph for this function:

void switch_core_db_test_reactive switch_core_db_t db,
char *  test_sql,
char *  drop_sql,
char *  reactive_sql
 

perform a test query then perform a reactive query if the first one fails

Parameters:
db the db handle
test_sql the test sql
drop_sql the drop sql
reactive_sql the reactive sql
00198 {
00199         char *errmsg;
00200 
00201         if (db) {
00202                 if (test_sql) {
00203                         switch_core_db_exec(db, test_sql, NULL, NULL, &errmsg);
00204 
00205                         if (errmsg) {
00206                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
00207                                 switch_core_db_free(errmsg);
00208                                 errmsg = NULL;
00209                                 if (drop_sql) {
00210                                         switch_core_db_exec(db, drop_sql, NULL, NULL, &errmsg);
00211                                 }
00212                                 if (errmsg) {
00213                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
00214                                         switch_core_db_free(errmsg);
00215                                         errmsg = NULL;
00216                                 }
00217                                 switch_core_db_exec(db, reactive_sql, NULL, NULL, &errmsg);
00218                                 if (errmsg) {
00219                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
00220                                         switch_core_db_free(errmsg);
00221                                         errmsg = NULL;
00222                                 }
00223                         }
00224                 }
00225         }
00226 
00227 }

Here is the call graph for this function:


Generated on Fri Oct 10 11:24:33 2008 for FreeSWITCH by  doxygen 1.3.9.1