Example #1
0
// Whether or not the SqldbResource is ready for use by a Sqldb.
bool SqldbResource::isReadyToStart(UtlString& missingResource)
{
   bool dbIsReady;

   // Check to ensure that we can connect to the database.
   OdbcHandle dbHandle = odbcConnect(mDbName, mServer, mUser, mDbDriver, mPassword);
   if (dbHandle)
   {
      odbcDisconnect(dbHandle);
      OsSysLog::add(FAC_SUPERVISOR, PRI_INFO, "SqldbResource::isReadyToStart "
                     "Successfully connected to database '%s'",
                     mDbName.data());
      dbIsReady = true;
   }
   else
   {
      OsSysLog::add(FAC_SUPERVISOR, PRI_ERR, "SqldbResource::isReadyToStart "
                     "Unable to connect to database '%s'",
                     mDbName.data());
      missingResource = "";
      appendDescription(missingResource);
      dbIsReady = false;
   }

   return dbIsReady;
}
Example #2
0
 void testOdbcConnect()
    {
       OdbcHandle handle = NULL;
     
       CPPUNIT_ASSERT((handle=odbcConnect(DATABASE_NAME,
                                          "localhost",
                                          POSTGRESQL_USER,
                                          "{PostgreSQL}"))!=NULL);
       
       if (handle)
       {
          CPPUNIT_ASSERT(odbcDisconnect(handle));
       }
    }
bool CallStateEventWriter_DB::closeLog()
{
   bool bRet = false;

   if (mHandle)
   {
      odbcDisconnect(mHandle);
      mHandle = NULL;
   }
   mbWriteable = false;
   bRet = true;

   Os::Logger::instance().log(FAC_CDR, PRI_DEBUG,
                 "%s::closeLog", ModuleName);
   return bRet;
}
Example #4
0
 void testOdbcValidateObserverData()
    {
       OdbcHandle handle = NULL;
       char sqlStatement[256];
    
       CPPUNIT_ASSERT((handle=odbcConnect(DATABASE_NAME,
                                          "localhost",
                                          POSTGRESQL_USER,
                                          "{PostgreSQL}"))!=NULL);
       
       if (handle)
       {
          databaseWrite(handle);
          int cols;            
          
          // Get data from call_state_observer_events
          sprintf(sqlStatement, "SELECT * FROM observer_state_events;");
          CPPUNIT_ASSERT(odbcExecute(handle, sqlStatement));
          
          CPPUNIT_ASSERT((cols=odbcResultColumns(handle)) == 6);
          
          CPPUNIT_ASSERT(odbcGetNextRow(handle));
          
          char buffer[256];
          
          CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 2, buffer, 256));
          CPPUNIT_ASSERT(strcmp(buffer, "10.1.20.3:5060") == 0);
          CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 3, buffer, 256));
          CPPUNIT_ASSERT(strcmp(buffer, "0") == 0);
          CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 4, buffer, 256));
          // When returning a timestamp as string data the fractional component
          // is truncated - this is expected behavior
          CPPUNIT_ASSERT(strcmp(buffer, "2006-03-10 12:59:00") == 0);            
   
          CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 5, buffer, 256));
          CPPUNIT_ASSERT(strcmp(buffer, "101") == 0);
          CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 6, buffer, 256));
          CPPUNIT_ASSERT(strcmp(buffer, "AuthProxyCseObserver") == 0);    
                         
          CPPUNIT_ASSERT(odbcDisconnect(handle));                           
       }
    }
Example #5
0
   void testOdbcValidateEventData()
      {
         OdbcHandle handle = NULL;
         char sqlStatement[256];
      
         CPPUNIT_ASSERT((handle=odbcConnect(DATABASE_NAME,
                                            "localhost",
                                            POSTGRESQL_USER,
                                            "{PostgreSQL}"))!=NULL);
         
         if (handle)
         {
            databaseWrite(handle);
            
            int cols;           
          
            // Get data from call_state_events
            sprintf(sqlStatement, "SELECT * FROM call_state_events;");
            CPPUNIT_ASSERT(odbcExecute(handle, sqlStatement));
            
            CPPUNIT_ASSERT((cols=odbcResultColumns(handle)) == 17);   

            CPPUNIT_ASSERT(odbcGetNextRow(handle));
            
            char buffer[256];            

            // First record
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 2, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "10.1.20.3:5060") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 3, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "1") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 4, buffer, 256));
            // When returning a timestamp as string data the fractional component
            // is truncated - this is expected behavior
            CPPUNIT_ASSERT(strcmp(buffer, "2006-03-10 13:00:00") == 0);            
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 5, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "R") == 0);            
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 7, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "call-111111") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 8, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "12345") == 0);    
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 9, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "67890") == 0);               
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 10, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "sip:[email protected]") == 0);               
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 11, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "sip:[email protected]") == 0);                                       
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 12, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "10.1.1.71") == 0);               
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 13, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "refer-to") == 0);   
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 14, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "referred-by") == 0);                                                   
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 15, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "0") == 0);                           
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 16, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "No Reason") == 0);                           
            
            CPPUNIT_ASSERT(odbcGetNextRow(handle));            

            // Second record            
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 2, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "10.1.20.3:5060") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 3, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "2") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 4, buffer, 256));
            // When returning a timestamp as string data the fractional component
            // is truncated - this is expected behavior
            CPPUNIT_ASSERT(strcmp(buffer, "2006-03-10 13:00:10") == 0);            
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 5, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "S") == 0);            
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 7, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "call-111112") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 8, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "54321") == 0);    
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 9, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "09876") == 0);               
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 10, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "sip:[email protected]") == 0);               
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 11, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "sip:[email protected]") == 0);                                       
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 12, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "10.1.20.71") == 0);               
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 13, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "refer-to-2") == 0);
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 14, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "referred-by-2") == 0);                  
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 15, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "0") == 0);                           
            CPPUNIT_ASSERT(odbcGetColumnStringData(handle, 16, buffer, 256));
            CPPUNIT_ASSERT(strcmp(buffer, "No Reason-2") == 0);                                       
            
            // End of rows 
            CPPUNIT_ASSERT(!odbcGetNextRow(handle));
           
            CPPUNIT_ASSERT(odbcDisconnect(handle));
         }
      }