#include #include "ace/INET_Addr.h" #include "ace/Synch.h" #include "ace/Hash_Map_Manager_T.h" #include "PES/PESCommon.h" #include "Database.h" #include "DbBase.h" #include "DbConnection.h" #define MAX_PRINT 15 void rollbackToSavePoint1(DbConnection* dbc) { printf("rollback savepoint1\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "ROLLBACK TO PIPECMD1"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void rollbackToSavePoint(DbConnection* dbc) { printf("rollback savepoint\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "ROLLBACK TO PIPECMD"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void createSavePoint1(DbConnection* dbc) { printf("create savepoint1\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "SAVEPOINT PIPECMD1"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void createSavePoint(DbConnection* dbc) { printf("create savepoint\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "SAVEPOINT PIPECMD"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void releaseSavePoint(DbConnection* dbc) { printf("release savepoint\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "RELEASE SAVEPOINT PIPECMD"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery(DbConnection* dbc) { printf("testquery pass\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "INSERT INTO authors (name, birthdate) VALUES ('J.K. Rowling', '1965-07-31');"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery1(DbConnection* dbc) { printf("testquery1 pass\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "INSERT INTO authors (name, birthdate) VALUES ('George R.R. Martin', '1948-09-20');"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery2(DbConnection* dbc) { printf("testquery2 pass\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "INSERT INTO books (title, published_date, author_id) VALUES ('Harry Potter and the Philosopher''s Stone', '1997-06-26', 1);"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery3(DbConnection* dbc) { printf("testquery3 pass\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "INSERT INTO books (title, published_date, author_id) VALUES ('A Game of Thrones', '1996-08-06', 2);"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery4(DbConnection* dbc) { printf("testquery4 pass\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "select from authors where name = 'J.K. Rowling';"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery5(DbConnection* dbc) { printf("testquery5 no data\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "select from authors where name = 'J.K. Rowling2';"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery6(DbConnection* dbc) { printf("testquery6 failure insert\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "INSERT INTO books (title, published_date, author_id) VALUES ('Harry Potter and the Philosopher''s Stone', '1997-06-26', 3);"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } void testQuery7(DbConnection* dbc) { printf("testquery7 pass\n"); HSTMT hstmt; hstmt = DbCommon::newStatementHandle(dbc->getConnectionHandle(), "INSERT INTO books (title, published_date, author_id) VALUES ('Harry Potter 2 and the Philosopher''s Stone', '1997-06-26', 2);"); ODBCContext odbcCtx(dbc->getConnectionHandle(),hstmt); // execute sql statement if(!SQLCheck(SQLExecute(hstmt),odbcCtx)) DbStatics::GetErrorInfo(dbc->getConnectionHandle(),hstmt); DbCommon::freeStatement(hstmt,odbcCtx,TRUE); //SQLRETURN rc = SQLEndTran(SQL_HANDLE_DBC, dbc, SQL_COMMIT); } int main(int, char**) { /* int res; int query; int counter; HDBC sqlCntxt = NULL; Carrier CarC, Car, CarN; Subscriber Subs, SubsN; Trunkgroup TgC, Tg, TgN; Gateway GwC, Gw, GwN; GatewayLrns GwLrC, GwLr, GwLrN; Partition ParC, Par, ParN; Ssg SgC, Sg, SgN; Country CntC, Cnt, CntN; Script ScrC, Scr, ScrN; Destination Dest, DestN; TableChanges TabC, TabCN; Country rtCnt; TollfreePrefix TlPrC, TlPr, TlPrN; NpaNxx NpNx, NpNxN; Authcode Auth, AuthN; Infodigit InfoC, Info, InfoN; Softswitch SoftC, Soft, SoftN; DbCarrier900Nxx CrNx; SRouteList rtList; // initialize connection manager DbConnectionManager::GetInstance().Initialize(FALSE); // Connect to the Database. DbError::ErrorCode errCode; DbConnection* dbConn = DbConnectionManager::GetInstance().GetConnection("dbimpl","dbimpl", errCode); DbConnectionManager::GetInstance().ReleaseConnection(dbConn); */ HDBC sqlCntxt = NULL; DbError::ErrorCode errCode; //DbConnection* dbConn = // DbConnectionManager::GetInstance().GetConnection("dbimpl","dbimpl", // errCode); // DbConnectionManager::GetInstance().Initialize(FALSE); DbConnection* dbConn = DbConnectionManager::GetInstance().createConnection(); if (NULL != dbConn) { sqlCntxt = dbConn->getConnectionHandle(); } printf("%x", dbConn); createSavePoint(dbConn); testQuery(dbConn); rollbackToSavePoint(dbConn); createSavePoint(dbConn); testQuery(dbConn); rollbackToSavePoint(dbConn); createSavePoint(dbConn); testQuery(dbConn); rollbackToSavePoint(dbConn); DbConnectionManager::GetInstance().ReleaseConnection(dbConn); }