[Freeswitch-branches] [commit] r3833 - freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr
Freeswitch SVN
mishehu at freeswitch.org
Tue Dec 26 13:54:12 EST 2006
Author: mishehu
Date: Tue Dec 26 13:54:12 2006
New Revision: 3833
Modified:
freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/sqlitecdr.cpp
Log:
Made more code updates to SqliteCDR. In theory it should be functional now, but it has not even been compiled yet. Surely there's at least one honorary typo in it somewhere...
Modified: freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/sqlitecdr.cpp
==============================================================================
--- freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/sqlitecdr.cpp (original)
+++ freeswitch/branches/mishehu/src/mod/event_handlers/mod_cdr/sqlitecdr.cpp Tue Dec 26 13:54:12 2006
@@ -141,7 +141,7 @@
if(activated)
{
- tmp_sql_query = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,callenddate,originated,clid,src,dst,ani,aniii,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,hangupcause,amaflags";
+ tmp_sql_query = "INSERT INTO freeswitchcdr (callstartdate,callanswerdate,calltransferdate,callenddate,originated,clid,src,dst,ani,aniii,dialplan,myuuid,destuuid,srcchannel,dstchannel,lastapp,lastdata,billusec,disposition,hangupcause,amaflags";
int items_appended = 0;
@@ -159,7 +159,7 @@
}
}
- tmp_sql_query.append(") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?");
+ tmp_sql_query.append(") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?");
if(chanvars_fixed_list.size() > 0 )
{
@@ -175,173 +175,196 @@
strncpy(sql_query,tmp_sql_query.c_str(),tmp_sql_query.size());
- switch_core_db_open(db_filename.c_str(),&db);
+ int sql_rc = switch_core_db_open(db_filename.c_str(),&db);
- char sql_query_check_tables[] = "SELECT name FROM sqlite_master WHERE type = \"table\"";
- char **result;
- int nrow = 0, ncol = 0;
- char *errormessage;
- int sql_rc = switch_core_db_get_table(db,sql_query_check_tables,&result,&nrow,&ncol,&errormessage);
-
- std::map<std::string,bool> temp_chanvars_map;
- // Now to copy out all the chanvars from the list into
-
- std::map<std::string,bool> temp_sql_tables;
- temp_sql_tables["freeswitchcdr"] = 0;
- temp_sql_tables["chanvars"] = 0;
+ if(sql_rc != SQLITE_OK)
+ {
+ switch_console_printf(SWITCH_CHANNEL_LOG,"There was an error opening database filename %s. The error was: %s. SqliteCDR logging has been disabled until the problem is resolved and modcdr_reload is initiated.\n",db_filename.c_str(),switch_core_db_errmsg(db));
+ activated = 0;
+ switch_core_db_close(db);
+ }
+ else
+ {
+ char sql_query_check_tables[] = "SELECT name FROM sqlite_master WHERE type = \"table\"";
+ char **result;
+ int nrow = 0, ncol = 0;
+ char *errormessage;
+ sql_rc = switch_core_db_get_table(db,sql_query_check_tables,&result,&nrow,&ncol,&errormessage);
+
+ std::map<std::string,bool> temp_chanvars_map;
+ // Now to copy out all the chanvars from the list into
+
+ std::map<std::string,bool> temp_sql_tables;
+ temp_sql_tables["freeswitchcdr"] = 0;
+ temp_sql_tables["chanvars"] = 0;
- if(sql_rc == SQLITE_OK)
- for(int i = 0; i < nrows; i++)
+ if(sql_rc == SQLITE_OK)
{
- std::string tablename = result[i];
- if(tablename == "freeswitchcdr" || tablename == "chanvars")
+ for(int i = 0; i < nrows; i++)
{
- temp_sql_tables[tablename] = 1;
+ std::string tablename = result[i];
+ if(tablename == "freeswitchcdr" || tablename == "chanvars")
+ {
+ temp_sql_tables[tablename] = 1;
+ }
}
}
- else
- switch_console_printf(SWITCH_CHANNEL_LOG,"There was an error in executing query %s: The error was %s.\n",sql_query_check_tables,errormessage);
-
- if(!temp_sql_tables["freeswitchcdr"])
- {
- switch_console_printf(SWITCH_CHANNEL_LOG,"Creating the freeswitchcdr table in the SQLite mod_cdr database file.\n");
- // Must create the missing freeswitchcdr table.
- char sql_query_create_freeswitchcdr[] = "CREATE TABLE freeswitchcdr (\n"
- "callid INTEGER AUTOINCREMENT PRIMARY KEY,\n"
- "callstartdate INTEGER NOT NULL,\n"
- "callanswerdate INTEGER NOT NULL,\n"
- "calltransferdate INTEGER NOT NULL,\n"
- "callenddate INTEGER NOT NULL,\n"
- "originated INTEGER default 0,\n"
- "clid TEXT default \"Freeswitch - Unknown\",\n"
- "src TEXT NOT NULL,\n"
- "dst TEXT NOT NULL,\n"
- "ani TEXT default \"\",\n"
- "aniii TEXT default \"\",\n"
- "dialplan TEXT default \"\",\n"
- "myuuid TEXT NOT NULL,\n"
- "destuuid TEXT NOT NULL,\n"
- "srcchannel TEXT NOT NULL,\n"
- "dstchannel TEXT NOT NULL,\n"
- "lastapp TEXT default \"\",\n"
- "lastdata TEXT default \"\",\n"
- "billusec INTEGER default 0,\n"
- "disposition INTEGER default 0,\n" /* 0 = Busy or Unanswered, 1 = Answered */
- "hangupcause INTEGER default 0\n",
- "amaflags INTEGER default 0\n"
- ");\n";
-
- switch_core_db_exec(db, sql_query_create_freeswitchcdr, NULL, NULL, NULL);
- }
-
- if(!temp_sql_tables["chanvars"])
- {
- switch_console_printf(SWITCH_CHANNEL_LOG,"Creating the chanvars table in the SQLite mod_cdr database file.\n");
- // Must create the missing chanvars table.
- sql_query_create_chanvars[] = "CREATE TABLE chanvars (\n"
- "callid INTEGER default 0,\n""
- "varname TEXT NOT NULL,\n"
- "varvalue TEXT default \"\"\n"
- ");\n";
+ else
+ switch_console_printf(SWITCH_CHANNEL_LOG,"There was an error in executing query %s: The error was %s.\n",sql_query_check_tables,errormessage);
- switch_core_db_exec(db, sql_query_create_chanvars, NULL, NULL, NULL);
- }
+ switch_core_db_free_table(&result);
- if(chanvars_fixed_list.size() > 0)
- {
- // Now to check if the freeswitchcdr schema matches
- std::map<std::string,std::string> freeswitchcdr_columns;
- char sql_query_get_schema_of_freeswitchcdr[] = "SELECT * FROM SQLITE_MASTER WHERE name=\"freeswitchcdr\"";
- char **result2;
- nrow = 0;
- ncol = 0;
- char *errormessage2;
- sql_rc = switch_core_db_get_table(db,sql_query_get_schema_of_freeswitchcdr,&result,&nrow,&ncol,&errormessage);
+ if(!temp_sql_tables["freeswitchcdr"])
+ {
+ switch_console_printf(SWITCH_CHANNEL_LOG,"Creating the freeswitchcdr table in the SQLite mod_cdr database file.\n");
+ // Must create the missing freeswitchcdr table.
+ char sql_query_create_freeswitchcdr[] = "CREATE TABLE freeswitchcdr (\n"
+ "callid INTEGER AUTOINCREMENT PRIMARY KEY,\n"
+ "callstartdate INTEGER NOT NULL,\n"
+ "callanswerdate INTEGER NOT NULL,\n"
+ "calltransferdate INTEGER NOT NULL,\n"
+ "callenddate INTEGER NOT NULL,\n"
+ "originated INTEGER default 0,\n"
+ "clid TEXT default \"Freeswitch - Unknown\",\n"
+ "src TEXT NOT NULL,\n"
+ "dst TEXT NOT NULL,\n"
+ "ani TEXT default \"\",\n"
+ "aniii TEXT default \"\",\n"
+ "dialplan TEXT default \"\",\n"
+ "myuuid TEXT NOT NULL,\n"
+ "destuuid TEXT NOT NULL,\n"
+ "srcchannel TEXT NOT NULL,\n"
+ "dstchannel TEXT NOT NULL,\n"
+ "lastapp TEXT default \"\",\n"
+ "lastdata TEXT default \"\",\n"
+ "billusec INTEGER default 0,\n"
+ "disposition INTEGER default 0,\n" /* 0 = Busy or Unanswered, 1 = Answered */
+ "hangupcause INTEGER default 0\n",
+ "amaflags INTEGER default 0\n"
+ ");\n";
+
+ switch_core_db_exec(db, sql_query_create_freeswitchcdr, NULL, NULL, NULL);
+ }
+
+ if(!temp_sql_tables["chanvars"])
+ {
+ switch_console_printf(SWITCH_CHANNEL_LOG,"Creating the chanvars table in the SQLite mod_cdr database file.\n");
+ // Must create the missing chanvars table.
+ sql_query_create_chanvars[] = "CREATE TABLE chanvars (\n"
+ "callid INTEGER default 0,\n""
+ "varname TEXT NOT NULL,\n"
+ "varvalue TEXT default \"\"\n"
+ ");\n";
+
+ switch_core_db_exec(db, sql_query_create_chanvars, NULL, NULL, NULL);
+ }
- if(sql_rc == SQLITE_OK)
- for(int i = 0; i < nrows; i++)
+ if(chanvars_fixed_list.size() > 0)
+ {
+ // Now to check if the freeswitchcdr schema matches
+ std::map<std::string,std::string> freeswitchcdr_columns;
+ char sql_query_get_schema_of_freeswitchcdr[] = "SELECT * FROM SQLITE_MASTER WHERE name=\"freeswitchcdr\"";
+ char **result2;
+ nrow = 0;
+ ncol = 0;
+ char *errormessage2;
+ sql_rc = switch_core_db_get_table(db,sql_query_get_schema_of_freeswitchcdr,&result2,&nrow,&ncol,&errormessage);
+
+ if(sql_rc == SQLITE_OK)
{
- std::string resultstring = result2[i][4];
- std::string::size_type j = resultstring.find('(',i);
-
- std::string tempstring1,tempstring2;
-
- for(std::string::size_type i = j+1 ; j != std::string::npos; )
+ for(int i = 0; i < nrows; i++)
{
- j = resultstring.find(' ',i);
- if(j > 0)
+ std::string resultstring = result2[i][4];
+ std::string::size_type j = resultstring.find('(',i);
+
+ std::string tempstring1,tempstring2;
+
+ for(std::string::size_type i = j+1 ; j != std::string::npos; )
{
- tempstring = resultstring.substr(i,(j-i));
- i = j+1;
- j =resultstring.find(',',i);
- if(j == std::string::npos)
- tempstring2 = resultstring.substr(i,(resultstring.size() - i));
+ j = resultstring.find(' ',i);
+ if(j > 0)
+ {
+ tempstring = resultstring.substr(i,(j-i));
+ i = j+1;
+ j =resultstring.find(',',i);
+ if(j == std::string::npos)
+ tempstring2 = resultstring.substr(i,(resultstring.size() - i));
+ else
+ tempstring2 = resultstring.substr(i,(j-i));
+
+ freeswitchcdr_columns[tempstring1] = tempstring2;
+ }
else
- tempstring2 = resultstring.substr(i,(j-i));
-
- freeswitchcdr_columns[tempstring1] = tempstring2;
+ switch_console_printf(SWITCH_CHANNEL_LOG,"There has been a parsing problem with the freeswitchcdr schema.\n");
}
- else
- switch_console_printf(SWITCH_CHANNEL_LOG,"There has been a parsing problem with the freeswitchcdr schema.\n");
}
}
-
- // Now to actually compare what we have in the config against the db schema
- std::map<std::string,std::string> freeswitchcdr_add_columns;
- std::list<std::string>::iterator iItr, iEnd;
- switch_size_t i = 0;
- for(iItr = chanvars_fixed_list.begin(), iEnd = chanvars_fixed_list.end(); iItr != iEnd; iItr++, i++)
- {
- switch(chanvars_fixed_types[i])
+
+ switch_core_db_free_table(&result2);
+
+ // Now to actually compare what we have in the config against the db schema
+ std::map<std::string,std::string> freeswitchcdr_add_columns;
+ std::list<std::string>::iterator iItr, iEnd;
+ switch_size_t i = 0;
+ for(iItr = chanvars_fixed_list.begin(), iEnd = chanvars_fixed_list.end(); iItr != iEnd; iItr++, i++)
{
- case CDR_INTEGER:
- case CDR_TINY:
- if(freeswitchcdr_columns.find(*iItr) != freeswitchcdr_columns.end())
- {
- if(freeswitchcdr_columns[*iItr] != "INTEGER")
- switch_console_printf(SWITCH_CHANNEL_LOG,"WARNING: SqliteCDR freeswitchcdr table column type mismatch: Column \"%s\" is not of an INTEGER type. This is not necessarily fatal, but may result in unexpected behavior.\n",iItr->c_str());
- }
- else
- freeswitchcdr_add_columns[*iItr] = "INTEGER";
- break;
- case CDR_DOUBLE:
- if(freeswitchcdr_columns.find(*iItr) != freeswitchcdr_columns.end())
- {
- if(freeswitchcdr_columns[*iItr] != "REAL")
- switch_console_printf(SWITCH_CHANNEL_LOG,"WARNING: SqliteCDR freeswitchcdr table column type mismatch: Column \"%s\" is not of a REAL type. This is not necessarily fatal, but may result in unexpected behavior.\n",iItr->c_str());
- }
- else
- freeswitchcdr_add_columns[*iItr] = "REAL";
- break;
- case CDR_DECIMAL:
- case CDR_STRING:
- if(freeswitchcdr_columns.find(*iItr) != freeswitchcdr_columns.end())
- {
- if(freeswitchcdr_columns[*iItr] != "TEXT")
- switch_console_printf(SWITCH_CHANNEL_LOG,"WARNING: SqliteCDR freeswitchcdr table column type mismatch: Column \"%s\" is not of a TEXT type. This is not necessarily fatal, but may result in unexpected behavior.\n",iItr->c_str());
- }
- else
- freeswitchcdr_add_columns[*iItr] = "TEXT";
- break;
- default:
- switch_console_printf("Oh bother, I should not have fallen into this hole in the switch/case statement. Please notify the author.\n");
+ switch(chanvars_fixed_types[i])
+ {
+ case CDR_INTEGER:
+ case CDR_TINY:
+ if(freeswitchcdr_columns.find(*iItr) != freeswitchcdr_columns.end())
+ {
+ if(freeswitchcdr_columns[*iItr] != "INTEGER")
+ switch_console_printf(SWITCH_CHANNEL_LOG,"WARNING: SqliteCDR freeswitchcdr table column type mismatch: Column \"%s\" is not of an INTEGER type. This is not necessarily fatal, but may result in unexpected behavior.\n",iItr->c_str());
+ }
+ else
+ freeswitchcdr_add_columns[*iItr] = "INTEGER";
+ break;
+ case CDR_DOUBLE:
+ if(freeswitchcdr_columns.find(*iItr) != freeswitchcdr_columns.end())
+ {
+ if(freeswitchcdr_columns[*iItr] != "REAL")
+ switch_console_printf(SWITCH_CHANNEL_LOG,"WARNING: SqliteCDR freeswitchcdr table column type mismatch: Column \"%s\" is not of a REAL type. This is not necessarily fatal, but may result in unexpected behavior.\n",iItr->c_str());
+ }
+ else
+ freeswitchcdr_add_columns[*iItr] = "REAL";
+ break;
+ case CDR_DECIMAL:
+ case CDR_STRING:
+ if(freeswitchcdr_columns.find(*iItr) != freeswitchcdr_columns.end())
+ {
+ if(freeswitchcdr_columns[*iItr] != "TEXT")
+ switch_console_printf(SWITCH_CHANNEL_LOG,"WARNING: SqliteCDR freeswitchcdr table column type mismatch: Column \"%s\" is not of a TEXT type. This is not necessarily fatal, but may result in unexpected behavior.\n",iItr->c_str());
+ }
+ else
+ freeswitchcdr_add_columns[*iItr] = "TEXT";
+ break;
+ default:
+ switch_console_printf("Oh bother, I should not have fallen into this hole in the switch/case statement. Please notify the author.\n");
+ }
}
- }
-
- if(freeswitchcdr_add_columns.size())
- {
- switch_console_printf(SWITCH_CHANNEL_LOG,"Updating the freeswitchcdr table schema.\n");
- std::string tempsql_freeswitchcdr_alter_table = "ALTER TABLE freeswithcdr ADD ";
- std::map<std::string, std::string>::iterator iItr, iEnd;
- for(iItr = freeswitchcdr_add_columns.begin(), iEnd = freeswitchcdr_add_columns.end(); iItr != iEnd; iItr++)
+
+ if(freeswitchcdr_add_columns.size())
{
- std::string sql_query_freeswitchcdr_alter_table = tempsql_freeswitchcdr_alter_table;
- sql_query_freeswitchcdr_alter_table.append(iItr->first);
- sql_query_freeswitchcdr_alter_table.append(" ");
- sql_query_freeswitchcdr_alter_table.append(iItr->second);
- switch_core_db_exec(db, sql_query_freeswitchcdr_alter_table.c_str(), NULL, NULL, NULL);
+ switch_console_printf(SWITCH_CHANNEL_LOG,"Updating the freeswitchcdr table schema.\n");
+ std::string tempsql_freeswitchcdr_alter_table = "ALTER TABLE freeswithcdr ADD ";
+ std::map<std::string, std::string>::iterator iItr, iEnd;
+ for(iItr = freeswitchcdr_add_columns.begin(), iEnd = freeswitchcdr_add_columns.end(); iItr != iEnd; iItr++)
+ {
+ std::string sql_query_freeswitchcdr_alter_table = tempsql_freeswitchcdr_alter_table;
+ sql_query_freeswitchcdr_alter_table.append(iItr->first);
+ sql_query_freeswitchcdr_alter_table.append(" ");
+ sql_query_freeswitchcdr_alter_table.append(iItr->second);
+ switch_core_db_exec(db, sql_query_freeswitchcdr_alter_table.c_str(), NULL, NULL, NULL);
+ }
}
}
+
+ switch_core_db_prepare(db,"BEGIN TRANSACTION SqliteCDR",-1,&stmt_begin,0);
+ switch_core_db_prepare(db,"COMMIT TRANSACTION SqliteCDR",-1,&stmt_commit,0);
+ switch_core_db_prepare(db,tmp_sql_query.c_str(),-1,&stmt,0);
+ if(chanvars_supp_list.size())
+ switch_core_db_prepare(db,sql_query_chanvars,-1,&stmt_chanvars,0);
}
}
}
@@ -365,237 +388,62 @@
bool SqliteCDR::process_record()
{
- std::list<void*> temp_chanvars_holder; // This is used for any fixed chanvars, as we don't want things out of scope
-
- if(chanvars_fixed_list.size() > 0)
+ int column = 1;
+ switch_core_db_step(stmt_begin);
+ switch_core_db_bind_int64(stmt, column++, (sqlite_int64) callstartdate);
+ switch_core_db_bind_int64(stmt, column++, (sqlite_int64) callanswerdate);
+ switch_core_db_bind_int64(stmt, column++, (sqlite_int64) calltransferdate);
+ switch_core_db_bind_int64(stmt, column++, (sqlite_int64) callenddate);
+ switch_core_db_bind_int(stmt, column++, (sqlite_int) originated);
+ switch_core_db_bind_text(stmt, column++, clid,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, src,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, dst,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, ani,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, aniii,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, dialplan,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, myuuid,36,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, destuuid,36,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, srcchannel,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, dstchannel,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, lastapp,-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt, column++, lastdata,-1,SQLITE_STATIC);
+ switch_core_db_bind_int64(stmt, column++, (sqlite_int64) billusec);
+ switch_core_db_bind_int(stmt, column++, (sqlite_int) disposition);
+ switch_core_db_bind_int(stmt, column++, (sqlite_int) hangupcause);
+ switch_core_db_bind_int(stmt, column++, (sqlite_int) amaflags);
+ int sql_rc = switch_core_db_step(stmt);
+ if(sql_rc != SQLITE_DONE)
{
- switch_size_t i = 0; // temporary variable, i is current spot on the string of types
- std::list<std::pair<std::string,std::string> >::iterator iItr, iEnd;
- for(iItr = chanvars_fixed.begin(), iEnd = chanvars_fixed.end(); iItr != iEnd; iItr++)
- {
- switch(chanvars_fixed_types[i])
- {
- case CDR_INTEGER:
- {
- int* x = new int;
- *x = 0;
- bool* is_null = new bool;
- *is_null = 0;
-
- if(iItr->second.size() > 0)
- {
- std::istringstream istring(iItr->second);
- istring >> *x;
- }
- else
- *is_null = 1;
- temp_chanvars_holder.push_back(x);
- temp_chanvars_holder.push_back(is_null);
- add_parameter(*x,MYSQL_TYPE_LONG,is_null);
- break;
- }
- case CDR_DOUBLE:
- {
- double* x = new double;
- *x = 0;
- bool* is_null = new bool;
- *is_null = 0;
- if(iItr->second.size() > 0)
- {
- std::istringstream istring(iItr->second);
- istring >> *x;
- }
- else
- *is_null = 1;
- temp_chanvars_holder.push_back(x);
- temp_chanvars_holder.push_back(is_null);
- add_parameter(*x,MYSQL_TYPE_DOUBLE,is_null);
- break;
- }
- case CDR_TINY:
- {
- short* x = new short;
- *x = 0;
- bool* is_null = new bool;
- *is_null = 0;
- if(iItr->second.size() > 0)
- {
- std::istringstream istring(iItr->second);
- istring >> *x;
- }
- else
- *is_null = 1;
- temp_chanvars_holder.push_back(x);
- temp_chanvars_holder.push_back(is_null);
- add_parameter(*x,MYSQL_TYPE_TINY,is_null);
- break;
- }
- case CDR_STRING:
- case CDR_DECIMAL:
- {
- long unsigned int* stringlength = new long unsigned int;
- *stringlength = (long unsigned int)(iItr->second.size());
-
- char* x = new char[(*stringlength+1)];
- strncpy(x,iItr->second.c_str(),*stringlength);
-
- bool* is_null = new bool;
- *is_null = 0;
- add_string_parameter(x,*stringlength,MYSQL_TYPE_VAR_STRING,is_null);
-
- temp_chanvars_holder.push_back(stringlength);
- temp_chanvars_holder.push_back(x);
- temp_chanvars_holder.push_back(is_null);
- break;
- }
- default:
- switch_console_printf(SWITCH_CHANNEL_LOG,"We should not get to this point in this switch/case statement.\n");
- }
- i++;
- }
+ if(sql_rc == SQLITE_BUSY)
+ sql_rc = switch_core_db_step(stmt);
+ else if (sql_rc == SQLITE_ERROR || sql_rc == SQLITE_MISUSE)
+ switch_console_printf(SWITCH_CHANNEL_LOG,"There was an error executing switch_core_db_step on SqliteCDR::stmt. The error was: %s\n",switch_core_db_errmsg(db));
}
-
- MYSQL_BIND *bindmetemp;
- bindmetemp = new MYSQL_BIND[bindme.size()];
- copy(bindme.begin(), bindme.end(), bindmetemp);
- for(int mysql_ping_result = -1, count = 0, mysql_stmt_error_code = -1; mysql_ping_result != 0 && count < 5 && mysql_stmt_error_code != 0 ; count++)
+ if(logchanvars && chanvars_supp.size())
{
- mysql_ping_result = mysql_ping(conn);
- if(mysql_ping_result)
+ sqlite_int64 rowid = switch_core_db_last_insert_rowid(db);
+ int column2 = 1;
+ std::map<std::string,std::string>::iterator iItr, iEnd;
+ for(iItr = chanvars_supp.begin(), iEnd = chanvars_supp.end(); iItr != iEnd; iItr++)
{
- switch(mysql_ping_result)
- {
- case CR_SERVER_GONE_ERROR:
- case CR_SERVER_LOST:
- {
- switch_console_printf(SWITCH_CHANNEL_LOG,"We lost connection to the MySQL server. Trying to reconnect.\n");
- connect_to_database();
- break;
- }
- default:
- {
- switch_console_printf(SWITCH_CHANNEL_LOG,"We have encountered an unknown error when pinging the MySQL server. Attempting to reconnect anyways.\n");
- connect_to_database();
- }
- }
+ switch_core_db_bind_int64(stmt_chanvars, column++, rowid);
+ switch_core_db_bind_text(stmt_chanvars, column++, iItr->first.c_str(),-1,SQLITE_STATIC);
+ switch_core_db_bind_text(stmt_chanvars, column++, iItr->second.c_str(),-1,SQLITE_STATIC);
}
- else
+
+ int sql_rc = switch_core_db_step(stmt_chanvars);
+ if(sql_rc != SQLITE_DONE)
{
- mysql_stmt_bind_param(stmt,bindmetemp);
- mysql_stmt_error_code = mysql_stmt_execute(stmt);
-
- if(mysql_stmt_error_code != 0)
- {
- errorstate = 1;
- switch_console_printf(SWITCH_CHANNEL_LOG,"MysqlCDR::process_record() - Statement executed? Error: %d\n",mysql_stmt_error_code);
-
- const char* mysql_stmt_error_string = mysql_stmt_error(stmt);
- switch_console_printf(SWITCH_CHANNEL_LOG,"MySQL encountered error: %s\n",mysql_stmt_error_string);
- }
- else
- errorstate = 0;
-
- if(logchanvars && chanvars_supp.size() > 0 && errorstate == 0)
- {
- long long insertid = mysql_stmt_insert_id(stmt);
-
- std::map<std::string,std::string>::iterator iItr,iBeg,iEnd;
- iEnd = chanvars_supp.end();
- for(iItr = chanvars_supp.begin(); iItr != iEnd; iItr++)
- {
- MYSQL_BIND bindme_chanvars[3];
- memset(bindme_chanvars,0,sizeof(bindme_chanvars));
-
- bindme_chanvars[0].buffer_type = MYSQL_TYPE_LONGLONG;
- bindme_chanvars[0].buffer = &insertid;
-
- std::vector<char> tempfirstvector(iItr->first.begin(), iItr->first.end());
- tempfirstvector.push_back('\0');
- char* varname_temp = &tempfirstvector[0];
-
- bindme_chanvars[1].buffer_type = MYSQL_TYPE_VAR_STRING;
- long unsigned int varname_length = (long unsigned int)(iItr->first.size());
- bindme_chanvars[1].length = &varname_length;
- bindme_chanvars[1].buffer_length = varname_length;
- bindme_chanvars[1].buffer = varname_temp;
-
- std::vector<char> tempsecondvector(iItr->second.begin(), iItr->second.end());
- tempsecondvector.push_back('\0');
- char* varvalue_temp = &tempsecondvector[0];
-
- bindme_chanvars[2].buffer_type = MYSQL_TYPE_VAR_STRING;
- if(iItr->second.size() == 0)
- bindme_chanvars[2].is_null = (my_bool*)1;
- else
- {
- long unsigned int varvalue_length = (long unsigned int)(iItr->second.size());
- bindme_chanvars[2].length = &varvalue_length;
- bindme_chanvars[2].buffer_length = varvalue_length;
- bindme_chanvars[2].buffer = varvalue_temp;
- }
-
- mysql_stmt_bind_param(stmt_chanvars,bindme_chanvars);
- mysql_stmt_execute(stmt_chanvars);
- }
- }
-
- if(errorstate == 0)
- mysql_commit(conn);
- else
- mysql_rollback(conn);
+ if(sql_rc == SQLITE_BUSY)
+ sql_rc = switch_core_db_step(stmt_chanvars);
+ else if (sql_rc == SQLITE_ERROR || sql_rc == SQLITE_MISUSE)
+ switch_console_printf(SWITCH_CHANNEL_LOG,"There was an error executing switch_core_db_step on SqliteCDR::stmt. The error was: %s\n",switch_core_db_errmsg(db));
}
}
- delete [] bindmetemp;
- if(temp_chanvars_holder.size() > 0)
- {
- std::string::size_type i = 0, j = chanvars_fixed_types.size();
- for(; i < j ; i++)
- {
- switch(chanvars_fixed_types[i])
- {
- case CDR_STRING:
- case CDR_DECIMAL:
- {
- long unsigned int* stringlength = (long unsigned int*)temp_chanvars_holder.front();
- temp_chanvars_holder.pop_front();
- delete stringlength;
- char* tempstring = (char*) temp_chanvars_holder.front();
- temp_chanvars_holder.pop_front();
- delete [] tempstring;
- break;
- }
- case CDR_INTEGER:
- {
- int* tempint = (int*) temp_chanvars_holder.front();
- temp_chanvars_holder.pop_front();
- delete tempint;
- break;
- }
- case CDR_DOUBLE:
- {
- double* tempdouble = (double*) temp_chanvars_holder.front();
- temp_chanvars_holder.pop_front();
- delete tempdouble;
- break;
- }
- case CDR_TINY:
- {
- short* tempshort = (short*) temp_chanvars_holder.front();
- temp_chanvars_holder.pop_front();
- delete tempshort;
- break;
- }
- default:
- switch_console_printf(SWITCH_CHANNEL_LOG,"We should not get to this point in this switch/case statement.\n");
- }
-
- bool* tempbool = (bool*) temp_chanvars_holder.front();
- temp_chanvars_holder.pop_front();
- delete tempbool;
- }
- }
+ switch_core_db_step(stmt_commit);
+
return 1;
}
More information about the Freeswitch-branches
mailing list