Anand Yogas wrote:
> Hi All,
>
>           I would like to fetch values from Sipxces database tables
> through C++ code.
>
>           For that I have used the following database functions
>
>
>          OdbcHandle handle = NULL;
>
>           
> handle=odbcConnect("SIPXCONFIG","localhost","postgres","{PostgreSQL}");
>
>           char sqlStatement[256];     
>
>           sprintf(sqlStatement, "SELECT *  FROM table_name;");
>
>           odbcExecute(handle,sqlStatement);
>
>            char buffer[256];
>
>                  odbcGetColumnStringData(handle, 1, buffer, 256);
>                                                                       
>                                       
>       I checked each database statements manually (means check value by the
> help of log file) all returns true and working well.
>
>         But when I print "buffer" as a string then it gives me garbage.
>
>         Please, tell me how can I get this value in buffer or do I
> need to follow some extra steps. where I am lacking.
>
>         It is urgent so please reply me asap.
>
>
> Thanks In Advance,
> Anand.
Here's how I've done for XCF-1891 ( 
http://track.sipfoundry.org/browse/XCF-1891 ) to connect to the CDR 
database and get the number of failed calls.
The code is in C, haven't tried in C++. Checkout the patch ( 
http://track.sipfoundry.org/secure/attachment/15305/0002-XCF-1891-Implement-Call-Statistics-into-MRTG-imple.patch
 
) for more info.
int getSipxecsNumberOfFailedCalls(void)
{
    const char    *conninfo;
    PGconn    *conn;
    PGresult    *res;
    int failed_calls = 0;

    conninfo = "dbname = SIPXCDR user = postgres host = localhost";

    /* Make a connection to the database */
    conn = PQconnectdb(conninfo);

    /* Check to see that the backend connection was successfully made */
    if (PQstatus(conn) != CONNECTION_OK)
    {
        DEBUGMSGTL(("sipxecsNumberOfFailedCalls",
                    "Connection to database failed: %s", 
PQerrorMessage(conn)));
        PQfinish(conn);
        return failed_calls;
    }

    /* select ... */
    res = PQexec(conn, "select count(*) from view_cdrs where termination 
= 'F';");
    if (PQresultStatus(res) != PGRES_TUPLES_OK)
    {
        DEBUGMSGTL(("sipxecsNumberOfFailedCalls",
                    "Select error: %s\n", PQerrorMessage(conn)));
        PQclear(res);
        PQfinish(conn);
        return failed_calls;
    }

    failed_calls = atoi(PQgetvalue(res, 0, 0));
    PQclear(res);
    PQfinish(conn);

    return failed_calls;
}

Hope this helps,
Andrei
_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev
Unsubscribe: http://list.sipfoundry.org/mailman/listinfo/sipx-dev

Reply via email to