Example #1
0
void TsSqlDatabaseThread::test()
{
   IBPP::Database db = IBPP::DatabaseFactory(
      "",
      "melchior:/var/firebird/test.fdb",
      "sysdba",
      "5735");
   db->Connect();
   IBPP::Transaction tr = IBPP::TransactionFactory(db);
   tr->Start();

   IBPP::Statement st = IBPP::StatementFactory(
      db, 
      tr, 
      "select * from test2");
   st->Execute();
   if (st->Fetch())
   {
      int cols = st->Columns();
      for(int i = 1; i <= cols; ++i)
      {
         TsSqlVariant variant;
         setFromStatement(variant, &st, i);
         qDebug() << variant.asString();
      }
   }
}
Example #2
0
void TransactionImpl::DetachDatabase(IBPP::Database db)
{
	if (db.intf() == 0)
		throw LogicExceptionImpl("Transaction::DetachDatabase",
				_("Can't detach an unbound Database."));

	DetachDatabaseImpl(dynamic_cast<DatabaseImpl*>(db.intf()));
}
Example #3
0
void TransactionImpl::AttachDatabase(IBPP::Database db,
	IBPP::TAM am, IBPP::TIL il, IBPP::TLR lr, IBPP::TFF flags)
{
	if (db.intf() == 0)
		throw LogicExceptionImpl("Transaction::AttachDatabase",
				_("Can't attach an unbound Database."));

	AttachDatabaseImpl(dynamic_cast<DatabaseImpl*>(db.intf()), am, il, lr, flags);
}
Example #4
0
void TransactionImpl::AddReservation(IBPP::Database db,
	const std::string& table, IBPP::TTR tr)
{
	if (mHandle != 0)
		throw LogicExceptionImpl("Transaction::AddReservation",
				_("Can't add table reservation if Transaction started."));
	if (db.intf() == 0)
		throw LogicExceptionImpl("Transaction::AddReservation",
				_("Can't add table reservation on an unbound Database."));

	// Find the TPB associated with this database
	std::vector<DatabaseImpl*>::iterator pos =
		std::find(mDatabases.begin(), mDatabases.end(), dynamic_cast<DatabaseImpl*>(db.intf()));
	if (pos != mDatabases.end())
	{
		size_t index = pos - mDatabases.begin();
		TPB* tpb = mTPBs[index];
		
		// Now add the reservations to the TPB
		switch (tr)
		{
			case IBPP::trSharedWrite :
					tpb->Insert(isc_tpb_lock_write);
					tpb->Insert(table);
					tpb->Insert(isc_tpb_shared);
					break;
			case IBPP::trSharedRead :
					tpb->Insert(isc_tpb_lock_read);
					tpb->Insert(table);
					tpb->Insert(isc_tpb_shared);
					break;
			case IBPP::trProtectedWrite :
					tpb->Insert(isc_tpb_lock_write);
					tpb->Insert(table);
					tpb->Insert(isc_tpb_protected);
					break;
			case IBPP::trProtectedRead :
					tpb->Insert(isc_tpb_lock_read);
					tpb->Insert(table);
					tpb->Insert(isc_tpb_protected);
					break;
			default :
					throw LogicExceptionImpl("Transaction::AddReservation",
						_("Illegal TTR value detected."));
		}
	}
	else throw LogicExceptionImpl("Transaction::AddReservation",
			_("The database connection you specified is not attached to this transaction."));
}
Example #5
0
int main()
{

    try
    {

        //  ------------------------------------------------------------

        //          L E C T U R A

        //  ------------------------------------------------------------

        try
        {
            IBPP::Database db = IBPP::DatabaseFactory("127.0.0.1", "testing", "SYSDBA", "pruebas");
            db->Connect();
            IBPP::Transaction tr = IBPP::TransactionFactory(db);
            tr->Start();

                int  id=0;
                std::string idServidor;
                mtk::nullable<mtk::DateTime> dt;

                IBPP::Statement st = IBPP::StatementFactory(db, tr);
                st->Execute("SELECT FIRST 10 * FROM ALARMS");
                while (st->Fetch())
                {
                    st->Get(1, id);                         //  acceso por índice
                    cout << "id          : " << id << std::endl;

                    st->Get("SOURCE", idServidor);     //  acceso por nombre
                    cout << "SOURCE  : " << idServidor << endl;


                    st->Get(st->ColumnNum("DB_TIME"), dt);   //   acceso por (índice -> nombre)
                    cout << "DB_TIME  : " << dt.Get() << endl;


                    cout << endl;
                }


            tr->Commit();
            db->Disconnect();
        }
        MTK_CATCH_RETHROW("main", "reading error")
            //  también se pueden hacer lecturas con parámetros






        //  ------------------------------------------------------------

        //          E S C R I T U R A

        //  ------------------------------------------------------------


        try
        {
            IBPP::Database db = IBPP::DatabaseFactory("127.0.0.1", "testing", "SYSDBA", "pruebas");
            db->Connect();
            IBPP::Transaction tr = IBPP::TransactionFactory(db);
            tr->Start();

                IBPP::Statement st = IBPP::StatementFactory(db, tr);
                st->Prepare(
                            "INSERT INTO ALARMS (DB_TIME, SOURCE, DESCRIPTION)"
                            "VALUES (?, ?, ?)"
               );
               st->Set(1, mtk::dtNowLocal());
               st->Set(2, MTK_SS("sc"<< mtk::dtNowLocal()));
               st->Set(3, MTK_SS("description" << mtk::dtNowLocal()));
               st->Execute();

            tr->Commit();
            db->Disconnect();
        }
        MTK_CATCH_RETHROW("main", "reading error")

        #include "support/release_on_exit.hpp"
        return 0;

    }
    MTK_CATCH_CALLFUNCION(std::cout <<, "main", "error")
    #include "support/release_on_exit.hpp"
    return -1;
}