SQLData Systems, Inc.
Home | Products | Services | Documents | Support

 

This sample demonstrates how easy it is to create a dynamic SQL processor using the ODBC Broker.  The function is capable of processing any SQL statement in Data Definition Language (DDL), Data Manipulation Language (DML) and Data Control Language (DCL) if supported by the ODBC driver.

/* the ExecuteSQL function is a dynamic SQL processor. It requires two arguments: an ODBC data source name (DSN) and an SQL  statement.  The DSN can also be a connect string in a format of DSN=DataSourceName;UID=YourUserId;PWD=YourPassword*/

long ExecuteSQL(const char * szDataSource, const char * szSQL)
{
    int nRowsAffected=0;
    Broker *pBroker =CreateBroker(Broker::DATA_BROKER, NULL);

    // make a database connection
    if(!pBroker->Connect(szDataSource, "", ""))
    {
        // we have trouble connecting to the database
        printf("Unable to connect to the database %s\n",
            szDataSource);
        return 0;
    }
    if(pBroker->ExecuteSQL(szSQL))
    {
        // SQL statement is executed successfully.
        nRowsAffected=pBroker->GetRowCount();
        printf("Number of rows affected is : %d\n",
            nRowsAffected);
    }
    else
    {
        // ooops, something wrong, let's get error string.
        printf("Error execute sql, %s\n",
            pBroker->GetErrorString());
    }

    // we are done
    DestroyBroker(pBroker);
    return nRowsAffected;
}

 

Download | Purchase | ContactFeedback

horizontal rule

Send mail to  info2-at-sqldata-dot-com with questions or comments about this web site.
Copyright 2008-2010 SQLData Systems, Inc.
Last modified: July 10, 2010