Esempio n. 1
0
void AddProductsForm::FillProductsList()
{
	try
	{
		IBPP::Transaction transaction = IBPP::TransactionFactory(db);
		transaction->Start();
		IBPP::Statement statement = IBPP::StatementFactory(db, transaction);
		statement->Execute("SELECT * FROM \"PRODUCTS\"");
		IBPP::Row row;
		statement->Fetch(row);
		auto rows = statement->AffectedRows();
		for (int i=0; i<rows; ++i)
		{
			int id;
			std::string name;
			row->Get(1, id);
			row->Get(2, name);
			ui.comboBox->addItem(name.c_str(), id);
			statement->Fetch(row);
		}
		ui.comboBox->setCurrentIndex(0);
	}
	catch (IBPP::Exception& exception)
	{
		std::string error = exception.ErrorMessage();
		qDebug() << exception.ErrorMessage();
	}
}
Esempio n. 2
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();
      }
   }
}
Esempio n. 3
0
void Exception::loadProperties(IBPP::Statement& statement, wxMBConv* converter)
{
    setPropertiesLoaded(false);

    std::string message;
    statement->Get(2, message);
    messageM = wxString(message.c_str(), *converter);
    statement->Get(3, numberM);
    if (statement->IsNull(4))
        setDescriptionIsEmpty();

    setPropertiesLoaded(true);
}
Esempio n. 4
0
void AddProductsForm::AddProducts()
{
	int productId = ui.comboBox->itemData(ui.comboBox->currentIndex()).toInt();
	int count = ui.spinBox->value();
	IBPP::Transaction transaction = IBPP::TransactionFactory(db);
	transaction->Start();
	IBPP::Statement statement = IBPP::StatementFactory(db, transaction);
	statement->Prepare("execute procedure ADD_PRODUCT_PROC (?, ?)");
	statement->Set(1, productId);
	statement->Set(2, count);
	statement->Execute();
	transaction->CommitRetain();
	qDebug() << "Executed!!";
}
Esempio n. 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;
}
Esempio n. 6
0
void Domain::loadProperties(IBPP::Statement& statement, wxMBConv* converter)
{
    setPropertiesLoaded(false);

    statement->Get(2, &datatypeM);
    if (statement->IsNull(3))
        subtypeM = 0;
    else
        statement->Get(3, &subtypeM);

    // determine the (var)char field length
    // - system tables use field_len and char_len is null
    // - computed columns have field_len/bytes_per_char, char_len is 0
    // - view columns have field_len/bytes_per_char, char_len is null
    // - regular table columns and SP params have field_len/bytes_per_char
    //   they also have proper char_len, but we don't use it now
    statement->Get(4, &lengthM);
    int bpc = 0;   // bytes per char
    if (!statement->IsNull(14))
        statement->Get(14, &bpc);
    if (bpc && (!statement->IsNull(8) || !statement->IsNull(13)))
        lengthM /= bpc;

    if (statement->IsNull(5))
        precisionM = 0;
    else
        statement->Get(5, &precisionM);
    if (statement->IsNull(6))
        scaleM = 0;
    else
        statement->Get(6, &scaleM);
    if (statement->IsNull(7))
        charsetM = "";
    else
    {
        std::string s;
        statement->Get(7, s);
        charsetM = std2wxIdentifier(s, converter);
    }
    bool notNull = false;
    if (!statement->IsNull(9))
    {
        statement->Get(9, notNull);
    }
    nullableM = !notNull;
    hasDefaultM = !statement->IsNull(10);
    if (hasDefaultM)
    {
        readBlob(statement, 10, defaultM, converter);
        defaultM = trimDefaultValue(defaultM);
    }
    else
        defaultM = wxEmptyString;

    if (statement->IsNull(11))
        collationM = wxEmptyString;
    else
    {
        std::string s;
        statement->Get(11, s);
        collationM = std2wxIdentifier(s, converter);
    }
    readBlob(statement, 12, checkM, converter);

    setPropertiesLoaded(true);
}