const WbSchema Tool::AddKeysRequiredByWorkbench( const WbSchema& schema, const QString& defaultName ) { WbSchema newSchema( schema ); newSchema.AddSingleValueKey( WbDefaultKeys::displayNameKey, WbSchemaElement::Multiplicity::One, KeyValue::from( defaultName ) ); return newSchema; }
void SchemaDrawer::openSchemaByFilePath( QString filePath ) { newSchema(); QWidget* widget = _workspace->activeWindow(); DocumentDrawer* documentDrawer = qobject_cast<DocumentDrawer*>( widget ); if( 0 == documentDrawer ) return; documentDrawer->openDocument( filePath ); }
Relation Relation::rename(pair<vector<Token>, vector<Token> >& ruleParameters, Relation& targetRelation) { Relation newRelation = (*this); const int FIRST = 0; const int SECOND = 1; vector<pair<Token, vector<vector<int> > > > myMap; for(int i = 0; i < ruleParameters.first.size(); i++) // Make a mapping of the rule parameters to find matches { vector<vector<int> > intVec; vector<int> firstVec; vector<int> secondVec; intVec.push_back(firstVec); intVec.push_back(secondVec); bool insert = true; for(int k = 0; k < myMap.size(); k++) { if(ruleParameters.first[i].getTokensValue() == myMap[k].first.getTokensValue()) // If token from first tvector is in map { Schema* tSchema = targetRelation.getSchema(); Token thisToken = (*tSchema)[myMap[k].second[FIRST][FIRST]]; tSchema->renameTokenAt(i, thisToken); // Rename right-side arguments that will be joined myMap[k].second[FIRST].push_back(i); insert = false; // don't insert that token } } if(insert) { intVec[FIRST].push_back(i); myMap.push_back(pair<Token, vector<vector<int> > >(ruleParameters.first[i], intVec)); } } for(int i = 0; i < myMap.size(); i++) // if there are duplicates in the second vector, add to int vector { for(int j = 0; j < ruleParameters.second.size(); j++) { if(myMap[i].first.getTokensValue() == ruleParameters.second[j].getTokensValue()) { myMap[i].second[SECOND].push_back(j); } else { Schema* tSchema = targetRelation.getSchema(); if((*tSchema)[myMap[i].second[FIRST][FIRST]].getTokensValue() == (*schema)[j].getTokensValue()); { string newValue = (*schema)[j].getTokensValue() + "$"; Token newToken = (*schema)[j]; newToken.setTokenValue(newValue); schema->renameTokenAt(j, newToken); } } } } Schema newSchema(*schema); for(int i = 0; i < myMap.size(); i++) // Rename the Schema { for(int j = 0; j < myMap[i].second[SECOND].size(); j++) { Schema* tSchema = targetRelation.getSchema(); Token thisToken = (*tSchema)[myMap[i].second[FIRST][FIRST]]; newSchema.renameTokenAt(myMap[i].second[SECOND][j], thisToken); } } newRelation.setSchema(newSchema); set<Tuple>* newTuples = new set<Tuple>(); for(set<Tuple>::iterator it = tuples->begin(); it != tuples->end(); it++) // Copy tuples with the renamed Schema { Tuple thisTuple = (*it); Tuple newTuple(thisTuple, newSchema); newTuples->insert(newTuple); } set<Tuple>* deleteTuples = newRelation.getTuples(); newRelation.setTuples(newTuples); delete deleteTuples; return newRelation; }
void testCheckingPrimaryKeyWithMultiAttribute(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 multiple attribute"; //this schema is different because it has a primary key that contains attribute 0 and 1,so this primary key have 2 attibute. schema = newSchema(); 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 a distinct record. TestRecord newInsert; newInsert=inserts[0]; newInsert.a=0; newInsert.b="aaab"; 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); //here is the code to check distinct,we insert a record that already exists in the file newInsert=inserts[0]; newInsert.a=0; newInsert.b="aaaa"; 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(); }
SchemaDrawer::SchemaDrawer(): QMainWindow( 0 ) { ActionIconProvider actionIconProvider; // SchemaDrawer QMenu* schemaDrawerMenu = menuBar()->addMenu( "SchemaDrawer" ); schemaDrawerMenu->addAction( actionIconProvider.getIconForAction("help"), "Help Me!", this, SLOT(helpMe()) ); schemaDrawerMenu->addSeparator(); schemaDrawerMenu->addAction( actionIconProvider.getIconForAction("exit"), "Exit", this, SLOT(close()) ); // Schema QMenu* schemaMenu = menuBar()->addMenu( "Schema" ); schemaMenu->addAction( actionIconProvider.getIconForAction("add"), "Schema", this, SLOT(newSchema()) ); schemaMenu->addAction( actionIconProvider.getIconForAction("save"), "Save", this, SLOT(saveSchema()) ); schemaMenu->addAction( actionIconProvider.getIconForAction("open"), "Open", this, SLOT(openSchema()) ); // preparing the workspace _workspace = new QWorkspace(); setCentralWidget( _workspace ); // cosmetics Styling styling( *this ); styling.loadOnScreenPosition(); setWindowTitle( "Schema Drawer" ); }