RetCode DropTableExec::Execute(ExecutedResult* exec_result) { RetCode ret = rSuccess; SemanticContext sem_cnxt; ret = drop_table_ast_->SemanticAnalisys(&sem_cnxt); if (rSuccess != ret) { exec_result->error_info_ = "Semantic analysis error.\n" + sem_cnxt.error_msg_; exec_result->status_ = false; LOG(WARNING) << "semantic analysis error result= : " << ret; cout << "semantic analysis error result= : " << ret << endl; return ret; } Catalog* local_catalog = Environment::getInstance()->getCatalog(); AstDropTableList* table_list = dynamic_cast<AstDropTableList*>(drop_table_ast_->table_list_); while (NULL != table_list) { string table_name; if ("" != table_list->table_name_) { // if the table_name is null, then // go to the next element of the // table_list_ // to make consistency, drop the del table first, and then the base table table_name = table_list->table_name_; if (CheckBaseTbl(table_name)) { // drop the base table ret = DropTable(table_name + "_DEL"); if (ret == rSuccess) { cout << table_name + "_DEL is dropped from this database!" << endl; ret = DropTable(table_name); cout << table_name + "is dropped from this database!" << endl; } else { DropTable(table_name + "_DEL"); DropTable(table_name); } } else { // drop the del table only, but the information in the catalog // does not need to be removed ret = DeleteTableFiles(table_name); // todo (miqni 2016.1.28) to delete the del table from memory cout << table_name + "_DeL is dropped from this database!" << endl; } if (ret == rSuccess) { exec_result->info_ = "drop table successfully!"; } else { exec_result->error_info_ = "drop table [" + table_name + "] failed."; exec_result->status_ = false; exec_result->result_ = NULL; return ret; } } table_list = dynamic_cast<AstDropTableList*>(table_list->next_); } local_catalog->saveCatalog(); exec_result->status_ = true; exec_result->result_ = NULL; return ret; }
void API::Switcher(SqlCommand* command){ SqlCommandType command_type = command->command_type(); Info info; // typedef std::chrono::high_resolution_clock Clock; // typedef std::chrono::milliseconds milliseconds; // Clock::time_point t0 = Clock::now(); switch(command_type){ case kSqlInvalid: { info = Info("Invalid Command, Please check your syntax."); break; } case kSqlCreateTable: { info = CreateTable(dynamic_cast<SqlCommandCreateTable *>(command)); break; } case kSqlCreateIndex: { info = CreateIndex(dynamic_cast<SqlCommandCreateIndex *>(command)); break; } case kSqlDeleteFrom: { info = DeleteFrom(dynamic_cast<SqlCommandDeleteFrom *>(command)); break; } case kSqlDropTable: { info = DropTable(dynamic_cast<SqlCommandDropTable *>(command)); break; } case kSqlDropIndex: { info = DropIndex(dynamic_cast<SqlCommandDropIndex *>(command)); break; } case kSqlInsertInto: { info = InsertInto(dynamic_cast<SqlCommandInsertInto *>(command)); break; } case kSqlSelectFrom: { info = SelectFrom(dynamic_cast<SqlCommandSelectFrom *>(command));break; } } info.PrintInfo(); // Clock::time_point t1 = Clock::now(); // milliseconds ms = std::chrono::duration_cast<milliseconds>(t1 - t0); // std::cout<<"time used:"<<ms.count()<<" ms."<<std::endl; }
ResultType TupleSamplesStorage::DeleteSamplesTable( oid_t database_id, oid_t table_id, concurrency::TransactionContext *txn) { auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); bool single_statement_txn = false; if (txn == nullptr) { single_statement_txn = true; txn = txn_manager.BeginTransaction(); } auto catalog = catalog::Catalog::GetInstance(); std::string samples_table_name = GenerateSamplesTableName(database_id, table_id); ResultType result = ResultType::FAILURE; try { result = catalog->DropTable(std::string(SAMPLES_DB_NAME), std::string(DEFAULT_SCHEMA_NAME), samples_table_name, txn); } catch (CatalogException &e) { // Samples table does not exist, no need to drop } if (single_statement_txn) { txn_manager.CommitTransaction(txn); } std::string result_str; if (result == ResultType::SUCCESS) { result_str = "success"; } else { result_str = "false"; } LOG_DEBUG("Drop table %s, result: %s", samples_table_name.c_str(), result_str.c_str()); return result; }
int SM_Manager::Exec(const char *instr) { vector<string> argv; string cur; cout << instr << endl; for (int i = 0; ; i++) { if (instr[i] == ' ' || instr[i] == '(' || instr[i] == ')' || instr[i] == ',' || instr[i] == 0) { if (cur.length() > 0) { argv.push_back(cur); cur = ""; } if (instr[i] == 0){ break; } } else { cur = cur + instr[i]; } } if (argv.size() < 3) return -1; if (argv[0] == "CREATE" && argv[1] =="DATABASE") { CreateDb(argv[2].c_str()); return 0; } if (argv[0] == "DROP" && argv[1] == "DATABASE") { DropDb(argv[2].c_str()); return 0; } if (argv[0] == "USE" && argv[1] == "DATABASE") { CloseDb(); OpenDb(argv[2].c_str()); return 0; } if (argv[0] == "SHOW" && argv[1] == "DATABASE") { ShowDb(argv[2].c_str()); return 0; } if (argv[0] == "CREATE" && argv[1] == "TABLE") { string tablename = argv[2]; vector<AttrInfo> attrs; for (int i = 3; i < argv.size();) { AttrInfo attr; if (argv[i] == "PRIMARY" && argv[i + 1] == "KEY") { attr.primaryKey = true; i += 2; } cout << argv[i] << endl; strcpy(attr.attrName, argv[i].c_str()); i += 1; if (argv[i] == "int") { attr.attrType = MyINT; attr.attrLength = 4; i += 1; cout << "lala" << endl; } else if (argv[i] == "float") { attr.attrType = FLOAT; attr.attrLength = 4; i += 1; } else if (argv[i] == "char") { attr.attrType = STRING; attr.attrLength = atoi(argv[i + 1].c_str()); i += 2; } if (i + 1 < argv.size() && argv[i] == "NOT" && argv[i + 1] == "NULL") { attr.notNull = true; i += 2; } attrs.push_back(attr); } AttrInfo *x = new AttrInfo[attrs.size()]; for (int i = 0; i < attrs.size(); i++) x[i] = attrs[i]; CreateTable(tablename.c_str(), attrs.size(), x); delete x; return 0; } if (argv[0] == "DROP" && argv[1] == "TABLE") { DropTable(argv[2].c_str()); return 0; } if (argv[0] == "SHOW" && argv[1] == "TABLE") { ShowTable(argv[2].c_str()); return 0; } return 0; }
void main(int argc, char ** argv) { SQLHANDLE henv; SQLHANDLE hdbc; SQLHANDLE hstmt; char username[256]; char password[256]; char datasource[256]; unsigned int i, j; char TableName[50]; strcpy(datasource, "SQLServer Express"); //strcpy(datasource, "Microsoft SQL Server"); strcpy(username, "test"); strcpy(password, "test"); strcpy(TableName, "EMPLOYEES_PERFTEST"); /* if (argc < 2) { fprintf (stderr, "Usage: ODBCBatchUpdates username/password@datasource\n\n"); exit(255); } */ /* if (getLoginInfo(argv[1], username, password, datasource) != SQL_SUCCESS) { fprintf (stderr, "Error: ' %s ' invalid login\n", argv[1]); fprintf (stderr, "Usage: ODBCBatchInserts username/password@datasource\n\n"); exit(255); } */ printf("ODBC BATCH UPDATE TEST\n\n"); InitODBCEnv(&henv); ODBCConnect(henv, &hdbc, username, password, datasource); InitODBCStmt(hdbc, &hstmt); printf("\nSETTING UP ENVIRONMENT\n"); printf("Dropping table: %s\n", TableName); DropTable(hstmt, TableName); printf("Creating table: %s\n", TableName); CreateTable(hstmt, TableName); printf("Filling table: %s\n", TableName); BatchInsert(hdbc, hstmt, TableName, 100, 5000); /* printf("\n\n"); printf ("Deleting contents of table"); ClearTable(hstmt, TableName); */ printf("\n\n"); PrintTableHeader(); for (i = 0; i < BatchSizeLen; i++) { for (j = 0; j < NumRecUpdatedLen; j++) { BatchUpdate(hdbc, hstmt, TableName, BatchSize[i], NumRecUpdated[j]); printf(" resetting test..."); ClearTable(hstmt, TableName); BatchInsert(hdbc, hstmt, TableName, 100, 5000); printf("done\n"); } printf ("\n"); } Terminate(henv, hdbc, hstmt); printf("ODBC BATCH UPDATE TEST COMPLETED.\n\n"); printf("===========================================================\n"); printf("Press ENTER to end program..."); getchar(); }