bool BaseSqlDropTableService::isValid(const Commands::ConstCommandPtr &command,
                                      const CommandExecution::CommandExecutionContext &context) const
{
    QSharedPointer<const Commands::DropTable> dropTable(command.staticCast<const Commands::DropTable>());

    //check if tableName is empty
    if (dropTable->tableName().isEmpty()) {
        ::qWarning() << "need to specify a table name!";
        return false;
    }

    //check if table exists
    if (!context.database().tables().contains(dropTable->tableName())) {
        ::qWarning() << "table doesn't exist!";
        return false;
    }

    return true;
}
예제 #2
0
파일: mainwindow.cpp 프로젝트: lemanhha/TMS
void MainWindow::openFile()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"),
                       tr(""), tr("Excel Files (*.xlsx)"));
    if (database.isOpen() && fileName.length() > 0 &&
       fileName.endsWith(".xlsx", Qt::CaseInsensitive))
    {
        if (check_box_open->isChecked())
        {
            for (int table_id = 0; table_id < number_of_tables; ++table_id)
            {
                dropTable(table_names.at(table_id));
            }
        }
        createTables();
        readExcelFile(fileName);
        table_models.at(table_list->currentRow())->select();
        QMessageBox::information(this,tr(""),tr("Load file ok"));
    }
}
예제 #3
0
void Select()
{
    char s[1000];
    gets(s);
    upper_change(s);///There, we change the string alphabat to upper.
    //puts(s);///转换检测
    SQL *sql=new SQL(s);
    if (sql->Get(sql->GetSize()-1) != ";") {cout<<"plz use ; to the end."<<endl; return ;}
    if (sql->Get(0) == "exit"){cout<<"ByeBye~"<<endl; exit(0);}
    if (!sql->Judge()) return ;
    if (sql->Get(0) == "create" && sql->Get(1) == "table")
        createTable(sql);//create table s (num int ,name char(10))
    else if(sql->Get(0) == "insert" && sql->Get(1) == "into" && sql->Get(3) == "values")
        insertRecord(sql);//insert into s values ()
    else if (sql->Get(0) == "show")
        showTable(sql->Get(1)); //show s
    else if (sql->Get(0) == "drop" && sql->Get(1) == "table")
        dropTable (sql->Get(2));//drop table s
    else if (sql->Get(0) =="alter" && sql->Get(1) == "table")
        alterTable (sql);//alter table s (add name type)/(drop name type)
    else if (sql->Get(0) =="delete" && sql->Get(1) == "from" && sql->Get(3) == "where")
        deleteRecord(sql);//delete from s while name = name1
    else cout << "The code is error!" << endl;
}
예제 #4
0
void ImportF::dropTmpTables()
{
	dropTable("updatecontacts");
	dropTable("tmpallcontacts");
	dropTable("updatesitedescription");
	dropTable("tmpalldescription");
	dropTable("tmpupdateradioinstallations");
	dropTable("existri");
	dropTable("newinstallations");
	dropTable("tmpantennapatterntable");
	dropTable("newinstallationswithantenna");
	dropTable("tmpsi");
	dropTable("tablecells");
	dropTable("tablecellunique");
	dropTable("newinstallationsTMP");
	dropTable("tmptechkey");
	dropTable("newinstallationswithTech");
}
예제 #5
0
void ImportF::updateRadioInstallations()
{
	printf("ImportF::updateRadioInstallations()\n");

	// ensure that the sequence is correct
	fixSequence("radioinstallation","id");

/* update old entries */
	// create a table with all the radio installations that are not newer
	dropTable("tmpupdateradioinstallations");
	printf("1\n");
	execSQLCommand("CREATE TABLE tmpupdateradioinstallations AS SELECT DISTINCT ON (radioinstallation.siteid,radioinstallationsector)  radioinstallation.siteid,radioinstallation.lastmodified, radioinstallationlastmodified,radioinstallationsector, radioinstallationpermanent,radioinstallationtechkey,radioinstallationeirp,radioinstallationdiversity, radioinstallationtxpower,radioinstallationtxlosses,radioinstallationtxantennaheight,radioinstallationtxantpatternkey, radioinstallationtxbearing,radioinstallationtxmechtilt,radioinstallationrxsensitivity,radioinstallationrxlosses, radioinstallationrxantennaheight,radioinstallationrxantpatternkey,radioinstallationrxbearing,radioinstallationrxmechtilt, radioinstallationbtlplot,radioinstallationflaga,radioinstallationflagb,radioinstallationflagc,technologytechnologytype FROM importtable,site,radioinstallation WHERE (site.sitename = sitesitename AND radioinstallation.siteid=site.id AND radioinstallationlastmodified>radioinstallation.lastmodified AND radioinstallation.sector = radioinstallationsector); ");

	// update all of the radioinstallations based on its sector and the site id
	printf("2\n");
	execSQLCommand("UPDATE radioinstallation SET  lastmodified=radioinstallationlastmodified,sector=radioinstallationsector, permanent=radioinstallationpermanent,techkey=radioinstallationtechkey,eirp=radioinstallationeirp, diversity=radioinstallationdiversity,txpower=radioinstallationtxpower,txlosses=radioinstallationtxlosses, txantennaheight=radioinstallationtxantennaheight,txantpatternkey=radioinstallationtxantpatternkey,txbearing=radioinstallationtxbearing, txmechtilt=radioinstallationtxmechtilt,rxsensitivity=radioinstallationrxsensitivity,rxlosses=radioinstallationrxlosses, rxantennaheight=radioinstallationrxantennaheight,rxantpatternkey=radioinstallationrxantpatternkey,rxbearing=radioinstallationrxbearing, rxmechtilt=radioinstallationrxmechtilt,btlplot=radioinstallationbtlplot,flaga=radioinstallationflaga, flagb=radioinstallationflagb,flagc=radioinstallationflagc FROM  tmpupdateradioinstallations WHERE (radioinstallation.siteid = tmpupdateradioinstallations.siteid AND radioinstallation.sector = radioinstallationsector); ");

/* add new entries */
	// create a table with existing siteid and sector combinations (i.e existing radioinstallations)
	printf("3\n");
	dropTable("existri");
	execSQLCommand("CREATE TABLE existri AS SELECT DISTINCT site.sitename, radioinstallation.sector FROM site, radioinstallation WHERE radioinstallation.siteid = site.id");

	// create a table with all the radioinstallations that were created for sites (i.e. no existing radio installation in site)
	printf("4\n");
	dropTable("newinstallations");
	dropTable("newinstallationsTMP");
	execSQLCommand("CREATE TABLE newinstallationsTMP AS SELECT DISTINCT ON (sitesitename, radioinstallationsector) sitesitename,radioinstallationlastmodified,radioinstallationsector, radioinstallationpermanent,radioinstallationeirp,radioinstallationdiversity, radioinstallationtxpower,radioinstallationtxlosses,radioinstallationtxantennaheight,radioinstallationtxantpatternkey, radioinstallationtxbearing,radioinstallationtxmechtilt,radioinstallationrxsensitivity,radioinstallationrxlosses, radioinstallationrxantennaheight,radioinstallationrxantpatternkey,radioinstallationrxbearing,radioinstallationrxmechtilt, radioinstallationbtlplot,radioinstallationflaga,radioinstallationflagb,radioinstallationflagc,txpatternfile,rxpatternfile,technologytechnologytype  FROM importtable WHERE (sitesitename NOT IN (SELECT sitename FROM existri)) OR (radioinstallationsector NOT IN (SELECT sector FROM existri WHERE sitename = sitesitename));");

	// resolve the techkey
	printf("4.1\n");
	execSQLCommand("DROP TABLE IF EXISTS tmptechkey");
	execSQLCommand("CREATE TABLE tmptechkey AS SELECT id, technologytype FROM technology;");

	// merge the keys with the table
	printf("4.4\n");
	dropTable("newinstallationswithTech");
	execSQLCommand("CREATE TABLE newinstallationswithTech AS SELECT * FROM newinstallationsTMP LEFT OUTER JOIN tmptechkey ON technologytype = technologytechnologytype;");
	execSQLCommand("ALTER TABLE newinstallationswithTech DROP COLUMN technologytype");
	execSQLCommand("ALTER TABLE newinstallationswithTech RENAME id TO radioinstallationtechkey");

	// create the new installations table
	execSQLCommand("CREATE TABLE newinstallations AS SELECT * FROM newinstallationswithTech");


	// create a temporary table 
	printf("5\n");
	dropTable("tmpantennapatterntable");
	execSQLCommand("CREATE TABLE tmpantennapatterntable AS SELECT id, patternfile FROM antennapattern");

	// create a table with all of the same columns as above, but remove the antennapatternfile column and fill in radioinstallationantennapatternkey
	execSQLCommand("DROP TABLE IF EXISTS newinstallationswithantennaB");
	execSQLCommand("DROP TABLE IF EXISTS newinstallationswithantennaA");
	printf("6\n");
	dropTable("newinstallationswithantennaA");
	execSQLCommand("CREATE TABLE newinstallationswithantennaA AS SELECT * FROM newinstallations LEFT OUTER JOIN tmpantennapatterntable ON txpatternfile = tmpantennapatterntable.patternfile;");

	execSQLCommand("ALTER TABLE newinstallationswithantennaA DROP COLUMN txpatternfile");
	execSQLCommand("ALTER TABLE newinstallationswithantennaA DROP COLUMN patternfile");
	execSQLCommand("ALTER TABLE newinstallationswithantennaA RENAME id TO txantpatternkey");

	printf("6.5\n");
	execSQLCommand("CREATE TABLE newinstallationswithantennaB AS SELECT * FROM newinstallationswithantennaA LEFT OUTER JOIN tmpantennapatterntable ON rxpatternfile = tmpantennapatterntable.patternfile;");

	execSQLCommand("ALTER TABLE newinstallationswithantennaB DROP COLUMN rxpatternfile");
	execSQLCommand("ALTER TABLE newinstallationswithantennaB RENAME id TO rxantpatternkey");

	//ALTER TABLE tablef RENAME antennapatternpatternfile TO txpatternfile
#if 0
	dropTable("newinstallationswithantenna");
	execSQLCommand("CREATE TABLE newinstallationswithantenna AS SELECT * FROM newinstallations LEFT OUTER JOIN tmpantennapatterntable ON antennapatternpatternfile = tmpantennapatterntable.patternfile;");
	printf("7\n");
	execSQLCommand("ALTER TABLE newinstallationswithantenna DROP COLUMN patternfile");
	printf("8\n");
	execSQLCommand("ALTER TABLE newinstallationswithantenna RENAME COLUMN id TO newinstallationswithantennaid");
#endif

	// add the new radio installations to the sites
	printf("9\n");
	dropTable("tmpsi");
	execSQLCommand("CREATE TABLE tmpsi AS SELECT DISTINCT  radioinstallationlastmodified,site.id,radioinstallationsector,radioinstallationpermanent, radioinstallationtechkey,radioinstallationeirp,radioinstallationdiversity,radioinstallationtxpower, radioinstallationtxlosses,radioinstallationtxantennaheight,txantpatternkey,rxantpatternkey,radioinstallationtxbearing, radioinstallationtxmechtilt,radioinstallationrxsensitivity,radioinstallationrxlosses,radioinstallationrxantennaheight, radioinstallationrxantpatternkey,radioinstallationrxbearing,radioinstallationrxmechtilt, radioinstallationbtlplot,radioinstallationflaga,radioinstallationflagb,radioinstallationflagc FROM newinstallationswithantennaB,site WHERE (sitesitename = sitename)");

	printf("10\n");
	execSQLCommand("ALTER TABLE tmpsi RENAME COLUMN id TO siteid");


	// add a new id key to the table
/*	execSQLCommand("ALTER TABLE tmpsi ADD COLUMN tid INTEGER;");

	// set the keys to a random value
	execSQLCommand("UPDATE tmpsi SET tid = RANDOM()*2E9;");*/

	// insert into the database
	execSQLCommand("INSERT INTO radioinstallation (lastmodified,siteid,sector, permanent,techkey,eirp, diversity,txpower,txlosses, txantennaheight,txantpatternkey,txbearing, txmechtilt,rxsensitivity,rxlosses, rxantennaheight,rxantpatternkey,rxbearing, rxmechtilt,btlplot,flaga, flagb,flagc) SELECT  DISTINCT  radioinstallationlastmodified,siteid,radioinstallationsector,radioinstallationpermanent, radioinstallationtechkey,radioinstallationeirp,radioinstallationdiversity,radioinstallationtxpower, radioinstallationtxlosses,radioinstallationtxantennaheight,txantpatternkey,radioinstallationtxbearing, radioinstallationtxmechtilt,radioinstallationrxsensitivity,radioinstallationrxlosses,radioinstallationrxantennaheight, rxantpatternkey,radioinstallationrxbearing,radioinstallationrxmechtilt, radioinstallationbtlplot,radioinstallationflaga,radioinstallationflagb,radioinstallationflagc FROM tmpsi ;");

	printf("11\n");
/*
	execSQLCommand("INSERT INTO radioinstallation (lastmodified,siteid,sector, permanent,techkey,eirp, diversity,txpower,txlosses, txantennaheight,txantpatternkey,txbearing, txmechtilt,rxsensitivity,rxlosses, rxantennaheight,rxantpatternkey,rxbearing, rxmechtilt,btlplot,flaga, flagb,flagc) SELECT  DISTINCT  radioinstallationlastmodified,siteid,radioinstallationsector,radioinstallationpermanent, radioinstallationtechkey,radioinstallationeirp,radioinstallationdiversity,radioinstallationtxpower, radioinstallationtxlosses,radioinstallationtxantennaheight,newinstallationswithantennaid,radioinstallationtxbearing, radioinstallationtxmechtilt,radioinstallationrxsensitivity,radioinstallationrxlosses,radioinstallationrxantennaheight, radioinstallationrxantpatternkey,radioinstallationrxbearing,radioinstallationrxmechtilt, radioinstallationbtlplot,radioinstallationflaga,radioinstallationflagb,radioinstallationflagc FROM tmpsi ;");*/

#if 0
	execSQLCommand("INSERT INTO radioinstallation (lastmodified,siteid,sector, permanent,techkey,eirp, diversity,txpower,txlosses, txantennaheight,txantpatternkey,txbearing, txmechtilt,rxsensitivity,rxlosses, rxantennaheight,rxantpatternkey,rxbearing, rxmechtilt,btlplot,flaga, flagb,flagc) SELECT DISTINCT  radioinstallationlastmodified,site.id,radioinstallationsector,radioinstallationpermanent, radioinstallationtechkey,radioinstallationeirp,radioinstallationdiversity,radioinstallationtxpower, radioinstallationtxlosses,radioinstallationtxantennaheight,newinstallationswithantennaid,radioinstallationtxbearing, radioinstallationtxmechtilt,radioinstallationrxsensitivity,radioinstallationrxlosses,radioinstallationrxantennaheight, radioinstallationrxantpatternkey,radioinstallationrxbearing,radioinstallationrxmechtilt, radioinstallationbtlplot,radioinstallationflaga,radioinstallationflagb,radioinstallationflagc FROM newinstallationswithantenna,site WHERE (sitesitename = sitename);");
#endif

}
예제 #6
0
int main()
{
	struct dbSysHead head;
	long fid1, fid2;

	/*
	≥ı ºªØ£¨»ª∫Û¥Ú”°≥ˆµ±«∞œµÕ≥µƒ–≈œ¢
	*/
	init_database(&head);
	showDesc(&head);

//	printf("create file1...\n");
	
	showFileDesc(&head);
/*	printf("extend 10 pages for file1...\n");
	extendFileSpace(&head, fid1, 10);//¿©’π Æ“≥
	showFileDesc(&head);
	printf("extend 10 pages for file1...\n");
	extendFileSpace(&head, fid1, 10);//‘Ÿ¿©’π Æ“≥
	showFileDesc(&head);

	printf("create file2...\n");
	fid2 = creatFileSpace(&head);
	showFileDesc(&head);
	printf("extend 10 pages for file2...\n");
	extendFileSpace(&head, fid2, 10);
	showFileDesc(&head);
	printf("extend 10 pages for file2...\n");
	extendFileSpace(&head, fid2, 10);
	showFileDesc(&head);

	printf("delete file1...\n");
	recyFileSpace(&head, fid1);
	showFileDesc(&head);
	printf("delete file2...\n");
	recyFileSpace(&head, fid2);
	showFileDesc(&head);*/
    //use dictID to scan file1
    /*
     int dictID = 1;
     int scanPointer = 0;
     int rec_length = head.redef[dictID].getRecordLength();
     printf("attributeName::%s", head.redef[dictID].getAttributeByNo(0).getName());
     RecordCursor scanTable(&head, 1, rec_length, 0);
     char * one_Row_ = (char *)malloc(sizeof(char)*rec_length);
     while (true == scanTable.getNextRecord(one_Row_)) { //only scan
     scanPointer ++;
     if(scanPointer > 230)
     getOneRecord(one_Row_, head.redef[dictID]); //get each attribute value and print
     }
     free(one_Row_);
     */
/*
    fid1 = creatFileSpace(&head);//Œ™Œƒº˛“ª∑÷≈‰ø’º‰
    fid2 = creatFileSpace(&head);
	
    if(initTable(&head, FIRST_FID) == 0)
		printf("1 initTable: customer.tbl\n");
	if(showTable(&head, "customer") == -1 )
		printf("2 showTable: customer\n");
    
    if(initTable(&head, FIRST_FID+1) == 0)
        printf("1 initTable: nation.tbl\n");
    if(showTable(&head, "nation") == -1 )
        printf("2 showTable: nation\n");
*/

    if(createTable(&head) == -1)
        printf("Create Table1 failed\n");
    if(createTable(&head) == -1)
        printf("Create Table2 failed\n");
    if(createTable(&head) == -1)
        printf("Create Table3 failed\n");
 /*
    struct eachAttribute * nation_att = new struct eachAttribute[12];
    strcpy(nation_att[0].attribute_name_,"custkey");
    nation_att[0].attribute_type_ = 1;
    nation_att[0].attribute_length_ = 4;
    strcpy(nation_att[1].attribute_name_,"name");
    nation_att[1].attribute_type_ = 2;
    nation_att[1].attribute_length_ =32;
    strcpy(nation_att[2].attribute_name_,"address");
    nation_att[2].attribute_type_ = 2;
    nation_att[2].attribute_length_ =40;
    strcpy(nation_att[3].attribute_name_,"nationkey");
    nation_att[3].attribute_type_ = 1;
    nation_att[3].attribute_length_ = 4;
    strcpy(nation_att[4].attribute_name_,"phone");
    nation_att[4].attribute_type_ = 2;
    nation_att[4].attribute_length_ =16;
    strcpy(nation_att[5].attribute_name_,"acctbal");
    nation_att[5].attribute_type_ = 2;
    nation_att[5].attribute_length_ =64;
    strcpy(nation_att[6].attribute_name_,"mktsemgent");
    nation_att[6].attribute_type_ = 2;
    nation_att[6].attribute_length_ =12;
    strcpy(nation_att[7].attribute_name_,"comment");
    nation_att[7].attribute_type_ = 2;
    nation_att[7].attribute_length_ =128;
    if (createTable( &head, "customer", "TianzhenWu",  8, nation_att) == -1) {
        printf("Create Table failed\n");
    }

    struct eachAttribute * region_att = new struct eachAttribute[3];
    strcpy(region_att[0].attribute_name_,"regionkey");
    region_att[0].attribute_type_ = 1;
    region_att[0].attribute_length_ = 4;
    strcpy(region_att[1].attribute_name_,"regionname");
    region_att[1].attribute_type_ = 2;
    region_att[1].attribute_length_ = 12;
    strcpy(region_att[2].attribute_name_,"regioncomment");
    region_att[2].attribute_type_ = 2;
    region_att[2].attribute_length_ = 152;
    if (createTable( &head, "region", "Mengxi", 3, region_att) == -1) {
        printf("Create Table failed\n");
    }
    */
    relation * temp_data_dict = new relation[MAX_FILE_NUM];
    //read customer.tbl and write into our file1, 一次性
//    loaddata(&head, FIRST_FID);
    loaddata(&head, FIRST_FID + 1);
    loaddata(&head, FIRST_FID + 2);
    sysUpdate(&head);

    insertOneTuple(&head, "customer", "501|Customer#000000501|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.H|");
    
    insertOneTuple(&head, "customer", "1002|Customer#000001001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.HH|");
    
    insertOneTuple(&head, "customer", "1003|Customer#000001002|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets.HHH|");
//    sysUpdate(&head);

    //Scan Table
    int customer_scan = -1;
    customer_scan = TableScan(&head, temp_data_dict, "customer");
    if (customer_scan>=0) {
        printf("tablescan succeed!\n");
    }
    printTempTable(&head, temp_data_dict,0);
    //char attribute_list[3][NAMELENGTH] = {"address", "name", "custkey"};
    //if(project(&head, temp_data_dict, customer_scan, 3, attribute_list)>=0)
    //    printf("project succeed!\n");
    //for each old table, only one time SPJ operator allowed, because it will be freed by this SPJ operator.
    /*
    printf("start tableScanEqualFilter()...\n");
    relation filter_result1;
    if(true == tableScanEqualFilter(&head, &temp_data_dict[0],"custkey","3", &filter_result1)){
        printf("tableScanEqualFilter()\n");
    }

    relation filter_result2;
    if(true == tableScanEqualFilter(&head, &temp_data_dict[0],"name","Customer#000000009", &filter_result2)){
        printf("tableScanEqualFilter()\n");
    }

    relation filter_result3;
    if(true == tableScanScopeFilter(&head,  &temp_data_dict[0],"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&filter_result3)){
        printf("tableScanScopeFilter()\n");
    }
    RecordCursorTmp t2(&head,-2,filter_result3.getRecordLength(), - filter_result3.fileID,filter_result3.getRecordNum());
    char * one_Row_ = (char *)malloc(sizeof(char)* filter_result3.getRecordLength());
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &filter_result3); //get each attribute value and print
    }
    free(one_Row_);
*/
    

/*
    //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1]
    int buffer_ID_ = - temp_data_dict[1].fileID;   //find which buffer
    int record_num_ = temp_data_dict[1].getRecordNum();
    int record_len_ = temp_data_dict[1].getRecordLength();
    RecordCursorTmp t1(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t1.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[1]); //get each attribute value and print
    }
    free(one_Row_);
*//*
printf("customer_scan:%d\n",customer_scan);
    	deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",LESS_THAN,0);

    printf("start tableScanEqualFilter()...\n");
    
    int filterFlag=-1;
//    filterFlag = tableScanSemiscopeFilter(&head, temp_data_dict, customer_scan,"custkey","3",LESS_THAN);

    filterFlag = tableScanSemiscopeFilter(&head, temp_data_dict,customer_scan, "name","Customer#000000009",NOT_MORE_THAN);

    int buffer_ID_,record_num_,record_len_; 
    buffer_ID_ = - temp_data_dict[filterFlag].fileID;   //find which buffer
    record_num_ = temp_data_dict[filterFlag].getRecordNum();
    record_len_ = temp_data_dict[filterFlag].getRecordLength();
    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        //printf("%s\n",one_Row_);
	//if(strcpy(one_Row_,"\0") == 0)
           // break;
    //    getOneRecord(one_Row_, &temp_data_dict[filterFlag]); //get each attribute value and print
    }
    free(one_Row_);
 printf("HERE~~~\n\n");
    deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",EQUAL,0); 
    customer_scan = -1;
    customer_scan = TableScan(&head, temp_data_dict, "customer");
    if (customer_scan>=0) {
        printf("tablescan succeed!\n");
    }
    printf("customer_scan:%d\n",customer_scan);
    buffer_ID_ = - temp_data_dict[customer_scan].fileID;   //find which buffer
    record_num_ = temp_data_dict[customer_scan].getRecordNum();
    record_len_ = temp_data_dict[customer_scan].getRecordLength();
    RecordCursorTmp t3(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    while (true == t3.getNextRecord(one_Row_)) { //only scan
        //printf("%s\n",one_Row_);
        //if(strcpy(one_Row_,"\0") == 0)
           // break;
        getOneRecord(one_Row_, &temp_data_dict[filterFlag]); //get each attribute value and print
    }
    free(one_Row_);


//    TableScan(&head, FIRST_FID + 1, temp_data_dict);
/*
    //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1]
    buffer_ID_ = - temp_data_dict[1].fileID;   //find which buffer
    record_num_ = temp_data_dict[1].getRecordNum();
    record_len_ = temp_data_dict[1].getRecordLength();
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    RecordCursorTmp t2(&head,2,record_len_,buffer_ID_,record_num_);
    one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[1]); //get each attribute value and print
    }
    free(one_Row_);
 */
    // create index
/*
    printf("recordNum:%d\n",head.redef[dictID].recordNum);
	if(true == createIndexOn(&head, 1, "custkey")){
		char* index_filename= "b_plus_tree_index_1custkey.dat";
		
		FILE* fp = fopen(index_filename,"rb+");
		printf("search(fp,-10):%d\n",search(fp,-10));
		printf("search(fp,1):%d\n",search(fp,1));
		printf("search(fp,2):%d\n",search(fp,2));
		printf("search(fp,50):%d\n",search(fp,50));
		display(fp);
		fclose(fp);
	}
	
    // insert one record
	relationDefine dic = head.redef[0];
    int size_per_record = dic.recordLength;
    char *oneRec = (char *)malloc(sizeof(char)*size_per_record);
        
	char * insertTest = (char *)malloc(sizeof(char)* 256);
    strcpy(insertTest,"501|Customer#000000001|IVhzIApeRb ot,c,E|15|25-989-741-2988|711.56|BUILDING|to the even, regular platelets. regular, ironic epitaphs nag eHHHHHH|");
    parserOneLineFromFile(insertTest, oneRec, dic);
    insertOneRecord(&head, 1, oneRec);//≤»ΓªÃı ˝æ›£¨◊‘∂Ø∏¸–¬À˜“˝
	free(insertTest);
    free(oneRec);
    
    // look up key in index
	char* index_filename= "b_plus_tree_index_1custkey.dat";
	FILE* fp = fopen(index_filename,"rb+");
	int pos = search(fp,501);
	printf("pos:::%d\n",pos);
	fclose(fp);
 
	one_Row_ = (char *)malloc(sizeof(char)*rec_length);
	rdFile( &head, 0, 1, pos, rec_length,one_Row_);
	printf("reading from index:\n");
	getOneRecord(one_Row_, dic);
*/
 /*   //nestloop_cp
    relation result;
    result.init("cus_nation", "zhangwenhui");
    /*merge_relation_cp(&head,temp_data_dict[0],temp_data_dict[1],&result);
     showRelation(&result);
     
     nestloop_cp(&head, &temp_data_dict[0],&temp_data_dict[1], &result);*/
/*
    //nestloop_equal
    merge_relation(&head,temp_data_dict[0],temp_data_dict[1],&result);
    //nestloop_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    //nestloop_bigger(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    //nestloop_smaller(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    nestloop_smaller_or_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");
    //nestloop_bigger_or_equal(&head, &temp_data_dict[0],&temp_data_dict[1], &result,"nationkey");

*/
    //project customer
/*	relation c_result;
	c_result.init("customer", "TianzhenWu");
	c_result.insertAttribute("name", 2, 64);
    c_result.insertAttribute("nationkey",1,4);
	c_result.insertAttribute("phone", 2, 64);
	showRelation(&c_result);
	project(&head, &temp_data_dict[0], &c_result);

    //project nation.tbl
    relation n_result;
    n_result.init("nation", "MengxiZhou");
    n_result.insertAttribute("nationkey", 1, 4);
    n_result.insertAttribute("name", 2, 16);
    n_result.insertAttribute("regionkey", 1, 4);
    showRelation(&n_result);
    project(&head, &temp_data_dict[1], &n_result);
*/
 /*
//    relation hashjoin_result_;
//    hashjoin_result_.init("customer_nation_hash", "irenewu");
//    hashjoin(&head, &c_result, &n_result, &hashjoin_result_,"nationkey");
    
    relation result;
    result.init("sortmergejoin zmx","zmx");
//    	merge_relation(&head, c_result, n_result, &result);
//    result.insertAttribute("custkey", 1, 4);
    result.insertAttribute("name", 2, 32);
//    result.insertAttribute("address", 2, 40);
    result.insertAttribute("nationkey", 1, 4);
    result.insertAttribute("phone", 2, 16);
//    result.insertAttribute("acctbal", 2, 64);
//    result.insertAttribute("mktsegment", 2, 12);
//    result.insertAttribute("comment", 2, 128);
    result.insertAttribute("nationkey", 1, 4);
    result.insertAttribute("name", 2, 32);
    result.insertAttribute("regionkey", 1, 4);
//    result.insertAttribute("comment", 2, 160);
    showRelation(&result);
    sortmergejoin(&head, &c_result, &n_result, "nationkey", &result);
    
    int buffer_ID_ = - result.fileID;   //find which buffer
    int record_num_ = result.getRecordNum();
    int record_len_ = result.getRecordLength();
    RecordCursorTmp t2(&head,-11,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &result); //get each attribute value and print
    }
    free(one_Row_);
/*
    //filter
    printf("start tableScanEqualFilter()...\n");
    
    if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"custkey","3",&temp_data_dict[5])){
        printf("tableScanEqualFilter()\n");
    }

    if(true == tableScanEqualFilter(&head, FIRST_FID, temp_data_dict,"name","Customer#000000009",&temp_data_dict[5])){
        printf("tableScanEqualFilter()\n");
    }
  
    buffer_ID_ = - temp_data_dict[5].fileID;   //find which buffer
    record_num_ = temp_data_dict[5].getRecordNum();
    record_len_ = temp_data_dict[5].getRecordLength();
    RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_);
    cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
    char * one_Row_ = (char *)malloc(sizeof(char)*record_len_);
    while (true == t2.getNextRecord(one_Row_)) { //only scan
        getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print
    }
    free(one_Row_);
    //head.buff[buffer_ID_].emptyOrnot = false;
 
    if(true == tableScanScopeFilter(&head, FIRST_FID, temp_data_dict,"custkey","220",NOT_MORE_THAN,"230",LESS_THAN,&temp_data_dict[5])){
        printf("tableScanScopeFilter()\n");
    }
*/

    showFileDesc(&head);
    dropTable(&head,"customer");
    deleteAllTuples(&head,"nation");
    dropTable(&head,"nation");

/*
   if(true == createIndexOn(&head, FIRST_FID, "custkey")){
        char* index_filename = "/Users/Irene/Desktop/b_plus_tree_index_1custkey.dat";
        FILE* fp;
        int pos;

        if( !(fp = fopen(index_filename,"rb+")))
                printf("error indexFile name.\n");
        printf("search(fp,-10):%d\n",search(fp,-10));
        printf("search(fp,1):%d\n",search(fp,1));
        printf("search(fp,2):%d\n",search(fp,2));
        printf("search(fp,50):%d\n",search(fp,50));
        //display(fp);


        deleteRecordWhere(&head, FIRST_FID, "name", "Customer#000000005",LESS_THAN,0);
        pos = search(fp,5);

        fclose(fp);
        printf("%d\n",pos);

        printf("start indexScanEqualFilter()...\n");
        if(true == indexScanEqualFilter(&head, FIRST_FID, "custkey","4",&temp_data_dict[5])){
          printf("indexScanEqualFilter(9) end!\n");

          buffer_ID_ = - temp_data_dict[5].fileID;   //find which buffer
          record_num_ = temp_data_dict[5].getRecordNum();
          record_len_ = temp_data_dict[5].getRecordLength();
          RecordCursorTmp t3(&head,1,record_len_,buffer_ID_,record_num_);
          cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl;
          one_Row_ = (char *)malloc(sizeof(char)*record_len_);
          while (true == t3.getNextRecord(one_Row_)) { //only scan
                if(one_Row_[0] == '$')
                        printf("empty\n");
           //getOneRecord(one_Row_, &temp_data_dict[5]); //get each attribute value and print
          }
          free(one_Row_);
          head.buff[buffer_ID_].emptyOrnot = true;

        }
    }//end of createIndexOn if
*/
    sysUpdate(&head);
    showFileDesc(&head);
    exit_database(&head);
	system("pause");
	return 0;
}
예제 #7
0
int testWorker(NDBT_Context* ctx, NDBT_Step* step)
{
  /* Run as a 'T1' testcase - do nothing for other tables */
  if (strcmp(ctx->getTab()->getName(), "T1") != 0)
    return NDBT_OK;

  /* Worker step to run in a separate thread for
   * blocking activities
   * Generally the blocking of the DIH table definition flush
   * blocks the completion of the drop table/node restarts,
   * so this must be done in a separate thread to avoid
   * deadlocks.
   */
  
  while (!ctx->isTestStopped())
  {
    ndbout_c("Worker : waiting for request...");
    ctx->getPropertyWait("DIHWritesRequest", 1);
  
    if (!ctx->isTestStopped())
    {
      Uint32 req = ctx->getProperty("DIHWritesRequestType", (Uint32)0);

      switch ((Tasks) req)
      {
      case DROP_TABLE_REQ:
      {
        /* Drop table */
        ndbout_c("Worker : dropping table");
        if (dropTable(ctx, step, 2) != NDBT_OK)
        {
          return NDBT_FAILED;
        }
        ndbout_c("Worker : table dropped.");
        break;
      }
      case MASTER_RESTART_REQ:
      {
        ndbout_c("Worker : restarting Master");
        
        NdbRestarter restarter;
        int master_nodeid = restarter.getMasterNodeId();
        ndbout_c("Worker : Restarting Master (%d)...", master_nodeid);
        if (restarter.restartOneDbNode2(master_nodeid, 
                                        NdbRestarter::NRRF_NOSTART |
                                        NdbRestarter::NRRF_FORCE |
                                        NdbRestarter::NRRF_ABORT) ||
            restarter.waitNodesNoStart(&master_nodeid, 1) ||
            restarter.startAll())
        {
          ndbout_c("Worker : Error restarting Master.");
          return NDBT_FAILED;
        }
        ndbout_c("Worker : Waiting for master to recover...");
        if (restarter.waitNodesStarted(&master_nodeid, 1))
        {
          ndbout_c("Worker : Error waiting for Master restart");
          return NDBT_FAILED;
        }
        ndbout_c("Worker : Master recovered.");
        break;
      }
      case SLAVE_RESTART_REQ:
      {
        NdbRestarter restarter;
        int slave_nodeid = restarter.getRandomNotMasterNodeId(rand());
        ndbout_c("Worker : Restarting non-master (%d)...", slave_nodeid);
        if (restarter.restartOneDbNode2(slave_nodeid, 
                                        NdbRestarter::NRRF_NOSTART |
                                        NdbRestarter::NRRF_FORCE |
                                        NdbRestarter::NRRF_ABORT) ||
            restarter.waitNodesNoStart(&slave_nodeid, 1) ||
            restarter.startAll())
        {
          ndbout_c("Worker : Error restarting Slave.");
          return NDBT_FAILED;
        }
        ndbout_c("Worker : Waiting for slave to recover...");
        if (restarter.waitNodesStarted(&slave_nodeid, 1))
        {
          ndbout_c("Worker : Error waiting for Slave restart");
          return NDBT_FAILED;
        }
        ndbout_c("Worker : Slave recovered.");
        break;
      }
      default:
      { 
        break;
      }
      }
    }
    ctx->setProperty("DIHWritesRequestType", (Uint32) 0);
    ctx->setProperty("DIHWritesRequest", (Uint32) 2);
  }
  
  ndbout_c("Worker, done.");
  return NDBT_OK;
}
예제 #8
0
/*
 * main -- データ操作モジュールのテスト
 */
int main(int argc, char **argv)
{
    char tableName[20];
    TableInfo tableInfo;
    int i;

    /* ファイルモジュールを初期化する */
    if (initializeFileModule() != OK) {
        fprintf(stderr, "Cannot initialize file module.\n");
        exit(1);
    }

    /* データ定義ジュールを初期化する */
    if (initializeDataDefModule() != OK) {
        fprintf(stderr, "Cannot initialize data definition module.\n");
        exit(1);
    }

    /* データ操作ジュールを初期化する */
    if (initializeDataManipModule() != OK) {
        fprintf(stderr, "Cannot initialize data manipulation module.\n");
        exit(1);
    }

    /*
     * このプログラムの前回の実行の時のデータ定義残っている可能性があるので、
     * とりあえず削除する
     */
    dropTable(TABLE_NAME);

    /*
     * 以下のテーブルを作成
     * create table student (
     *   id string,
     *   name string,
     *   age int,
     *   address string
     * )
     */
    strcpy(tableName, TABLE_NAME);
    i = 0;

    strcpy(tableInfo.fieldInfo[i].name, "id");
    tableInfo.fieldInfo[i].dataType = TYPE_VARCHAR;
    i++;

    strcpy(tableInfo.fieldInfo[i].name, "name");
    tableInfo.fieldInfo[i].dataType = TYPE_VARCHAR;
    i++;

    strcpy(tableInfo.fieldInfo[i].name, "age");
    tableInfo.fieldInfo[i].dataType = TYPE_INT;
    i++;

    strcpy(tableInfo.fieldInfo[i].name, "weight");
    tableInfo.fieldInfo[i].dataType = TYPE_DOUBLE;
    i++;

    strcpy(tableInfo.fieldInfo[i].name, "address");
    tableInfo.fieldInfo[i].dataType = TYPE_VARCHAR;
    i++;

    tableInfo.numField = i;

    /* テーブルの作成 */
    if (createTable(tableName, &tableInfo) != OK) {
        /* テーブルの作成に失敗 */
        fprintf(stderr, "Cannot create table.\n");
        exit(1);
    }

    /* 挿入テスト */
    fprintf(stderr, "test1: Start\n\n");
    if (test1() == OK) {
        fprintf(stderr, "test1: OK\n\n");
    } else {
        fprintf(stderr, "test1: NG\n\n");
    }

    /* 検索テスト */
    fprintf(stderr, "test2: Start\n\n");
    if (test2() == OK) {
        fprintf(stderr, "test2: OK\n\n");
    } else {
        fprintf(stderr, "test2: NG\n\n");
    }

    /* 削除テスト */
    fprintf(stderr, "test3: Start\n\n");
    if (test3() == OK) {
        fprintf(stderr, "test3: OK\n\n");
    } else {
        fprintf(stderr, "test3: NG\n\n");
    }

    /* 後始末 */
    dropTable(TABLE_NAME);
    finalizeDataManipModule();
    finalizeDataDefModule();
    finalizeFileModule();
}
예제 #9
0
int main()
{
  // próba po³±czenia
  PGconn *myconnection = PQconnectdb("host=localhost port=5432 dbname=myDb user=mateuszek password=mateuszek");
  //PGconn *myconnection = PQconnectdb("");
  // sprawdzamy status po³±czenia
  if(PQstatus(myconnection) == CONNECTION_OK) {
		printf("connection made\n");
		// informacje o po³±czeniu
		printf("PGDBNAME   = %s\n",PQdb(myconnection));
		printf("PGUSER     = %s\n",PQuser(myconnection));
		//printf("PGPASSWORD = %s\n",PQpass(myconnection));
		printf("PGPASSWORD = ********\n");
		printf("PGHOST     = %s\n",PQhost(myconnection));
		printf("PGPORT     = %s\n",PQport(myconnection));
		printf("OPTIONS    = %s\n",PQoptions(myconnection));
  }
  else{
	  printf("connection failed: %s\n", PQerrorMessage(myconnection));
	  // w razie utraty po³±czenia wywo³anie 
	  // PQreset(myconnection);
	  // zamyka op³±czenie i nawi±zuje je raz jeszcze  
	  // z dotychczasowymi parametrami
	  PQfinish(myconnection);
	  return EXIT_SUCCESS;
	}
  int k=1;
  int choice;
  while (k==1){
	  printf("wpisz: \n");
	  printf("\t '0': aby zakonczyc\n");
	  printf("\t '1' : aby utworzyc tabele\n");
	  printf("\t '2' : aby usunac tabele\n");
	  printf("\t '3' : aby dodac rekord\n");
	  printf("\t '4' : aby edytowac rekord\n");
	  printf("\t '6' : aby wyswietlic wszystkie rekordy\n");
	  printf("\t '7' : wyszukaj pracownika po dacie urodzenia\n");
	  printf("\t '8' : wyszukaj pracownika po stanowisku i nazwisku\n");
	  scanf("\t%d",&choice);
	  switch (choice){
		  case 1 :  system("clear");
					createTable(myconnection);
					break;
		  case 2 :  system("clear");
					dropTable(myconnection);
					break;
		  case 3 :  system("clear");
					addRecord(myconnection);
					break;
		  case 4 :	system("clear");
					editRecord(myconnection);
					break;		
		  case 5 :	system("clear");
					deleteRecord(myconnection);
					break;				
		  case 6 :  system("clear");
					showAllRecords(myconnection);
					break;					
					
		  case 7 :  system("clear");
					searchByBirthDate(myconnection);
					break;			
		  case 8 :  system("clear");
					searchByPosAndSalary(myconnection);
					break;		
		  default:  system("clear");
				    printf("Nieodpowiedni wybor ('%d').\n\n",choice);
	  }
   
  }
}
예제 #10
0
int main(void){
	PGresult *result;
	PGconn   *conn;
	int z;
	conn = PQconnectdb("host=localhost port=5432 dbname=dsienkiewicz user=dsienkiewicz password=aplikacje");
	
	if(PQstatus(conn) == CONNECTION_OK) {
		printf("connection made\n");
    
		//czyszczenie ekranu
		system("clear");

		//menu
		do{
			printf("\n 1 - Create table");
			printf("\n 2 - Add sample data");
			printf("\n 3 - Print");
			printf("\n 4 - Add");
			printf("\n 5 - Drop from table");
			printf("\n 6 - Update");
			printf("\n 7 - Search");
                        printf("\n 8 - Add Trigger");
                        printf("\n 9 - Drop Trigger");
			printf("\n 10 - Drop Table");
			printf("\n 11 - Exit");
			printf("\n choice: ");
			scanf("%d", &z);
			
			switch(z){

				case 1: doSQL(conn, "CREATE TABLE cars(id_car SERIAL PRIMARY KEY, make VARCHAR(20), model VARCHAR(20), price money, capacity numeric(8,1), yop date);");
					break;
				case 2: addData(conn);
					break;
				case 3:	print(conn);
					break;
				case 4: add(conn);
					break;
				case 5: drop(conn);
					break;
				case 6:	update(conn);
					break;
				case 7: search(conn);
					break;
				case 8: createTrigger(conn);
					break;
				case 9: delTrigger(conn);
					break;
				case 10: dropTable(conn);
					break;
			}

		}while(z != 11);
		
		printf("Bye, bye ...\n");
	}
	
	else
		printf("connection failed: %s\n", PQerrorMessage(conn));

	PQfinish(conn);
	return EXIT_SUCCESS;
}
void TableListWidget::dropActionTriggered()
{
	emit dropTable( this->currentItem()->text());
}