void TalkManager::clear() { for (Tables::iterator t = _tablesMain.begin(); t != _tablesMain.end(); ++t) deleteTable(*t); for (Tables::iterator t = _tablesAlt.begin(); t != _tablesAlt.end(); ++t) deleteTable(*t); _tablesMain.clear(); _tablesAlt.clear(); }
void database::redoTable() { deleteTable(); deleteReactionsTable(); createTable(); createReactionsTable(); }
// ************************************************************ void testCreateTableAndInsert (void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2} }; int numInserts = 9, i; Record *r; RID *rids; Schema *schema; testName = "test creating a new table and inserting tuples"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); //printf("\n Testing create table"); TEST_CHECK(createTable("test_table_r.txt",schema)); //printf("\n Testing open Table"); TEST_CHECK(openTable(table, "test_table_r.txt")); printf("\n Opened "); // insert rows into table for(i = 0; i < numInserts; i++) { printf("\n Inserting"); r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r.txt")); printf("\n Opened successsfully"); // randomly retrieve records from the table and compare to inserted ones for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid = rids[pos]; printf("\n getting records"); TEST_CHECK(getRecord(table, rid, r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[pos]), r, schema, "compare records"); } TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r.txt")); TEST_CHECK(shutdownRecordManager()); free(rids); free(table); TEST_DONE(); }
/* * Called after class unloads have occurred. Creates a new hash table * of currently loaded prepared classes. * The signatures of classes which were unloaded (not present in the * new table) are returned. */ struct bag * classTrack_processUnloads(JNIEnv *env) { KlassNode **newTable = jdwpClearedAlloc(HASH_SLOT_COUNT * sizeof(KlassNode *)); jint classCount; jclass *classes; jint i; struct bag *unloadedSignatures; if (newTable == NULL) { ALLOC_ERROR_EXIT(); } if ((classes = allLoadedClasses(&classCount)) == NULL) { jdwpFree(newTable); ALLOC_ERROR_EXIT(); } /* Transfer each current class into the new table */ for (i=0; i<classCount; i++) { jclass klass = classes[i]; transferClass(env, klass, newTable); (*env)->DeleteGlobalRef(env, klass); } jdwpFree(classes); /* Delete old table, install new one */ unloadedSignatures = deleteTable(env, table); table = newTable; return unloadedSignatures; }
void interactive() { HashTable* ht = makeTable(22); for (unsigned i = 0; i < 27; ++i) { ht = insertTable(ht, namen[i], rand() % 100); } printHashTable(ht); while (1) { unsigned i; printf( "Insert (2) or search (1) or delete (0)? " ); scanf( "%u", &i ); if (i == 2) { printf( "Name: " ); char* name = getline(); unsigned telNr; printf( "Telephone-Nr.: " ); scanf("%u", &telNr); ht = insertTable(ht, name, telNr); printHashTable(ht); } else if (i == 1) { printf( "Name: " ); char* name = getline(); unsigned* telNr = searchTable(ht, name); printf( "Telephone-Nr.: %u\n", *telNr ); } else { printf( "Name: " ); char* name = getline(); deleteTable(ht, name); printHashTable(ht); } } }
RC testTombstone(void) { RM_TableData *table = (RM_TableData *)malloc(sizeof(RM_TableData)); TestRecord inserts[] = { { 1, "aaaa", 3 }, { 2, "bbbb", 2 }, { 3, "cccc", 1 }, { 4, "dddd", 3 }, { 5, "eeee", 5 }, { 6, "ffff", 1 }, { 7, "gggg", 3 }, { 8, "hhhh", 3 }, { 9, "iiii", 2 }, { 10, "jjjj", 5 }, }; int numInserts = 10, numUpdates = 3, numDeletes = 5, numFinal = 5, i; Record *r; RID *rids; Schema *schema; testName = "test creating a new table and insert,update,delete tuples"; schema = testSchema(); rids = (RID *)malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_r", schema)); TEST_CHECK(openTable(table, "test_table_r")); // insert rows into table for (i = 0; i < numInserts; i++) { r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table, r)); rids[i] = r->id; } TEST_CHECK(deleteRecord(table, rids[9])); RID id; id.page = rids[9].page; id.slot = rids[10].slot; int isTombstone = checkIfTombstoneEncountered(table, rids[9]); TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r")); TEST_CHECK(shutdownRecordManager()); free(table); if (isTombstone == 1) { return RC_OK; } else { return RC_NOT_A_TOMBSTONE; } }
int main(int argc, char* argv[]){ int i; //Checking command-line arguments if(argc > 3){ printf("%s\n", USAGE); return 1; }else if(argc < 2){ fin = stdin; }else if(argc == 2){ if(strcmp(argv[1], "-q") == 0){ verbose = 0; fin = stdin; }else{ fin = fopen(argv[1], "r"); if(!fin){ printf("%s\n", USAGE); return 1; } } }else if(argc == 2){ if(strcmp("-q", argv[1]) != 0){ printf("%s\n", USAGE); return 1; } verbose = 0; fin = fopen(argv[2], "r"); } //Initializing the symbol table symTable = newTable(); //Initializing the disjoint set for scopes for(i = 0; i < MAX_CODE_LENGTH; i++) scopeParent[i] = 0; //Fetching the first token readToken(); //Parsing the program program(); //Generating code printCode(); //END: deleteTable(symTable); return 0; }
void deleteTableManager(TableManager *tm) { if(tm->deleter != NULL) { while(tm->deleter->length > 0) { DeletionHandler *dh = (DeletionHandler *) getArrayListObject(tm->deleter, tm->deleter->length - 1); removeArrayListObjectFromPosition(tm->deleter, tm->deleter->length - 1); deleteDeletionHandler(dh); } deleteArrayList(tm->deleter); } if(tm->select != NULL) { while(tm->select->length > 0) { SelectionHandler *sh = (SelectionHandler *) getArrayListObject(tm->select, tm->select->length - 1); removeArrayListObjectFromPosition(tm->select, tm->select->length - 1); deleteSelectionHandler(sh); } deleteArrayList(tm->select); } if(tm->insert != NULL) { while(tm->insert->length > 0) { InsertionHandler *ih = (InsertionHandler *) getArrayListObject(tm->insert, tm->insert->length - 1); removeArrayListObjectFromPosition(tm->insert, tm->insert->length - 1); deleteInsertionHandler(ih); } deleteArrayList(tm->insert); } if(tm->tables != NULL) { while(tm->tables->length > 0) { Table *t = (Table *) getArrayListObject(tm->tables, tm->tables->length - 1); removeArrayListObjectFromPosition(tm->tables, tm->tables->length - 1); deleteTable(t); } deleteArrayList(tm->tables); } if(tm->names != NULL) { while(tm->names->length > 0) { char *name = (char *) getArrayListObject(tm->names, tm->names->length - 1); removeArrayListObjectFromPosition(tm->names, tm->names->length - 1); free(name); } deleteArrayList(tm->names); } if(tm->path != NULL) free(tm->path); if(tm->fileName != NULL) free(tm->fileName); if(tm != NULL) free(tm); }
void mainmenufirst2(int i) { char key; //Detect key UP and DOWN until ENTER is pressed do { key = getch(); //Get the input switch(key) { case 72 : create(--cursor2); //Select upper menu break; case 80 : create(++cursor2); //Select lower menu break; } } while(key!=13); switch(cursor2) { case 1 : createDB(); break; case 2 : createTable("",""); cursor2 = 1; mainmenu(cursor2); break; case 3: deleteDB(); cursor2=7; Sleep(400); create(cursor2); cursor2=1; break; case 4: deleteTable(); create(cursor2); cursor2=1; break; case 5 : cursor2 = 1; mainmenu(cursor2); break; } }
void PropertyView::displayProperties(const IPropertyDescription& desc) { deleteTable(); std::list<PropertyEntry> entries = desc.getEntries(); table = new QTableWidget(entries.size(), 2, this); QStringList headerLabels; headerLabels.append("Value"); headerLabels.append("Hide"); table->setHorizontalHeaderLabels(headerLabels); table->setShowGrid(false); int rowIndex = 0; for (std::list<PropertyEntry>::const_iterator it = entries.begin(); it != entries.end(); ++it, ++rowIndex) { const PropertyEntry& current = *it; table->setVerticalHeaderItem(rowIndex, new QTableWidgetItem(current.getName().c_str())); const std::list<const IWidgetConstructor*>& wCtors = current.getWidgetCtors(); int colIndex = 0; for (std::list<const IWidgetConstructor*>::const_iterator it2 = wCtors.begin(); it2 != wCtors.end(); ++it2, ++colIndex) { const IWidgetConstructor* ctor = *it2; QWidget* widget = ctor->constructWidget(table); if (table->rowHeight(rowIndex) < widget->height()) table->setRowHeight(rowIndex, widget->height()); table->setCellWidget(rowIndex,colIndex,widget); widgetCtors.push_back(std::make_pair(ctor,widget)); } } m_layout->addWidget(table); table->show(); }
void TalkManager::removeTable(Common::ChangeID &changeID) { Change *change = dynamic_cast<Change *>(changeID.getContent()); if (!change) return; Tables *tables = &_tablesMain; if (change->_isAlt) tables = &_tablesAlt; for (Tables::iterator t = tables->begin(); t != tables->end(); ++t) { if (t->id == change->_id) { deleteTable(*t); tables->erase(t); break; } } changeID.clear(); }
/* Complete the query parsing by joining the table results */ void Database::completeQueryParsing(Query_parser* parser) { vector<Table*> tables; vector<string> tableNames = parser->tables; for (int k = 0; k < tableNames.size(); k++) { Table* t = createPartialTable(parser, tableNames[k]); if(debug) { cout<<t->printSelf()<<endl; } if (tableNames.size() > 1) addTable(t, t->getTableName()); tables.push_back(queryParsing(parser, tableNames[k], t)); } Table* newTable = findTable(parser->new_table_name); if (newTable == NULL) { createTable(parser->new_table_name); newTable = findTable(parser->new_table_name); } if(debug) { cout<<"new table is "<<endl; cout<<newTable->printSelf()<<endl; } if (tables.size() == 1) { this->deleteTable(parser->new_table_name); this->addTable(tables[0], parser->new_table_name); } else { combineTables(tables, parser, newTable); } if (tables.size() > 1) { for (int k = 0; k < tables.size(); k++) { deleteTable(tables[k]->getTableName()); } } }
void testUserInterface() { int attrNum=0; int keys[]={}; printf("Enter the number of attributes: \n"); scanf("%d",&attrNum); int attrTypes[attrNum]; int attrSize[attrNum]; DataType dt[attrNum]; char *attrName[attrNum]; int numRec; int j; for(j=0 ; j< attrNum ; j++){ printf("Enter the attribute name for %d attribute :",j+1); attrName[j]=malloc(100); scanf("%s",attrName[j]); printf("Enter the type of attribute for %d attribute \n int : 0 \n string : 1 \n Float : 2 \n Boolean : 3 \n",j+1); scanf("%d",&attrTypes[j]); if(attrTypes[j]==0) dt[j] = DT_INT; else if(attrTypes[j]==1) dt[j] = DT_STRING; else if(attrTypes[j]==2) dt[j] = DT_FLOAT; else if(attrTypes[j]==3) dt[j] = DT_BOOL; if(attrTypes[j]!= 1){ attrSize[j] = 0; }else{ printf("Enter the size of the string attribute \n"); scanf("%d",&attrSize[j]); } } Schema *schema; schema = createSchema(attrNum, attrName, dt, attrSize, 0 ,keys); RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2} }; int numInserts = 9, i; Record *r; RID *rids; testName = "testing user interface"; rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_r",schema)); TEST_CHECK(openTable(table, "test_table_r")); // insert rows into table for(i = 0; i < numInserts; i++) { r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r")); // randomly retrieve records from the table and compare to inserted ones with (int,string,int) format. if(attrNum <= 3) { for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid = rids[pos]; TEST_CHECK(getRecord(table, rid, r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[pos]), r, schema, "compare records"); } } TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r")); TEST_CHECK(shutdownRecordManager()); free(rids); free(table); TEST_DONE(); }
void testScansTwo (void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2}, {10, "jjjj", 5}, }; bool foundScan[] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE }; int numInserts = 10, i; Record *r; RID *rids; Schema *schema; RM_ScanHandle *sc = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle)); Expr *sel, *left, *right, *first, *se; int rc; testName = "test creating a new table and inserting tuples"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_r",schema)); TEST_CHECK(openTable(table, "test_table_r")); // insert rows into table for(i = 0; i < numInserts; i++) { r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r")); // Select 1 record with INT in condition a=2. MAKE_CONS(left, stringToValue("i2")); MAKE_ATTRREF(right, 0); MAKE_BINOP_EXPR(sel, left, right, OP_COMP_EQUAL); createRecord(&r, schema); TEST_CHECK(startScan(table, sc, sel)); while((rc = next(sc, r)) == RC_OK) { ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[1]), r, schema, "compare records"); } if (rc != RC_NO_TUPLES) TEST_CHECK(rc); TEST_CHECK(closeScan(sc)); // Select 1 record with STRING in condition b='ffff'. MAKE_CONS(left, stringToValue("sffff")); MAKE_ATTRREF(right, 1); MAKE_BINOP_EXPR(sel, left, right, OP_COMP_EQUAL); createRecord(&r, schema); TEST_CHECK(startScan(table, sc, sel)); while((rc = next(sc, r)) == RC_OK) { ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[5]), r, schema, "compare records"); serializeRecord(r, schema); } if (rc != RC_NO_TUPLES) TEST_CHECK(rc); TEST_CHECK(closeScan(sc)); // Select all records, with condition being false MAKE_CONS(left, stringToValue("i4")); MAKE_ATTRREF(right, 2); MAKE_BINOP_EXPR(first, right, left, OP_COMP_SMALLER); MAKE_UNOP_EXPR(se, first, OP_BOOL_NOT); TEST_CHECK(startScan(table, sc, se)); while((rc = next(sc, r)) == RC_OK) { serializeRecord(r, schema); for(i = 0; i < numInserts; i++) { if (memcmp(fromTestRecord(schema, inserts[i])->data,r->data,getRecordSize(schema)) == 0) foundScan[i] = TRUE; } } if (rc != RC_NO_TUPLES) TEST_CHECK(rc); TEST_CHECK(closeScan(sc)); ASSERT_TRUE(!foundScan[0], "not greater than four"); ASSERT_TRUE(foundScan[4], "greater than four"); ASSERT_TRUE(foundScan[9], "greater than four"); // clean up TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r")); TEST_CHECK(shutdownRecordManager()); freeRecord(r); free(table); free(sc); freeExpr(sel); TEST_DONE(); }
void testScans (void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2}, {10, "jjjj", 5}, }; TestRecord scanOneResult[] = { {3, "cccc", 1}, {6, "ffff", 1}, }; bool foundScan[] = { FALSE, FALSE }; int numInserts = 10, scanSizeOne = 2, i; Record *r; RID *rids; Schema *schema; RM_ScanHandle *sc = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle)); Expr *sel, *left, *right; int rc; testName = "test creating a new table and inserting tuples"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_r",schema)); TEST_CHECK(openTable(table, "test_table_r")); // insert rows into table for(i = 0; i < numInserts; i++) { r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r")); // run some scans MAKE_CONS(left, stringToValue("i1")); MAKE_ATTRREF(right, 2); MAKE_BINOP_EXPR(sel, left, right, OP_COMP_EQUAL); TEST_CHECK(startScan(table, sc, sel)); while((rc = next(sc, r)) == RC_OK) { for(i = 0; i < scanSizeOne; i++) { if (memcmp(fromTestRecord(schema, scanOneResult[i])->data,r->data,getRecordSize(schema)) == 0) foundScan[i] = TRUE; } } if (rc != RC_NO_TUPLES) TEST_CHECK(rc); TEST_CHECK(closeScan(sc)); for(i = 0; i < scanSizeOne; i++) ASSERT_TRUE(foundScan[i], "check for scan result"); // clean up TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r")); TEST_CHECK(shutdownRecordManager()); free(table); free(sc); freeExpr(sel); TEST_DONE(); }
void testInsertManyRecords(void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2}, {10, "jjjj", 5}, }; TestRecord realInserts[10000]; TestRecord updates[] = { {3333, "iiii", 6} }; int numInserts = 10000, i, numcheck=50; int randomRec = 3333; Record *r; RID *rids; Schema *schema; testName = "test creating a new table and inserting 10000 records then updating record from rids[3333]"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_t",schema)); TEST_CHECK(openTable(table, "test_table_t")); // insert rows into table for(i = 0; i < numInserts; i++) { realInserts[i] = inserts[i%10]; realInserts[i].a = i; r = fromTestRecord(schema, realInserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_t")); // retrieve records from the table and compare to expected final stage for(i = 0; i < numcheck; i++) { RID rid = rids[i]; TEST_CHECK(getRecord(table, rid, r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, realInserts[i]), r, schema, "compare records"); } r = fromTestRecord(schema, updates[0]); r->id = rids[randomRec]; TEST_CHECK(updateRecord(table,r)); TEST_CHECK(getRecord(table, rids[randomRec], r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, updates[0]), r, schema, "compare records"); TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_t")); TEST_CHECK(shutdownRecordManager()); freeRecord(r); free(table); TEST_DONE(); }
void testUpdateTable (void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2}, {10, "jjjj", 5}, }; TestRecord updates[] = { {1, "iiii", 6}, {2, "iiii", 6}, {3, "iiii", 6} }; int deletes[] = { 9, 6, 7, 8, 5 }; TestRecord finalR[] = { {1, "iiii", 6}, {2, "iiii", 6}, {3, "iiii", 6}, {4, "dddd", 3}, {5, "eeee", 5}, }; int numInserts = 10, numUpdates = 3, numDeletes = 5, numFinal = 5, i; Record *r; RID *rids; Schema *schema; testName = "test creating a new table and insert,update,delete tuples"; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_r",schema)); TEST_CHECK(openTable(table, "test_table_r")); // insert rows into table for(i = 0; i < numInserts; i++) { r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } // delete rows from table for(i = 0; i < numDeletes; i++) { TEST_CHECK(deleteRecord(table,rids[deletes[i]])); } // update rows into table for(i = 0; i < numUpdates; i++) { r = fromTestRecord(schema, updates[i]); r->id = rids[i]; TEST_CHECK(updateRecord(table,r)); } TEST_CHECK(closeTable(table)); TEST_CHECK(openTable(table, "test_table_r")); // retrieve records from the table and compare to expected final stage for(i = 0; i < numFinal; i++) { RID rid = rids[i]; TEST_CHECK(getRecord(table, rid, r)); ASSERT_EQUALS_RECORDS(fromTestRecord(schema, finalR[i]), r, schema, "compare records"); } TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r")); TEST_CHECK(shutdownRecordManager()); free(table); TEST_DONE(); }
void testMultipleScans(void) { RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2}, {10, "jjjj", 5}, }; int numInserts = 10, i, scanOne=0, scanTwo=0; Record *r; RID *rids; Schema *schema; testName = "test running muliple scans "; schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); RM_ScanHandle *sc1 = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle)); RM_ScanHandle *sc2 = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle)); Expr *se1, *left, *right; int rc,rc2; TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_r",schema)); TEST_CHECK(openTable(table, "test_table_r")); // insert rows into table for(i = 0; i < numInserts; i++) { r = fromTestRecord(schema, inserts[i]); TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } // Mix 2 scans with c=3 as condition MAKE_CONS(left, stringToValue("i3")); MAKE_ATTRREF(right, 2); MAKE_BINOP_EXPR(se1, left, right, OP_COMP_EQUAL); createRecord(&r, schema); TEST_CHECK(startScan(table, sc1, se1)); TEST_CHECK(startScan(table, sc2, se1)); if ((rc2 = next(sc2, r)) == RC_OK) scanTwo++; i = 0; while((rc = next(sc1, r)) == RC_OK) { scanOne++; i++; if (i % 3 == 0) if ((rc2 = next(sc2, r)) == RC_OK) scanTwo++; } while((rc2 = next(sc2, r)) == RC_OK) scanTwo++; ASSERT_TRUE(scanOne == scanTwo, "scans returned same number of tuples"); if (rc != RC_NO_TUPLES) TEST_CHECK(rc); TEST_CHECK(closeScan(sc1)); TEST_CHECK(closeScan(sc2)); TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_r")); TEST_CHECK(shutdownRecordManager()); free(rids); free(table); TEST_DONE(); }
void test_functionality_boxscore_buffer() { /* tests that boxscore buffer is functional */ /****** CHECK 1: If a team's info is not on the buffer, then startSeekPos is 0 and boxscore buffer is updated *********/ /* Check 1.1: If it's a new year, startSeekPos = 0 and boxscore buffer is set to [year, {'team': lastByteChecked}] */ // Put 2010 on the buffer and clear the hashTable bufferYear = 2010; deleteTable(); /* Run the finish_did_get_portion of R.did_get_hit(date(2012, 6, 17), Player("Albert", "Pujols")) */ char boxscore1[200]; strcpy(boxscore1, rootDir); strcat(boxscore1, "datasets/retrosheet/unzipped/events2012/2012ANAB.txt"); FILE *fp = fopen(boxscore1, "r"); assert (fp); char *foundIt; char searchD[] = "6/17/2012"; char searchP[] = "Pujols A"; _search_boxscore(fp, &foundIt, searchD, boxscore1); assert (seekPosUsed == 0); // we only do seeking on date searches _search_boxscore(fp, &foundIt, searchP, boxscore1); /* Check that the buffer has the right values */ assert (bufferYear == 2012); struct boxData *boxData1 = findBoxscore(boxscore1); assert (strcmp(boxData1->boxscore, boxscore1) == 0); assert (boxData1->month = 6); assert (boxData1->day = 17); assert (boxData1->lastViewedByte == 53216); fclose(fp); /* Check 1.2: If its the same year but the team's boxscore has not yet been opened, startSeekPos = 0 and team is added to boxscoreBuffer[1].keys */ /* Run the __search_boxscore portion of R.did_get_hit(date(2012, 6, 15), Player("Jose", "Reyes", 2012, debut="6/10/2003")) */ char boxscore2[200]; strcpy(boxscore2, rootDir); strcat(boxscore2, "datasets/retrosheet/unzipped/events2012/2012TBAB.txt"); // char *boxscore2 = "/Users/faiyamrahman/programming/Python/beatthestreak/\ // beatthestreak/datasets/retrosheet/unzipped/events2012/2012TBAB.txt"; fp = fopen(boxscore2, "r"); assert (fp); char *foundIt2; char searchD2[] = "6/15/2012"; char searchP2[] = "Reyes J"; _search_boxscore(fp, &foundIt2, searchD2, boxscore2); assert (seekPosUsed == 0); _search_boxscore(fp, &foundIt2, searchP2, boxscore2); /* Check that the buffer has the right values */ assert (bufferYear == 2012); // first added boxscore assert (strcmp(boxData1->boxscore, boxscore1) == 0); assert (boxData1->month = 6); assert (boxData1->day = 17); assert (boxData1->lastViewedByte == 53216); // newly added boxscore struct boxData *boxData2 = findBoxscore(boxscore2); assert (strcmp(boxData2->boxscore, boxscore2) == 0); assert (boxData2->month == 6); assert (boxData2->day == 15); assert (boxData2->lastViewedByte == 57626); fclose(fp); /**** CHECK 2: if a team's boxscore info is on the buffer, then their info is examined on the buffer *****/ /* Check 2.1: If date is GREATER than date on buffer, startSeekPos = boxscoreBuffer[1][team][1] and buffer's last byte checked is updated */ /* Run the __search_boxscore portion of R.did_get_hit(date(2012, 8, 9), Player("Colby", "Rasmus", 2012) */ char *boxscore3 = boxscore2; fp = fopen(boxscore3, "r"); assert (fp); char *foundIt3; char searchD3[] = "8/9/2012"; char searchP3[] = "Rasmus C"; _search_boxscore(fp, &foundIt3, searchD3, boxscore3); assert (seekPosUsed == 57626); _search_boxscore(fp, &foundIt3, searchP3, boxscore3); /* Check that the buffer has the right values */ assert (bufferYear == 2012); // first added boxscore assert (strcmp(boxData1->boxscore, boxscore1) == 0); assert (boxData1->month = 6); assert (boxData1->day = 17); assert (boxData1->lastViewedByte == 53216); // second added boxscore assert (strcmp(boxData2->boxscore, boxscore2) == 0); assert (boxData2->month == 8); assert (boxData2->day == 9); assert (boxData2->lastViewedByte == 101668); fclose(fp); /* CHECK 2.2: if date is less than date on buffer, startSeekPos = 0 and last byte checked is updated */ char *boxscore4 = boxscore3; fp = fopen(boxscore4, "r"); assert (fp); char *foundIt4; char searchD4[] = "6/15/2012"; char searchP4[] = "Reyes J"; _search_boxscore(fp, &foundIt4, searchD4, boxscore4); assert (seekPosUsed == 0); // boxscore used correctly? _search_boxscore(fp, &foundIt4, searchP4, boxscore4); // check boxscore updated correctly assert (bufferYear == 2012); // first added boxscore assert (strcmp(boxData1->boxscore, boxscore1) == 0); assert (boxData1->month = 6); assert (boxData1->day = 17); assert (boxData1->lastViewedByte = 53216); // second added boxscore assert (strcmp(boxData2->boxscore, boxscore2) == 0); assert (boxData2->month == 6); assert (boxData2->day == 15); assert (boxData2->lastViewedByte == 57626); fclose(fp); /* Check 2.3: If date is EQUAL to date on buffer, startSeekPos = 0 and last byte checked is the SAME */ fp = fopen(boxscore4, "r"); assert (fp); _search_boxscore(fp, &foundIt4, searchD4, boxscore4); assert (seekPosUsed == 0); // boxscore used correctly? _search_boxscore(fp, &foundIt4, searchP4, boxscore4); // check boxscore updated correctly assert (bufferYear == 2012); // first added boxscore assert (strcmp(boxData1->boxscore, boxscore1) == 0); assert (boxData1->month = 6); assert (boxData1->day = 17); assert (boxData1->lastViewedByte = 53216); // second added boxscore assert (strcmp(boxData2->boxscore, boxscore2) == 0); assert (boxData2->month == 6); assert (boxData2->day == 15); assert (boxData2->lastViewedByte == 57626); fclose(fp); deleteTable(); }
int processOneTable(threadFunctionParameter *tfp) { MYSQL *pMySQL = NULL; sqlite3 *pSqlite = NULL; tableName tableNameOne; char sql[2046] = { 0 }; tableStruct tableStructOne; int ret = 0; memset(sql,0,sizeof(sql)); memset(&tableNameOne,0,sizeof(tableNameOne)); memset(&tableStructOne,0,sizeof(tableStructOne)); pMySQL = (MYSQL *)tfp->first; pSqlite = (sqlite3 *)tfp->second; memcpy(&tableNameOne,&tfp->table,sizeof(tableNameOne)); ret = getTableStruct(pMySQL,tableNameOne,&tableStructOne); if(ret < 0) { printf("call getTableStruct error.\n"); ret = -4; goto END; } sprintf(sql,"DROP TABLE IF EXISTS %s;\n",tableNameOne.str); ret = deleteTable(pSqlite,sql); if(ret < 0) { printf("call createTable error.\n"); ret = -4; goto END; } ret = createTable(pSqlite,tableStructOne.str); if(ret < 0) { printf("call createTable error.\n"); ret = -4; goto END; } ret = getIndexFromTable(pMySQL, tableNameOne, &tableStructOne); if(ret < 0) { printf("call createTable error.\n"); ret = -4; goto END; } ret = createIndex(pSqlite,tableStructOne.str); if(ret < 0) { printf("call createIndex error.\n"); ret = -4; goto END; } ret = getDataRow(pMySQL, pSqlite, tableNameOne, &tableStructOne); if(ret < 0) { printf("call getDataRow error.\n"); ret = -4; goto END; } END: return ret; }
/* * Constructs a mainForm as a child of 'parent', with the * name 'name' and widget flags set to 'f'. * */ mainForm::mainForm( QWidget* parent, const char* name, WFlags fl ) : QMainWindow( parent, name, fl ) { (void)statusBar(); if ( !name ) setName( "mainForm" ); setCentralWidget( new QWidget( this, "qt_central_widget" ) ); mainFormLayout = new QVBoxLayout( centralWidget(), 11, 6, "mainFormLayout"); mainTab = new QTabWidget( centralWidget(), "mainTab" ); structure = new QWidget( mainTab, "structure" ); structureLayout = new QVBoxLayout( structure, 11, 6, "structureLayout"); dblistView = new QListView( structure, "dblistView" ); dblistView->addColumn( tr( "Name" ) ); dblistView->header()->setClickEnabled( FALSE, dblistView->header()->count() - 1 ); dblistView->addColumn( tr( "Object" ) ); dblistView->header()->setClickEnabled( FALSE, dblistView->header()->count() - 1 ); dblistView->addColumn( tr( "Type" ) ); dblistView->header()->setClickEnabled( FALSE, dblistView->header()->count() - 1 ); dblistView->addColumn( tr( "Schema" ) ); dblistView->header()->setClickEnabled( FALSE, dblistView->header()->count() - 1 ); dblistView->setResizePolicy( QScrollView::Manual ); dblistView->setSelectionMode( QListView::NoSelection ); dblistView->setRootIsDecorated( TRUE ); dblistView->setResizeMode( QListView::LastColumn ); structureLayout->addWidget( dblistView ); mainTab->insertTab( structure, QString("") ); browser = new QWidget( mainTab, "browser" ); browserLayout = new QVBoxLayout( browser, 11, 6, "browserLayout"); layout2 = new QHBoxLayout( 0, 0, 6, "layout2"); textLabel1 = new QLabel( browser, "textLabel1" ); layout2->addWidget( textLabel1 ); comboBrowseTable = new QComboBox( FALSE, browser, "comboBrowseTable" ); comboBrowseTable->setMinimumSize( QSize( 115, 0 ) ); layout2->addWidget( comboBrowseTable ); buttonFind = new QPushButton( browser, "buttonFind" ); buttonFind->setPixmap( QPixmap::fromMimeSource( "searchfind.png" ) ); buttonFind->setToggleButton( TRUE ); layout2->addWidget( buttonFind ); QSpacerItem* spacer = new QSpacerItem( 51, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout2->addItem( spacer ); buttonNewRecord = new QPushButton( browser, "buttonNewRecord" ); layout2->addWidget( buttonNewRecord ); buttonDeleteRecord = new QPushButton( browser, "buttonDeleteRecord" ); layout2->addWidget( buttonDeleteRecord ); browserLayout->addLayout( layout2 ); dataTable = new QTable( browser, "dataTable" ); dataTable->setAcceptDrops( TRUE ); dataTable->setResizePolicy( QTable::Default ); dataTable->setVScrollBarMode( QTable::Auto ); dataTable->setNumRows( 0 ); dataTable->setNumCols( 0 ); dataTable->setReadOnly( TRUE ); dataTable->setSelectionMode( QTable::Single ); dataTable->setFocusStyle( QTable::FollowStyle ); browserLayout->addWidget( dataTable ); layout9 = new QHBoxLayout( 0, 0, 6, "layout9"); buttonPrevious = new QPushButton( browser, "buttonPrevious" ); buttonPrevious->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, buttonPrevious->sizePolicy().hasHeightForWidth() ) ); layout9->addWidget( buttonPrevious ); labelRecordset = new QLabel( browser, "labelRecordset" ); layout9->addWidget( labelRecordset ); buttonNext = new QPushButton( browser, "buttonNext" ); buttonNext->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, buttonNext->sizePolicy().hasHeightForWidth() ) ); layout9->addWidget( buttonNext ); QSpacerItem* spacer_2 = new QSpacerItem( 50, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout9->addItem( spacer_2 ); buttonGoto = new QPushButton( browser, "buttonGoto" ); layout9->addWidget( buttonGoto ); editGoto = new QLineEdit( browser, "editGoto" ); editGoto->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, editGoto->sizePolicy().hasHeightForWidth() ) ); editGoto->setFrameShape( QLineEdit::LineEditPanel ); editGoto->setFrameShadow( QLineEdit::Sunken ); layout9->addWidget( editGoto ); browserLayout->addLayout( layout9 ); mainTab->insertTab( browser, QString("") ); query = new QWidget( mainTab, "query" ); queryLayout = new QVBoxLayout( query, 11, 6, "queryLayout"); textLabel1_2 = new QLabel( query, "textLabel1_2" ); queryLayout->addWidget( textLabel1_2 ); sqlTextEdit = new QTextEdit( query, "sqlTextEdit" ); sqlTextEdit->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)5, 0, 0, sqlTextEdit->sizePolicy().hasHeightForWidth() ) ); queryLayout->addWidget( sqlTextEdit ); layout5 = new QHBoxLayout( 0, 0, 6, "layout5"); executeQueryButton = new QPushButton( query, "executeQueryButton" ); layout5->addWidget( executeQueryButton ); QSpacerItem* spacer_3 = new QSpacerItem( 325, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); layout5->addItem( spacer_3 ); queryLayout->addLayout( layout5 ); textLabel2 = new QLabel( query, "textLabel2" ); queryLayout->addWidget( textLabel2 ); queryErrorLineEdit = new QLineEdit( query, "queryErrorLineEdit" ); queryErrorLineEdit->setReadOnly( TRUE ); queryLayout->addWidget( queryErrorLineEdit ); textLabel3 = new QLabel( query, "textLabel3" ); queryLayout->addWidget( textLabel3 ); queryResultListView = new QListView( query, "queryResultListView" ); queryResultListView->setResizePolicy( QListView::Default ); queryResultListView->setSelectionMode( QListView::NoSelection ); queryResultListView->setResizeMode( QListView::AllColumns ); queryLayout->addWidget( queryResultListView ); mainTab->insertTab( query, QString("") ); mainFormLayout->addWidget( mainTab ); // actions fileNewAction = new QAction( this, "fileNewAction" ); fileNewAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "new.png" ) ) ); fileOpenAction = new QAction( this, "fileOpenAction" ); fileOpenAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "open.png" ) ) ); fileExitAction = new QAction( this, "fileExitAction" ); editCopyAction = new QAction( this, "editCopyAction" ); editPasteAction = new QAction( this, "editPasteAction" ); editFindAction = new QAction( this, "editFindAction" ); editFindAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "searchfind.png" ) ) ); helpContentsAction = new QAction( this, "helpContentsAction" ); helpIndexAction = new QAction( this, "helpIndexAction" ); helpAboutAction = new QAction( this, "helpAboutAction" ); fileCloseAction = new QAction( this, "fileCloseAction" ); fileCloseAction->setEnabled( FALSE ); newRecordAction = new QAction( this, "newRecordAction" ); fileCompactAction = new QAction( this, "fileCompactAction" ); fileCompactAction->setEnabled( FALSE ); helpWhatsThisAction = new QAction( this, "helpWhatsThisAction" ); helpWhatsThisAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "whatis.png" ) ) ); sqlLogAction = new QAction( this, "sqlLogAction" ); sqlLogAction->setToggleAction( TRUE ); sqlLogAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "log.png" ) ) ); fileImportCSVAction = new QAction( this, "fileImportCSVAction" ); fileExportCSVAction = new QAction( this, "fileExportCSVAction" ); fileSaveAction = new QAction( this, "fileSaveAction" ); fileSaveAction->setEnabled( FALSE ); fileSaveAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "save.png" ) ) ); fileRevertAction = new QAction( this, "fileRevertAction" ); fileRevertAction->setEnabled( FALSE ); fileRevertAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "revert.png" ) ) ); fileImportAction = new QAction( this, "fileImportAction" ); fileExportAction = new QAction( this, "fileExportAction" ); editCreateTableAction = new QAction( this, "editCreateTableAction" ); editCreateTableAction->setEnabled( FALSE ); editCreateTableAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "create_table.png" ) ) ); editDeleteTableAction = new QAction( this, "editDeleteTableAction" ); editDeleteTableAction->setEnabled( FALSE ); editDeleteTableAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "delete_table.png" ) ) ); editModifyTableAction = new QAction( this, "editModifyTableAction" ); editModifyTableAction->setEnabled( FALSE ); editModifyTableAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "modify_table.png" ) ) ); editCreateIndexAction = new QAction( this, "editCreateIndexAction" ); editCreateIndexAction->setEnabled( FALSE ); editCreateIndexAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "create_index.png" ) ) ); editDeleteIndexAction = new QAction( this, "editDeleteIndexAction" ); editDeleteIndexAction->setEnabled( FALSE ); editDeleteIndexAction->setIconSet( QIconSet( QPixmap::fromMimeSource( "delete_index.png" ) ) ); fileImportSQLAction = new QAction( this, "fileImportSQLAction" ); fileExportSQLAction = new QAction( this, "fileExportSQLAction" ); // toolbars Toolbar = new QToolBar( QString(""), this, DockTop ); fileNewAction->addTo( Toolbar ); fileOpenAction->addTo( Toolbar ); fileSaveAction->addTo( Toolbar ); fileRevertAction->addTo( Toolbar ); Toolbar->addSeparator(); editCreateTableAction->addTo( Toolbar ); editDeleteTableAction->addTo( Toolbar ); editModifyTableAction->addTo( Toolbar ); editCreateIndexAction->addTo( Toolbar ); editDeleteIndexAction->addTo( Toolbar ); Toolbar->addSeparator(); sqlLogAction->addTo( Toolbar ); Toolbar->addSeparator(); helpWhatsThisAction->addTo( Toolbar ); // menubar menubar = new QMenuBar( this, "menubar" ); fileMenu = new QPopupMenu( this ); fileNewAction->addTo( fileMenu ); fileOpenAction->addTo( fileMenu ); fileCloseAction->addTo( fileMenu ); fileMenu->insertSeparator(); fileSaveAction->addTo( fileMenu ); fileRevertAction->addTo( fileMenu ); fileCompactAction->addTo( fileMenu ); fileMenu->insertSeparator(); QPopupMenu *PopupMenuEditor_9 = new QPopupMenu( this ); fileMenu->setAccel( tr( "" ), fileMenu->insertItem( fileImportAction->iconSet(),tr( "Import" ), PopupMenuEditor_9 ) ); fileImportSQLAction->addTo( PopupMenuEditor_9 ); fileImportCSVAction->addTo( PopupMenuEditor_9 ); QPopupMenu *PopupMenuEditor_12 = new QPopupMenu( this ); fileMenu->setAccel( tr( "" ), fileMenu->insertItem( fileExportAction->iconSet(),tr( "Export" ), PopupMenuEditor_12 ) ); fileExportSQLAction->addTo( PopupMenuEditor_12 ); fileExportCSVAction->addTo( PopupMenuEditor_12 ); fileMenu->insertSeparator(); fileExitAction->addTo( fileMenu ); menubar->insertItem( QString(""), fileMenu, 1 ); EditMenu = new QPopupMenu( this ); editCreateTableAction->addTo( EditMenu ); editDeleteTableAction->addTo( EditMenu ); editModifyTableAction->addTo( EditMenu ); EditMenu->insertSeparator(); editCreateIndexAction->addTo( EditMenu ); editDeleteIndexAction->addTo( EditMenu ); menubar->insertItem( QString(""), EditMenu, 2 ); ViewMenu = new QPopupMenu( this ); sqlLogAction->addTo( ViewMenu ); menubar->insertItem( QString(""), ViewMenu, 3 ); PopupMenu = new QPopupMenu( this ); helpWhatsThisAction->addTo( PopupMenu ); helpAboutAction->addTo( PopupMenu ); menubar->insertItem( QString(""), PopupMenu, 4 ); languageChange(); resize( QSize(702, 552).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); // signals and slots connections connect( fileExitAction, SIGNAL( activated() ), this, SLOT( fileExit() ) ); connect( fileOpenAction, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); connect( fileNewAction, SIGNAL( activated() ), this, SLOT( fileNew() ) ); connect( fileCloseAction, SIGNAL( activated() ), this, SLOT( fileClose() ) ); connect( comboBrowseTable, SIGNAL( activated(const QString&) ), this, SLOT( populateTable(const QString&) ) ); connect( buttonNewRecord, SIGNAL( clicked() ), this, SLOT( addRecord() ) ); connect( buttonDeleteRecord, SIGNAL( clicked() ), this, SLOT( deleteRecord() ) ); connect( buttonPrevious, SIGNAL( clicked() ), this, SLOT( navigatePrevious() ) ); connect( buttonNext, SIGNAL( clicked() ), this, SLOT( navigateNext() ) ); connect( editGoto, SIGNAL( returnPressed() ), this, SLOT( navigateGoto() ) ); connect( buttonGoto, SIGNAL( clicked() ), this, SLOT( navigateGoto() ) ); connect( buttonFind, SIGNAL( toggled(bool) ), this, SLOT( browseFind(bool) ) ); connect( fileCompactAction, SIGNAL( activated() ), this, SLOT( compact() ) ); connect( editCopyAction, SIGNAL( activated() ), this, SLOT( copy() ) ); connect( editPasteAction, SIGNAL( activated() ), this, SLOT( paste() ) ); connect( helpWhatsThisAction, SIGNAL( activated() ), this, SLOT( helpWhatsThis() ) ); connect( helpAboutAction, SIGNAL( activated() ), this, SLOT( helpAbout() ) ); connect( dataTable, SIGNAL( doubleClicked(int,int,int,const QPoint&) ), this, SLOT( doubleClickTable(int,int,int,const QPoint&) ) ); connect( mainTab, SIGNAL( selected(const QString&) ), this, SLOT( mainTabSelected(const QString&) ) ); connect( sqlLogAction, SIGNAL( toggled(bool) ), this, SLOT( toggleLogWindow(bool) ) ); connect( executeQueryButton, SIGNAL( clicked() ), this, SLOT( executeQuery() ) ); connect( fileImportCSVAction, SIGNAL( activated() ), this, SLOT( importTableFromCSV() ) ); connect( fileExportCSVAction, SIGNAL( activated() ), this, SLOT( exportTableToCSV() ) ); connect( fileRevertAction, SIGNAL( activated() ), this, SLOT( fileRevert() ) ); connect( fileSaveAction, SIGNAL( activated() ), this, SLOT( fileSave() ) ); connect( editDeleteIndexAction, SIGNAL( activated() ), this, SLOT( deleteIndex() ) ); connect( editCreateIndexAction, SIGNAL( activated() ), this, SLOT( createIndex() ) ); connect( editCreateTableAction, SIGNAL( activated() ), this, SLOT( createTable() ) ); connect( editDeleteTableAction, SIGNAL( activated() ), this, SLOT( deleteTable() ) ); connect( editModifyTableAction, SIGNAL( activated() ), this, SLOT( editTable() ) ); connect( fileExportSQLAction, SIGNAL( activated() ), this, SLOT( exportDatabaseToSQL() ) ); connect( fileImportSQLAction, SIGNAL( activated() ), this, SLOT( importDatabaseFromSQL() ) ); init(); }
void throwError(errorCode code){ printf("Error #%d at token %d: ", code, tokenNum); switch(code){ case(EQ_NOT_BECOMES): // Used printf("Use = instead of :=.\n"); break; case(NUM_FOLLOW_EQ): // Used printf("= must be followed by a number.\n"); break; case(EQ_FOLLOW_ID): // Used printf("Identifier must be followed by a number.\n"); break; case(ID_FOLLOW_CONST_VAR_PROC): // Used printf("const, var, procedure must be followed by identifier.\n"); break; case(SEMICOL_COMMA_MISS): // Used printf("Semicolon or comma missing.\n"); break; case(WRONG_SYM_AFTER_PROC): // Used printf("Incorrect symbol after procedure declaration.\n"); break; case(STATEMENT_EXPEC): // Used printf("Statement expected.\n"); break; case(WRONG_SYM_AFTER_STATE): // Used printf("Incorrect symbol after statement part in block.\n"); break; case(PERIOD_EXPEC): // Used printf("Period expected.\n"); break; case(SEMICOL_BW_STATE_MISS): // Used printf("Semicolon between statements missing.\n"); break; case(UNDEC_ID): // Used printf("Undeclared identifier.\n"); break; case(CANNOT_ASSIGN_TO_CONST_OR_PROC): // Used printf("Assignment to constant or procedure is not allowed.\n"); break; case(ASSIGN_EXPEC): // Used printf("Assignment operator expected.\n"); break; case(ID_FOLLOW_SYAW): // Used printf("syaw must be followed by an identifier.\n"); break; case(CONST_OR_VAR_CALL_USELESS): // NO printf("Call of a constant or variable is meaningless.\n"); break; case(TSAKRR_EXPEC): // Used printf("tsakrr expected.\n"); break; case(SEMICOL_OR_RBRACK_EXPEC): // Used printf("Semicolon or } expected.\n"); break; case(SI_EXPEC): // Used printf("si expected.\n"); break; case(WRONG_SYM_FOLLOWING_STATE): // Used parallel to SEMICOL_OR_RBRACK_EXPEC printf("Incorrect symbol following statement.\n"); break; case(REL_OP_EXPEC): // Used printf("Relational operator expected.\n"); break; case(EXP_CANNOT_CONTAIN_PROC_IDENT): // Used printf("Expression must not contain a procedure identifier.\n"); break; case(RPAREN_MISS): // Used printf("Right parenthesis missing.\n"); break; case(PREC_FACTOR_CANNOT_BEGIN_SYM): // Used printf("The preceding factor cannot begin with this symbol.\n"); break; case(SYMBOL_CANNOT_BEGIN_THIS_EXP): printf("An expression cannot begin with this symbol.\n"); break; case(NUMBER_TOO_LARGE): // NO? printf("This number is too large.\n"); break; case(RBRACK_EXPEC_AT_END): printf("} expected at the end of the program.\n"); break; case(CANNOT_STORE_IN_CONST_OR_PROC): printf("Cannot store a value in a constant or procedure.\n"); break; default: printf("Improper error code.\n"); break; } deleteTable(symTable); abort(); }
int main() { char filename[MAX_SIZE+1], temp[MAX_SIZE+1]; FILE *ifp; int numwords, i; struct htable mytable; int ans; // Get the file name. printf("What is the name of the dictionary file?\n"); scanf("%s", &filename); ifp = fopen(filename, "r"); fscanf(ifp, "%d", &numwords); // Read in all of the words from a file into the table. // This is only done once. printf("get here\n"); initTable(&mytable); printf("iniit table\n"); for (i=0; i<numwords; i++) { fscanf(ifp, "%s", temp); insertTable(&mytable, temp); } // Allow the user to make changes to the hash table and search for words. do { printf("Do you want to 1)search word, 2) add word, 3) delete a word?\n"); scanf("%d", &ans); // Search for a word. if (ans == 1) { printf("What word are you looking for?\n"); scanf("%s", temp); if (searchTable(&mytable, temp)) printf("%s was found.\n", temp); else printf("%s was NOT found.\n", temp); } // Add a word. else if (ans == 2) { printf("What word do you want to add?\n"); scanf("%s", temp); if (searchTable(&mytable, temp)) printf("%s was ALREADY in the table\n", temp); else insertTable(&mytable, temp); } // Delete a word. else if (ans == 3) { printf("What word do you want to delete?\n"); scanf("%s", temp); deleteTable(&mytable, temp); } } while (ans < 4); // Not very user friendly, just quits for any number > 3. system("PAUSE"); return 0; }
void testCheckingPrimaryKeyWithSingleAttribute(void) { //just like test_assign3_1.c we insert records in the same way at first. RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData)); TestRecord inserts[] = { {1, "aaaa", 3}, {2, "bbbb", 2}, {3, "cccc", 1}, {4, "dddd", 3}, {5, "eeee", 5}, {6, "ffff", 1}, {7, "gggg", 3}, {8, "hhhh", 3}, {9, "iiii", 2}, {10, "jjjj", 5}, }; TestRecord realInserts[10000]; int numInserts = 100, i; Record *r; RID *rids; Schema *schema; testName = "test checking primary key with single attribute"; //this schema is exactly the same as test_assign3_1.c, this primary key only have 1 attibute. schema = testSchema(); rids = (RID *) malloc(sizeof(RID) * numInserts); TEST_CHECK(initRecordManager(NULL)); TEST_CHECK(createTable("test_table_t",schema)); TEST_CHECK(openTable(table, "test_table_t")); for(i = 0; i <numInserts; i++) { realInserts[i] = inserts[i%10]; realInserts[i].a = i; r = fromTestRecord(schema, realInserts[i]); printf("inserting record {%d,\"%s\",%d}",realInserts[i].a,realInserts[i].b,realInserts[i].c); //Extra Credit: Check primary key constraints. //check whether there exists a tuple that have the same key attribute value with this new record. if (CheckPrimaryKey(table, r)==RC_OK) { printf(" Success!\n"); } else { printf(" Failed! A tuple with same attribute value already exists!\n"); } TEST_CHECK(insertRecord(table,r)); rids[i] = r->id; } //here is the code to check distinct,we insert some records that are already exist in the file, if detected, the checking function will return a RC value differen from RC_OK. TestRecord newInsert; newInsert=inserts[0]; newInsert.a=0; r=fromTestRecord(schema, newInsert); printf("inserting record {%d,\"%s\",%d}",newInsert.a,newInsert.b,newInsert.c); //Extra Credit: Check primary key constraints. //check whether there exists a tuple that have the same key attribute value with this new record. if (CheckPrimaryKey(table, r)==RC_OK) { printf(" Success!\n"); } else { printf(" Failed! A tuple with same attribute value already exists!\n"); } insertRecord(table,r); TEST_CHECK(closeTable(table)); TEST_CHECK(deleteTable("test_table_t")); TEST_CHECK(shutdownRecordManager()); freeRecord(r); free(table); TEST_DONE(); }
int main (int argc, char* argv[]){ if(argc!=3){printf("Bad input - incorrect number of arguments\n");return 1;} FILE *file= fopen(argv[2],"r"); if(file==NULL){printf("file/directory given to index does not exist\n");return 1;} fclose(file);/*only opened it to check that it existed*/ file = fopen(argv[1],"r"); if(file!=NULL){/*Handle the case of being given an output file that already exists. Prompt user for action*/ char a[15]; fclose(file); printf("Output file exists. Would you like to overwrite it? [y/n]: "); scanf("%c",a); if(a[0]!='y'){return 1;} } FILE *outfile= fopen(argv[1],"w+");/*Open the outfile for real this time*/ table = makeTable(); ftw(argv[2],applyme,100);/*The ftw function applies the given method [applyme] recursively across directories [and to all files in them]*/ struct Node* curr = table->keylist; if(curr==NULL){deleteTable(table); fclose(outfile); return 0;} struct Node* next = curr->next; int size=1,j=0; while(next!=NULL){/*Walk across the keylist to get the number of elements in the hashtable - Really only necessary for the output at the end, but helpful for building sortMe*/ size++; curr=next; next=curr->next; } struct hashnode *sortMe[size];/*Will contain the list of hashnodes to be sorted by qsort and then output*/ curr = table->keylist; for(j=0;j<size;j++){/*Populate the sortMe list*/ sortMe[j] = search(((struct hashnode*)(curr->data))->key,table); curr=curr->next; } qsort(sortMe,size,(sizeof(struct hashnode*)),compareHashNodes); /*Output in JSON format. This is ugly, but don't blame me, blame JSON*/ fprintf(outfile,"{\"list\" : [\n"); for(j=0;j<size;j++){ if(j==0){fprintf(outfile,"\t\"%s\" : [\n",(sortMe[j]->word)); fprintf(outfile,"\t\t{\"%s\" : %d}",(sortMe[j]->path),(sortMe[j]->frequency)); if(j+1==size){fprintf(outfile,"\t]}\n]}\n");break;} continue; } if(strcmp((sortMe[j-1]->word),(sortMe[j]->word))!=0){fprintf(outfile,"\t\"%s\" : [",(sortMe[j]->word));} if(strcmp((sortMe[j]->word),(sortMe[j+1]->word))==0){fprintf(outfile,"\n\t\t{\"%s\" : %d},",(sortMe[j]->path),(sortMe[j]->frequency));} else{fprintf(outfile,"\n\t\t{\"%s\" : %d}\n\t\t]},\n\n",(sortMe[j]->path),(sortMe[j]->frequency));} if(j+2==size){ if(strcmp((sortMe[j]->word),(sortMe[j+1]->word))!=0){fprintf(outfile,"\t\"%s\" : [",(sortMe[j+1]->word));} fprintf(outfile,"\n\t\t{\"%s\" : %d}",(sortMe[j+1]->path),(sortMe[j+1]->frequency)); fprintf(outfile,"\n\t]}\n]}\n"); break;} } deleteTable(table);/*Chain reaction data clearing*/ fclose(outfile);/*Close the output file to finish*/ }
PropertyView::~PropertyView() { deleteTable(); }
int mainForm::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = Q3MainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: fileOpen((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 1: fileOpen(); break; case 2: fileNew(); break; case 3: populateStructure(); break; case 4: populateTable((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 5: resetBrowser(); break; case 6: fileClose(); break; case 7: fileExit(); break; case 8: closeEvent((*reinterpret_cast< QCloseEvent*(*)>(_a[1]))); break; case 9: addRecord(); break; case 10: deleteRecord(); break; case 11: updateTableView((*reinterpret_cast< int(*)>(_a[1]))); break; case 12: selectTableLine((*reinterpret_cast< int(*)>(_a[1]))); break; case 13: navigatePrevious(); break; case 14: navigateNext(); break; case 15: navigateGoto(); break; case 16: setRecordsetLabel(); break; case 17: browseFind((*reinterpret_cast< bool(*)>(_a[1]))); break; case 18: browseFindAway(); break; case 19: lookfor((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break; case 20: showrecord((*reinterpret_cast< int(*)>(_a[1]))); break; case 21: createTable(); break; case 22: createIndex(); break; case 23: compact(); break; case 24: deleteTable(); break; case 25: editTable(); break; case 26: deleteIndex(); break; case 27: copy(); break; case 28: paste(); break; case 29: helpWhatsThis(); break; case 30: helpAbout(); break; case 31: updateRecordText((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break; case 32: logWinAway(); break; case 33: editWinAway(); break; case 34: editText((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 35: doubleClickTable((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3])),(*reinterpret_cast< const QPoint(*)>(_a[4]))); break; case 36: executeQuery(); break; case 37: mainTabSelected((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 38: toggleLogWindow((*reinterpret_cast< bool(*)>(_a[1]))); break; case 39: importTableFromCSV(); break; case 40: exportTableToCSV(); break; case 41: dbState((*reinterpret_cast< bool(*)>(_a[1]))); break; case 42: fileSave(); break; case 43: fileRevert(); break; case 44: exportDatabaseToSQL(); break; case 45: importDatabaseFromSQL(); break; case 46: openPreferences(); break; case 47: updatePreferences(); break; case 48: languageChange(); break; default: ; } _id -= 49; } return _id; }
void MainWindow::updatePropertyTable(int nodeID) { if(nodeID == -2) nodeID = Data::instance()->getFocusedID(); QTableWidget *table = ui->tableWidget; if (nodeID >= 0 && Data::instance()->nodesInMesh()->contains(nodeID)) { deleteTable(); oldfocus = nodeID; Node *n = Data::instance()->getNodeByID(nodeID); QMap<QString, Node::Parameter> *map = n->getParams(); table->setRowCount(map->size() + 6); int i = 0; // create the entries all nodes have QTableWidgetItem *name = new QTableWidgetItem(), *ID = new QTableWidgetItem(), *type = new QTableWidgetItem(), *category = new QTableWidgetItem(); // set the data ID->setData(0, nodeID); name->setData(0, n->getName()); type->setData(0, n->getType()); category->setData(0,n->getCategory()); // asign to table: // NodeID table->setItem(i, 0, new QTableWidgetItem("NodeID")); table->setItem(i, 1, ID); table->item(i, 0)->setFlags(table->item(0, 0)->flags() ^ (Qt::ItemIsEnabled | Qt::ItemIsSelectable)); i++; // Node Class table->setItem(i, 0, new QTableWidgetItem("Node Class")); table->setItem(i, 1, type); table->item(i, 0)->setFlags(table->item(i, 0)->flags() ^ (Qt::ItemIsEnabled | Qt::ItemIsSelectable)); i++; //Node Category table->setItem(i, 0, new QTableWidgetItem("Node Category")); table->setItem(i, 1, category); table->item(i, 0)->setFlags(table->item(i, 0)->flags() ^ (Qt::ItemIsEnabled | Qt::ItemIsSelectable)); i++; // input Gates bool moreThanOne = n->getInputGates()->size() > 1; if (!n->getInputGates()->isEmpty()) { QString types; for (Gate *g : *n->getInputGates()) for (QString s : g->getTypes()) types += s + ", "; types.chop(2); QTableWidgetItem *in = new QTableWidgetItem(); in->setText(types); in->setFlags(in->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable)); table->setItem(i, 0, new QTableWidgetItem( "Input" + QString((moreThanOne ? "s" : "")))); table->setItem(i, 1, in); table->item(i, 1)->setToolTip(types); i++; } // output gates moreThanOne = n->getOutputGates()->size() > 1; if (!n->getOutputGates()->isEmpty()) { QString types; for (Gate *g : *n->getOutputGates()) for (QString s : g->getTypes()) types += s + ", "; types.chop(2); QTableWidgetItem *out = new QTableWidgetItem; out->setText(types); out->setFlags(out->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable)); table->setItem(i, 0, new QTableWidgetItem( "Output" + QString((moreThanOne ? "s" : "")))); table->setItem(i, 1, out); table->item(i, 1)->setToolTip(types); i++; } table->setItem(i, 0, new QTableWidgetItem("Node Name")); table->setItem(i, 1, name); i++; // make name editable name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable); // avoid editing keys, and nodeID/type ID->setFlags(ID->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled)); type->setFlags(type->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled)); for (int j = 0; j < i; j++) table->item(j, 0)->setFlags(table->item(j, 0)->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable)); QStringList keys = map->keys(); int count = i; for (int j = 0; j < keys.size(); j++) { count++; // create key item QString key = keys.value(j); QTableWidgetItem *key_item = new QTableWidgetItem((*map)[key].name); key_item->setData(Qt::UserRole, key); key_item->setFlags(key_item->flags() ^ (Qt::ItemIsEditable | Qt::ItemIsSelectable)); key_item->setToolTip((*map)[key].descr); table->setItem(i + j, 0, key_item); // create value item QVariant value = map->value(key).value; QTableWidgetItem *value_item = new QTableWidgetItem(); value_item->setToolTip((*map)[key].descr); // QSpinBox *spinner; switch (value.userType()) { case QVariant::Bool: // value_item->setData(0, value); value_item->setCheckState(value.toBool() ? Qt::Checked : Qt::Unchecked); table->setItem(i + j, 1, value_item); break; default: value_item->setData(Qt::UserRole, value); value_item->setText(value.toString()); table->setItem(i + j, 1, value_item); if (key.contains("file")) { connect(table, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(onFilebuttonClicked(int, int))); } break; } }
void test_structure_boxscore_buffer() { /* Tests that the hash table and basic structure of the boxscore buffer works */ struct boxData *bD; /* Test that we can retrieve and set the boxscorebuffer year */ bufferYear = 7; assert (bufferYear == 7); /* Test..... */ deleteTable(); assert (HASH_COUNT(boxHashTable) == 0); /* adding */ addReplaceBoxscore("boxscore1", 10L, 5, 3); assert (HASH_COUNT(boxHashTable) == 1); /* finding */ struct boxData *boxData1 = findBoxscore("boxscore1"); assert (strcmp(boxData1->boxscore, "boxscore1") == 0); assert (boxData1->lastViewedByte == 10L); assert (boxData1->month == 5); assert (boxData1->day == 3); /* replacing an already hashed key */ addReplaceBoxscore("boxscore1", 55L, 7, 2); assert(HASH_COUNT(boxHashTable) == 1); // also do a manual count to guard against nonunique keys int i = 0; for (bD=boxHashTable; bD != NULL; bD=bD->hh.next) { i++; } assert (i == 1); assert (strcmp(boxData1->boxscore,"boxscore1") == 0); assert (boxData1->lastViewedByte == 55L); assert (boxData1->month == 7); assert (boxData1->day == 2); /* deleting */ deleteTable(); // frees memory assert (HASH_COUNT(boxHashTable) == 0); /* Another test to gaurd against nonunique keys. Motivated by a bug */ char *bs2 = "/Users/faiyamrahman/programming/Python/beatthestreak/\ beatthestreak/datasets/retrosheet/unzipped/events2010/2010ANAB.txt"; char *bs3 = "/Users/faiyamrahman/programming/Python/beatthestreak/\ beatthestreak/datasets/retrosheet/unzipped/events2010/2010ANAB.txt"; // printf("\n\nBefore first addition:"); // printHashTable(0); addReplaceBoxscore(bs2, 48L, 4, 4); // printf("After first addition:"); // printHashTable(0); assert (HASH_COUNT(boxHashTable) == 1); // manual count i = 0; for (bD=boxHashTable; bD != NULL; bD=bD->hh.next) { i++; } assert (i == 1); addReplaceBoxscore(bs3, 50L, 4, 5); // printf("\nAfter second addition:"); // printHashTable(0); assert (HASH_COUNT(boxHashTable) == 1); // manual count i = 0; for (bD=boxHashTable; bD != NULL; bD=bD->hh.next) { i++; } assert (i == 1); }