예제 #1
0
PhoebetriaApp::PhoebetriaApp(int &argc, char **argv)
    : QApplication(argc, argv),
      m_currentStyle_filename()
{
    setOrganizationName("Phoebetria");
    setApplicationName("Phoebetria");

    QSettings::setDefaultFormat(QSettings::IniFormat);

    DatabaseManager db;
    db.initAllDatabases();

    if (!setTheme(m_prefs.stylesheet()))
    {
        QMessageBox::critical(
                    NULL,
                    tr("Could not set style."),
                    tr("Could not set the application style."
                               " It may not exist. Please check preferences.\n\n"
                               "Style filename: %1\n\n"
                               "Setting to the standard profile instead."
                       ).arg(m_prefs.stylesheet())
                    );
        setTheme(Themes::getBuiltInStyleSheetName());
    }

    m_globalTimer.start(200);
    m_dispatcher.start(200);

    m_fanControllerIO.connect();            // Connect to the IO device
    m_fanControllerIO.connectSignals();

    m_fanControllerIO.fanControllerData().connectSignals();
}
예제 #2
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    TableDef tabDef;
    for (int i=0;i<100;i++)
    {
	tabDef.addField("f1", typeInt);
	tabDef.dropField("f1");
    }
    int fieldcount=tabDef.getFieldCount();
    printf("Number of Fields = %d\n",fieldcount);
    rv=dbMgr->createTable("t1", tabDef);
    if(rv==OK) 
    { 
	printf("Table created without Fields\n"); 
	printf("Test failed\n");
	dbMgr->dropTable("t1");
	return 3;
    }
    
    dbMgr->dropTable("t1"); 
    conn.close();
    return 0;
}
예제 #3
0
파일: Game.cpp 프로젝트: oedead26/ChessPP
void Game::saveToDatabase() const
{
    time_t now = time(0);
    struct tm tstruct;
    char buff[80];
    localtime_s(&tstruct, &now);

    strftime(buff, sizeof(buff), "%Y-%m-%d", &tstruct);
    string strDate = buff;

    strftime(buff, sizeof(buff), "%X", &tstruct);
    string strTime = buff;

    string strMovesString;
    string strPromotionsString;
    for (Move m : vecPreviousMoves)
    {
        if (m.isPawnPromotionMove())
        {
            strPromotionsString += m.getInitialSquare().getPieceAtSquare()->getAbbreviation();
        }
        strMovesString += to_string(m.getInitialSquare().getRow());
        strMovesString += to_string(m.getInitialSquare().getCol());
        strMovesString += to_string(m.getFinalSquare().getRow());
        strMovesString += to_string(m.getFinalSquare().getCol());
    }

    DatabaseManager dbManager;
    dbManager.connectToDatabase();
    dbManager.addGame(strDate, strTime, ptrWhitePlayer->getName(), ptrBlackPlayer->getName(), strMovesString, strPromotionsString);
    dbManager.disconnectFromDatabase();
}
예제 #4
0
/**
 * @brief Slot triggered when `Ok` is clicked
 * Updates the person or tell the MovieDialog that it's done
 */
void PeopleDialog::on_validationButtons_accepted()
{
    Macaw::DEBUG("[PeopleDialog] validationButtons accepted");
    m_people.setName(getName());
    m_people.setBirthday(getBirthday());
    m_people.setBiography(getBiography());

    // If type != 0, it means we come from the movie dialog
    // If type = 0, it means we directly edit a people
    if (m_people.type() != 0)
    {
        Macaw::DEBUG("[PeopleDialog] validationButtons method: type="
                     +QString::number(m_people.type()));
        emit(peopleCreated(m_people));
    }
    else
    {
        Macaw::DEBUG("[PeopleDialog] validationButtons method: type=0");
        DatabaseManager *databaseManager = ServicesManager::instance()->databaseManager();

        databaseManager->updatePeople(m_people);
    }

    Macaw::DEBUG("[PeopleDialog] validationButtons method done");
}
예제 #5
0
/**
 * @brief Set the ElementIdsList, used to fill the listWidget
 */
void LeftPannel::setElementIdsList()
{
    Macaw::DEBUG_IN("[LeftPannel] Enters setElementIdsList()");

    m_elementIdsList.clear();

    ServicesManager *servicesManager = ServicesManager::instance();
    DatabaseManager *databaseManager = servicesManager->databaseManager();

    QList<Movie> l_matchingMoviesList = servicesManager->matchingMoviesList();

    foreach(Movie l_movie, l_matchingMoviesList) {
        if( (servicesManager->toWatchState()
                 && databaseManager->isMovieInPlaylist(l_movie.id(), Playlist::ToWatch)
                 ) || !servicesManager->toWatchState()
               ) {
            switch (m_typeElement)
            {
                case Macaw::isPeople:
                {
                    QList<People> l_peopleList = l_movie.peopleList(m_typePeople);
                    this->updateElementIdsList(l_peopleList);
                    break;
                }
                case Macaw::isTag:
                {
                    QList<Tag> l_tagList = l_movie.tagList();
                    this->updateElementIdsList(l_tagList);
                    break;
                }
            }
        }
    }
    Macaw::DEBUG_OUT("[LefPannel] Exits setElementIdsList()");
}
예제 #6
0
int main (int argc, char **argv)
{
  Connection conn;
  DbRetVal rv = conn.open("root","manager");
  printf ("Main open Returned %d\n", rv);
  pthread_t thread1, thread2;
  int message1 =1; 
  int message2 =2; 
  int status;

  pthread_create (&thread1, NULL,
		  &print_message_function, (void *) &message1);
  pthread_create (&thread2, NULL,
		  &print_message_function, (void *) &message2);

  pthread_join(thread1, (void **)&status);
  pthread_join(thread2, (void **)&status);


  DatabaseManager *dbMgr = conn.getDatabaseManager();
  if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
  dbMgr->dropTable("T1");
  dbMgr->dropTable("T2");

  rv = conn.close();
  printf ("Main Returned %d\n", rv);
  exit (0);
}
예제 #7
0
void* print_message_function(void *ptr)
{
    //if (flag == 0) {flag =1; sleep(2); }
    char tblname[20];
    sprintf(tblname, "T%d", *(int*)ptr );
    Connection conn;
    DbRetVal rv=conn.open("root","manager");
    printf("Thread Return value of open %d %d\n", rv, getpid());
    if(rv!=OK)
    {
      return NULL;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}


    TableDef tabDef;
    tabDef.addField("f1", typeInt);
    tabDef.addField("f2", typeInt);
    rv = dbMgr->createTable(tblname, tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return NULL; }
    printf("Table created\n");

    rv = conn.close();
    printf("Thread Return value of close %d %d\n", rv, getpid());
}
예제 #8
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) { printf("Error during connection %d\n", rv); return 1; }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    int ret = createTable(dbMgr);
    if (ret != 0) { return 1; }

    pthread_t thr[2];
    int *status1, *status2;
    pthread_create (&thr[0], NULL, &runTest1,  NULL);
    pthread_create (&thr[1], NULL, &runTest2,  NULL);
    printf("All threads started\n");

    pthread_join(thr[0], (void**)&status1);
    pthread_join(thr[1], (void**)&status2);
    ret = 0;
    if (*status1 != 0 || *status2 != 0) ret = 1;
    if (p1RetVal) { delete p1RetVal; p1RetVal = NULL; }
    if (p2RetVal) { delete p2RetVal; p2RetVal = NULL; }
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
예제 #9
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root","manager");
    if(rv!=OK)return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if(dbMgr == NULL)
    {
       printf("Auth failed\n");
       return 2;
    }

    TableDef tabDef;
    tabDef.addField("f1",typeInt,0,NULL,true);
    tabDef.addField("f2",typeInt);
    
    rv = dbMgr->createTable("t1",tabDef);
    if(rv!=OK)
    {
      printf("Table created failed\n");
      conn.close();
      return 0;
    }

    
    Table *table = dbMgr->openTable("t1");
    long spaceused;
    spaceused = table->spaceUsed();
    printf("Total space used=%ld\n",spaceused);

   dbMgr->closeTable(table);
   dbMgr->dropTable("t1");
   conn.close();
   return 0;
}  	
예제 #10
0
//creating index with non existing field
//It should fail
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("notexist");
    idxInfo->indType = hashIndex;
#ifdef TREEINDEX
    idxInfo->indType = treeIndex;
#elif defined TRIEINDEX
    idxInfo->indType = trieIndex;
#endif
    int ret =0;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv == OK) ret =1;
    delete idxInfo;
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
예제 #11
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
    int inscount =  insertTuple(dbMgr, conn);
    //check the inscount and return error

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        return 0;
    }


    Condition p1,p2,p3,p4,p5;
    int val1 = 2, val2 = 3, val3 = 4;
    p1.setTerm("f1", OpEquals, &val3);
    p2.setTerm("f2", OpGreaterThan, &val2);
    p3.setTerm("f2", OpEquals, &val3);
    p4.setTerm("f1", OpLessThan, &val1);
    p5.setTerm("f1", OpGreaterThan, &val1);


    Condition cond1, cond1a;
    cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
    cond1a.setTerm(cond1.getPredicate(), OpOr, p4.getPredicate());
    table->setCondition(&cond1a);
    printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond2, cond2a;
    cond2.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
    cond2a.setTerm(cond1.getPredicate(), OpOr, cond2.getPredicate());
    table->setCondition(&cond2a);
    printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2 AND f2 > 4) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
예제 #12
0
파일: Game.cpp 프로젝트: oedead26/ChessPP
Game::Game(int intGameID)
{
    DatabaseManager dbManager;
    dbManager.connectToDatabase();
    vector<string> vecGame = dbManager.getGame(intGameID);
    dbManager.disconnectFromDatabase();

    ptrWhitePlayer = new Player(vecGame.at(3), WHITE);
    ptrBlackPlayer = new Player(vecGame.at(4), BLACK);

    int intPromotionsStringIndex = 0;
    for (unsigned int i = 0; i < vecGame.at(5).size(); i += 4)
    {
        int intInitialRow = static_cast<int>(vecGame.at(5).at(i) - '0');
        int intInitialCol = static_cast<int>(vecGame.at(5).at(i + 1) - '0');
        int intFinalRow = static_cast<int>(vecGame.at(5).at(i + 2) - '0');
        int intFinalCol = static_cast<int>(vecGame.at(5).at(i + 3) - '0');
        Move aMove(currentBoard.getSquare(intInitialRow, intInitialCol), currentBoard.getSquare(intFinalRow, intFinalCol));

        if (currentBoard.getPieceAt(intInitialRow, intInitialCol)->getType() == PAWN && (intFinalRow == 0 || intFinalRow == 7))
        {
            aMove.setIsPawnPromotionMove(true);
        }
        makeMove(aMove);
        generatePGNString();

        if (aMove.isPawnPromotionMove())
        {
            char charPromotionAbbreviation = vecGame.at(6).at(intPromotionsStringIndex);
            PieceType promotionType;
            if (toupper(charPromotionAbbreviation) == 'N')
            {
                promotionType = KNIGHT;
            }
            else if (toupper(charPromotionAbbreviation) == 'B')
            {
                promotionType = BISHOP;
            }
            else if (toupper(charPromotionAbbreviation) == 'R')
            {
                promotionType = ROOK;
            }
            else
            {
                promotionType = QUEEN;
            }
            promotePawn(intFinalRow, intFinalCol, promotionType);
            intPromotionsStringIndex++;
        }
    }
}
예제 #13
0
bool StopsQueryModel::move(int from, int to) {
    qDebug() << "Moving index" << from << "to" << to;
    if (from == to) return true; //no move is required
    bool ok = databaseManager->move(record(from).value("code").toString(), record(to).value("code").toString());
    query().exec();
    return ok;
}
예제 #14
0
/**
 * @brief fill the listWidget based on m_elementIdsList
 * @author Olivier CHURLAUD <*****@*****.**>
 */
void LeftPannel::fillListWidget()
{
    Macaw::DEBUG_IN("[LeftPannel] Enters fillListWidget()");

    m_ui->listWidget->clear();

    DatabaseManager *databaseManager = ServicesManager::instance()->databaseManager();

    // Add the "All" element
    if(m_typeElement != Macaw::isPlaylist) {
        // First space needed for sorting
        Entity l_entity(" All");
        l_entity.setId(0);

        this->addEntityToListWidget(l_entity);
    }

    foreach(int l_objectId, m_elementIdsList) {
        if(l_objectId == -1) {
            // First space needed for sorting
            Entity l_entity(" Unknown");
            l_entity.setId(-1);

            this->addEntityToListWidget(l_entity);
        } else {
            Entity l_entity;
            switch (m_typeElement)
            {
            case Macaw::isPeople:
                l_entity = databaseManager->getOnePeopleById(l_objectId);
                break;
            case Macaw::isTag:
                l_entity = databaseManager->getOneTagById(l_objectId);
                break;
            }

            this->addEntityToListWidget(l_entity);
        }
    }
    if(m_ui->listWidget->selectedItems().isEmpty()) {
        m_ui->listWidget->item(0)->setSelected(true);
    }
    m_ui->listWidget->sortItems();

    Macaw::DEBUG_OUT("[LeftPannel] Exits fillListWidget()");
}
예제 #15
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
    if ( createIndex(dbMgr, false) != 0 ) { dbMgr->dropTable("t1");conn.close(); return 4;
 }
    int inscount =  insertTupleWithSameValue(dbMgr, conn);
    if (inscount != 10 ) { dbMgr->dropTable("t1"); conn.close(); return 5; }
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
예제 #16
0
//public slots:
//clears the database from stops from stopstable that are not set as favorite
//this does//will not affect underground stations
void StopsQueryModel::clearStops() {
    if (databaseManager) {
        bool ok = databaseManager->clearStopsTable();
        if (!ok) {
            qDebug() << "clearing stopstable failed";
        }
        else qDebug() << "cleared stopstable";
        showStops(Stop::Bus);
    }
}
예제 #17
0
DbFieldWidget::DbFieldWidget(DatabaseDialog *parent):
    StepWidget(parent),
    ui(new Ui::DbFieldWidget())
{
    ui->setupUi(this);

    connect(this, SIGNAL(signalAddColumns(QStringList)), this, SLOT(slotAddColumns(QStringList)));

    dialog->setButtonState(DatabaseDialog::BUTTON_BACK, true);
    dialog->setButtonState(DatabaseDialog::BUTTON_NEXT, false);
    dialog->setButtonState(DatabaseDialog::BUTTON_FINISH, false);

    DatabaseManager *dm = MatchMaker::instance->dbManager;

    dm->queryConnection(CONNECTION, dialog->db->getColumnQuery(dialog->dbSetup.getTable()),
    [this](QSqlQuery *query){
        //emit signalProcessQuery(query);
        processQuery(query);
    });
}
예제 #18
0
void BrowserWindowMobile::setupDeclarativeEnvironment()
{
    QQmlContext* context = rootContext();
    context->setContextProperty("BrowserWindow", this);

    DatabaseManager* dbManager = DatabaseManager::instance();
    context->setContextProperty("HistoryModel", dbManager->historyDataBaseModel());
    context->setContextProperty("BookmarkModel", dbManager->bookmarkDataBaseModel());
    context->setContextProperty("TabsModel", new TabsModel(this));
    context->setContextProperty("UrlTools", new UrlTools(this));

    QObject::connect(engine(), SIGNAL(quit()), qApp, SLOT(quit()));

    setResizeMode(QQuickView::SizeRootObjectToView);
#if defined(SNOWSHOE_MEEGO_HARMATTAN)
    reportContentOrientationChange(Qt::PortraitOrientation);
    setSource(QUrl("qrc:///mobile/qml/main-harmattan.qml"));
#else
    setSource(QUrl("qrc:///mobile/qml/Main.qml"));
#endif
}
예제 #19
0
PeopleDialog::PeopleDialog(int id, QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::PeopleDialog)
{
    Macaw::DEBUG("[PeopleDialog] Constructor called");

    DatabaseManager *databaseManager = ServicesManager::instance()->databaseManager();

    m_ui->setupUi(this);
    this->setWindowTitle(tr("Edit People Metadata"));
    this->setAttribute(Qt::WA_DeleteOnClose);

    // If id is 0 it means we create a new People
    if (id != 0)
    {
        m_people = databaseManager->getOnePeopleById(id);
        setName(m_people.name());
        setBirthday(m_people.birthday());
        setBiography(m_people.biography());
    }
    Macaw::DEBUG("[PeopleDialog] Construction done");
}
예제 #20
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    TableDef tabDef;

    tabDef.addField("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklabc", typeInt, 0, NULL, true);
    rv=dbMgr->createTable("t1", tabDef);
    if(rv==OK) 
    { 
	printf("Allowing fieldname more than 64 character\n");
	printf("Test Failed\n");
	dbMgr->dropTable("t1");
	return 3;
    }
    printf("Test Passed\n");
    conn.close();
    return 0;
}
예제 #21
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 1016);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    char name[20] = "PRAVEEN";
    table->bindFld("f1", &id1);
    table->bindFld("f2", &id2);
    table->bindFld("f3", name);
    int icount =0;
    for (int i = 0 ; i < 1000 ; i++)
    {
        conn.startTransaction();
        for (int j = 0 ; j < 100 ; j++) {
            id1= icount++;
            rv = table->insertTuple();
            if (rv != OK) break;
        }
        conn.commit();
    }
    printf("Tuples inserted %d\n", icount);
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    if (rv == ErrNoMemory)
    {
       //insert is expected to fail
       printf("insert failed with return values %d\n", rv);
       return 0;
    } 
    return 1;
}
예제 #22
0
//bind non exisiting field
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 20);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    int ret =0;
    char name[20] = "PRAVEEN";
    rv = table->bindFld("f1", &id1);
    if (rv != OK) ret = 1;
    rv  = table->bindFld("f5", &id2);
    if (rv == OK) ret = 1;
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return ret;
}
예제 #23
0
void* runDelTest(void *message)
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return NULL;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return NULL; }
    int id = 0;
    char name[20] = "PRABAKARAN";
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int i;
    int ret;
    int retrycnt=0;
    int icount =0;
    int val = *(int*)message;

    Condition p1;
    int valTerm = 0;
    p1.setTerm("f1", OpEquals, &valTerm);
    table->setCondition(&p1);

    for(i = val * ITERATION; i< (val *ITERATION) +ITERATION; i++)
    {
        rv = conn.startTransaction();
        if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
        id= i;
        valTerm = i;
        rv = table->execute();
        if (rv != OK) {
            printf("Execute returned %d\n", rv);
            os::usleep(500);
            int retry=5;
            while (rv == ErrLockTimeOut) {
                if (retry == 0) { printf("DELETE:execute failed\n"); break;}
                printf("retrying execute\n");
                rv = table->execute();
                retry--;
            }
        }
        tuple = (char*)table->fetch() ;
        if (tuple == NULL)  { printf("DELETE:fetch failed\n");break;}
        ret = table->deleteTuple();
        retrycnt=0;
        while (ret == ErrLockTimeOut)
        {
           table->closeScan();
            rv = conn.rollback();
            if (rv != OK)  {
                while (rv == ErrLockTimeOut)
                {
                    printf("retrying abort\n");
                    rv = conn.rollback();
                }
            }
            if (retrycnt == 10) { ret = 1; break;}
            rv = conn.startTransaction();
            if (rv != OK) {
                while (rv == ErrLockTimeOut)
                {
                    printf("retrying startTransaction\n");
                    rv = conn.startTransaction();
                }
            }
            rv = table->execute();
            if (rv != OK) {
                printf("Execute returned %d\n", rv);
                os::usleep(500);
                int retry=5;
                while (rv == ErrLockTimeOut) {
                   if (retry == 0) { printf("DELETE:execute failed\n"); break;}
                   printf("retrying execute\n");
                   rv = table->execute();
                   retry--;
                }
            }
            tuple = (char*)table->fetch() ;
            if (tuple == NULL)  { printf("DELETE:fetch failed\n");break;}
            ret = table->deleteTuple();
            retrycnt++;
        }
        if (ret != 0) { printf("RETURNING EARLY: %d with i:%d\n", ret, i); break;}
        table->closeScan();
        rv = conn.commit();
        if (rv != OK) {
            printf("COMMIT returned %d for record %d\n", rv, i);
            if (rv != ErrLockTimeOut)
            {
                printf("RETURNING EARLY: with i:%d\n", i);
                break;
            }

            os::usleep(500);
            while (rv == ErrLockTimeOut) {
                printf("retrying commit\n");
                rv = conn.commit();
            }
        }
        icount++;
    }
   char msgBuf[1024];
   sprintf(msgBuf,"Delete: Thread %lu %d: Total rows :%d\n",os::getthrid(), val, icount);
   os::write(1,msgBuf,strlen(msgBuf));
   dbMgr->closeTable(table);
   rv  = conn.close();
   return NULL;
}
예제 #24
0
void* runSelTest(void *message)
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return NULL;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return NULL; }
    int id = 0;
    char name[1020] = "PRABAKARAN";
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int i;
    int icount =0;
    int val = *(int*)message;

    Condition p1;
    int valTerm = 0;
    p1.setTerm("f1", OpEquals, &valTerm);
    table->setCondition(&p1);

    for(i = val * ITERATION; i< (val *ITERATION) +ITERATION; i++)
    {
        rv = conn.startTransaction();
        if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
        valTerm = i;
        if (valTerm ==0) valTerm=1;
        rv = table->execute();
        if (rv != OK) {
            printf("Execute returned %d\n", rv);
            os::usleep(500);
            int retry=5;
            while (rv == ErrLockTimeOut) { 
                if (retry == 0) break;
                printf("retrying execute\n");
                rv = table->execute();
                retry--;
            }
        }
        tuple = (char*)table->fetch() ;
        if (tuple == NULL)  break;
        icount++;
        table->closeScan();
        rv = conn.commit();
        if (rv != OK) {
            while (rv == ErrLockTimeOut) { 
                printf("retrying commit\n");
                rv = conn.commit();
            }
        }
    }

   char msgBuf[1024];
   sprintf(msgBuf,"Select: Thread %lu %d: Total rows :%d\n",os::getthrid(), val, icount);
   os::write(1,msgBuf,strlen(msgBuf));
   dbMgr->closeTable(table);
   rv  = conn.close();
   return NULL;
}
예제 #25
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true, true);
    tabDef.addField("f2", typeString, 12);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->isPrimary = true;
    idxInfo->isUnique = true;
#ifdef HASH
    idxInfo->indType = hashIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
#endif
#ifdef TREE
    idxInfo->indType = treeIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
#endif
    delete idxInfo;
    pthread_t thr[THREADS];
    int message[THREADS];
    int status;
    for (int i=0; i <THREADS; i++) {
        message[i] = i;
        pthread_create (&thr[i], NULL,
                  &runInsTest, (void *) &message[i]);
    }
    for (int i=0; i <THREADS; i++) {
        pthread_join(thr[i], (void**)&status);
    }
    
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    table->setCondition(NULL);
    rv = conn.startTransaction();
    if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
    table->execute();
    int count=0;
    void *tuple = NULL;
    while ((tuple = (char*) table->fetch())) {
         count++;
    }
    printf("Tuples found: %d\n", count);
    table->closeScan();
    conn.commit();

#ifdef HASH
    Condition p1;
    int valTerm = 0;
    p1.setTerm("f1", OpEquals, &valTerm);
    table->setCondition(&p1);
    int icount=0;
    for(int i = 0; i< THREADS * ITERATION; i++)
    {
        rv = conn.startTransaction();
        if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
        valTerm = i+1;
        rv = table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL)  break;
        icount++;
        table->closeScan();
        conn.commit();
        //if (i%ITERATION == 0) printf("%d\n", i);
    }
    printf("Index Tuples found: %d\n", icount);
#endif



    dbMgr->closeTable(table);

    for (int i=0; i <THREADS; i++) {
        message[i] = i;
        pthread_create (&thr[i], NULL,
                  &runSelTest, (void *) &message[i]);
    }
    for (int i=0; i <THREADS; i++) {
        pthread_join(thr[i], (void**)&status);
    }

    dbMgr->dropTable("t1");
    
    conn.close();
    return 0;
}
예제 #26
0
void* runInsTest(void *message)
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return NULL;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return NULL; }
    int id = 0;
    char name[20] = "PRABAKARAN";
    //table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int ret;
    int i;
    int icount =0;
    int val = *(int*)message;
    int retrycnt=0;
    for(i = val * ITERATION; i< (val *ITERATION) +ITERATION; i++)
    {
        rv = conn.startTransaction();
        if (rv != OK) while (rv !=OK) rv = conn.startTransaction();
        id= i;
        strcpy(name, "KARAN123");
        ret = table->insertTuple();
        retrycnt=0;
        while (ret == ErrLockTimeOut)  
        { 
            rv = conn.rollback();
            if (rv != OK)  {
                while (rv == ErrLockTimeOut) 
                {
                    printf("retrying abort\n");
                    rv = conn.rollback();
                }
            }
            if (retrycnt == 3) { ret = 1; break;}
            rv = conn.startTransaction();
            if (rv != OK) {
                while (rv == ErrLockTimeOut) 
                {
                    printf("retrying startTransaction\n");
                    rv = conn.startTransaction();
                }
            }
            ret = table->insertTuple(); 
            retrycnt++;
            //ret =1; break; //temp to analyse issue
        }
        if (ret != 0) { printf("RETURNING EARLY: %d with i:%d\n", ret, i); break;}
        icount++;
        rv = conn.commit();
        if (rv != OK) {
            printf("COMMIT returned %d\n", rv);
            os::usleep(500);
            while (rv == ErrLockTimeOut) { 
                printf("retrying commit\n");
                rv = conn.commit();
            }
        }
        //if (icount %ITERATION ==0) printf("%d\n", i);
    }
   char msgBuf[1024];
   sprintf(msgBuf,"Insert: Thread %lu %d: Total rows :%d\n",os::getthrid(), val, icount);
   os::write(1,msgBuf,strlen(msgBuf));
   dbMgr->closeTable(table); 
   rv  = conn.close();
   return NULL;
}
예제 #27
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return 1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
    TableDef tabDef;
    tabDef.addField("f1", typeLongLong, 0, NULL, true);
    tabDef.addField("f2", typeString, 196);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return 3; }
    printf("Table created\n");
#ifdef WITHINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
    idxInfo->isUnique = true;
    idxInfo->isPrimary = true;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif
#ifdef WITHTREEINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = treeIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif
#ifdef WITHTRIEINDEX
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = trieIndex;
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created\n");
    delete idxInfo;
#endif


    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return 4; }
    table->bindFld("f1", &id);
    table->bindFld("f2", name);
    char *tuple;
    int ret;
    long long i;
    rv =conn.startTransaction();
    for(i = 0; i< 5; i++)
    {
        if (rv != OK) exit(5);
        id= i;
        strcpy(name, "PRABAKARAN0123456750590");
        ret = table->insertTuple();
        if (ret != 0) break;
    }
    conn.commit();

    conn.startTransaction();
    select(table, OpEquals);
    conn.commit();

    conn.startTransaction();
    select(table, OpNotEquals);
    conn.commit();

    conn.startTransaction();
    select(table, OpLessThan);
    conn.commit();

    conn.startTransaction();
    select( table, OpLessThanEquals);
    conn.commit();

    conn.startTransaction();
    select( table, OpGreaterThan);
    conn.commit();

    conn.startTransaction();
    select( table, OpGreaterThanEquals);
    conn.commit();

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");

    conn.close();
    return 0;
}
예제 #28
0
파일: dbfull1.c 프로젝트: mattibickel/csql
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
   
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeInt);
    tabDef.addField("f3", typeString, 2000);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
    printf("Table created\n");

    Table *table = dbMgr->openTable("t1");
    if (table == NULL) 
    { 
        printf("Unable to open table\n"); 
        dbMgr->dropTable("t1");
        conn.close();
        return -1; 
    }
    int id1 = 0, id2 = 5;
    char name[20] = "PRAVEEN";
    table->bindFld("f1", &id1);
    table->bindFld("f2", &id2);
    table->bindFld("f3", name);
    int i=0;
    for (i = 0 ; i < 4000; i++)
    {
        conn.startTransaction();
        id1= i;
        rv = table->insertTuple();
        if (rv != OK) break;
        conn.commit();
    }
    printf("%d records inserted\n", i);
    for (int k=0; k <100; k++) {
      table->setCondition(NULL);
      rv = table->execute();
      if (rv != OK) {
        printf("table execute failed rv:%d\n", rv);
        dbMgr->closeTable(table);
        conn.close();
        return 1;
      }
      void *tuple = NULL;
      for (i = 0 ; i < 1000 ; i++)
      {
        conn.startTransaction();
        tuple = table->fetchNoBind();
        if (tuple == NULL) { printf("No more records\n"); break; }
        rv = table->deleteTuple();
        if (rv != OK) { printf("Delete tuple failed\n"); break;}
        conn.commit();
      }
      table->closeScan();
      printf("Iteration:%d \n %d records deleted\n", k, i);
      i=0;
      for (i = 0 ; i < 1000 ; i++)
      {
        conn.startTransaction();
        id1= i;
        rv = table->insertTuple();
        if (rv != OK) break;
        conn.commit();
      }
      printf("%d records inserted\n", i);
    }

    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;
}
예제 #29
0
int main()
{
    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK) return 1;
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}

    if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; }
#ifdef WITHF1INDEX
    if (createIndex(dbMgr, "f1", "idx1") != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif
#ifdef WITHF1TREEINDEX
    if (createIndex(dbMgr, "f1", "idx1", true) != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif

#ifdef WITHF2INDEX
    if (createIndex(dbMgr, "f2", "idx2") != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif
#ifdef WITHF2TREEINDEX
    if (createIndex(dbMgr, "f2", "idx2", true) != 0) {dbMgr->dropTable("t1");
                                        conn.close();
                                        return 4;
                                       }
#endif

    int inscount =  insertTuple(dbMgr, conn);
    //check the inscount and return error

    Table *table = dbMgr->openTable("t1");
    if (table == NULL)
    {
        printf("Unable to open table\n");
        return 0;
    }


    Condition p1,p2,p3,p4,p5;
    int val1 = 2, val2 = 3, val3 = 4;
    p1.setTerm("f1", OpEquals, &val3);
    p2.setTerm("f2", OpGreaterThan, &val2);
    p3.setTerm("f2", OpEquals, &val3);
    p4.setTerm("f1", OpLessThan, &val3);
    p5.setTerm("f1", OpGreaterThan, &val1);


    Condition cond1, cond1a;
    cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate());
    cond1a.setTerm(cond1.getPredicate(), OpNot);
    table->setCondition(&cond1a);
    printf("Predicate: NOT(f1 ==4 AND f2 >3) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond2, cond2a;
    cond2.setTerm(p1.getPredicate(), OpAnd, p3.getPredicate());
    cond2a.setTerm(cond2.getPredicate(), OpNot);
    table->setCondition(&cond2a);
    printf("Predicate: NOT( f1 ==4 AND f2 ==4) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond3, cond3a;
    cond3.setTerm(p4.getPredicate(), OpAnd, p5.getPredicate());
    cond3a.setTerm(cond3.getPredicate(), OpNot);
    table->setCondition(&cond3a);
    printf("Predicate: NOT( f1 <4 AND f1 >2) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();


    Condition cond4, cond4a;
    cond4.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate());
    cond4a.setTerm(cond4.getPredicate(), OpNot);
    table->setCondition(&cond4a);
    printf("Predicate: NOT( f1 <4 AND f2 >3) \n");
    conn.startTransaction();
    execAndPrint(table);
    conn.commit();

    Condition cond5, cond5a;
    cond5.setTerm(p2.getPredicate(), OpNot);
    cond5a.setTerm(p4.getPredicate(), OpAnd, cond5.getPredicate());
    table->setCondition(&cond5a);
    printf("Predicate: ( f1 <4 AND (NOT(f2 >3)) \n");
    conn.startTransaction();
    execAndPrint(table);

    conn.commit();
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");
    conn.close();
    return 0;

}
예제 #30
0
int main()
{

    Connection conn;
    DbRetVal rv = conn.open("root", "manager");
    if (rv != OK)
    {
       printf("Error during connection %d\n", rv);
       return -1;
    }
    DatabaseManager *dbMgr = conn.getDatabaseManager();
    if (dbMgr == NULL) { printf("Auth failed\n"); return -1;}
    TableDef tabDef;
    tabDef.addField("f1", typeInt, 0, NULL, true);
    tabDef.addField("f2", typeString, 50);
    rv = dbMgr->createTable("t1", tabDef);
    if (rv != OK) { printf("Table creation failed\n"); return -1; }
    printf("Table created\n");
    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
    strcpy(idxInfo->tableName, "t1");
    idxInfo->list.append("f1");
    idxInfo->indType = hashIndex;
#ifdef F1TREE
    idxInfo->indType = treeIndex;
#endif
#ifdef F2TRIE
    idxInfo->indType = trieIndex;
#endif
    rv = dbMgr->createIndex("indx1", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created for f1\n");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->list.remove("f1");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->list.append("f2");
    printf("size of index field list %d\n", idxInfo->list.size());
    idxInfo->indType = hashIndex;
#ifdef F2TREE
    idxInfo->indType = treeIndex;
#endif
#ifdef F2TRIE
    idxInfo->indType = trieIndex;
#endif
    rv = dbMgr->createIndex("indx2", idxInfo);
    if (rv != OK) { printf("Index creation failed\n"); return -1; }
    printf("Index created for f2\n");
    delete idxInfo;
    Table *table = dbMgr->openTable("t1");
    if (table == NULL) { printf("Unable to open table\n"); return -1; }
    int id1 = 0;
    char id2[50] ="Aruna";
    table->bindFld("f1", &id1);
    table->bindFld("f2", id2);
    char *tuple;
    int ret;
    int i;
    int icount =0;
    rv = conn.startTransaction();
    if (rv != OK) exit(1);
    for(i = 0; i< 10; i++)
    {
        id1= i;
        sprintf(id2, "Aruna:%d", i);
        ret = table->insertTuple();
        if (ret != 0) break;
        icount++;
    }
    conn.commit();
    printf("Total tuples inserted: %d\n", icount);
    Condition p1, p2;
    int val1 = 0;
    char val2[50];
    p1.setTerm("f1", OpEquals, &val1);
    p2.setTerm("f2", OpEquals, &val2);
    table->setCondition(&p1);
    rv =conn.startTransaction();
    if (rv != OK) exit(1);
    for(i = 0; i< 10; i++)
    {    
        val1 = i;
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        printf("I:tuple value is %d %s \n", id1, id2);
        table->closeScan();
    }

    table->setCondition(&p2);
    for(i = 0; i< 10; i++)
    {    
        sprintf(val2, "Aruna:%d", i);
        table->execute();
        tuple = (char*)table->fetch() ;
        if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
        printf("II:tuple value is %d %s \n", id1, id2);
        table->closeScan();
    }
    conn.commit();

    rv =conn.startTransaction();
    if (rv != OK) exit(1);
    table->setCondition(&p1);
    val1 = 1;
    table->execute();
    tuple = (char*)table->fetch() ;
    if (tuple != NULL) {
        table->deleteTuple();
    }
    table->closeScan();
    table->setCondition(&p2);
    sprintf(val2, "Aruna:%d", 2);
    table->execute();
    tuple = (char*)table->fetch() ;
    if (tuple != NULL) {
        table->deleteTuple();
    }
    table->closeScan();
    conn.commit();

    int count =0;
    rv = conn.startTransaction();
    table->setCondition(NULL);
    if (rv != OK) exit (1);
    table->execute();
    while((tuple = (char*)table->fetch())!= NULL) {
        printf("tuple value is %d %s \n", id1, id2);
        count++;
    }
    table->closeScan();
    conn.commit();
    printf("Total rows selected %d\n", count);
    dbMgr->closeTable(table);
    dbMgr->dropTable("t1");

    conn.close();
    return 0;
}