static void daemon_getemail() { if (userID.empty()) { daemon_printf( "%d unknow user id\n", CODE_DENIED ); return; } if (init_database()) { daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED ); return; } std::string sql; sql = "SELECT email FROM user_basic WHERE id="; sql += userID; if (stardictdMain.conn.query(sql.c_str(), sql.length())) { daemon_printf( "%d query failed\n", CODE_DENIED ); return; } MySQLResult *res = stardictdMain.conn.getResult(); if (!res) { daemon_printf( "%d get result failed\n", CODE_DENIED ); return; } DB_ROW row = res->fetchRow(); if (!row) { res->destroy(); daemon_printf( "%d fetch row failed\n", CODE_DENIED ); return; } daemon_printf( "%d\n", CODE_OK ); net_write_str(row[0]); res->destroy(); }
static void daemon_setemail(std::string &email) { if (userID.empty()) { daemon_printf( "%d unknow user id\n", CODE_DENIED ); return; } if (strchr(email.c_str(), '@') == NULL) { daemon_printf( "%d invalid email\n", CODE_DENIED ); return; } if (init_database()) { daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED ); return; } std::string sql; sql = "UPDATE user_basic SET email="; AppendMysql(sql, email.c_str()); sql += " WHERE id="; sql += userID; if (stardictdMain.conn.query(sql.c_str(), sql.length())) { daemon_printf( "%d query failed\n", CODE_DENIED ); return; } daemon_printf( "%d\n", CODE_OK ); }
int main(int argc, char *argv[]) { char *conffile = NULL; int request_kill = 0, show_message = 0; if (!read_parameters(argc, argv, &conffile, &request_kill, &show_message)) { print_usage(argv[0]); return 1; } /* read the config file; conffile = NULL means use the default. */ if (!read_config(conffile)) return 1; /* error reading the config file */ setup_defaults(); if (request_kill) { kill_server(); return 0; } if (show_message) { signal_message(); return 0; } setup_signals(); /* Init files and directories. * Start logging last, so that the log is only created if startup succeeds. */ if (!init_workdir() || !init_database() || !check_database() || !begin_logging()) return 1; if (!settings.nodaemon) { if (daemon(0, 0) == -1) { settings.nodaemon = TRUE; log_msg("could not detach from terminal: %s", strerror(errno)); return 1; } if (!create_pidfile()) return 1; } /* give this process and its children their own process group id for kill() */ setpgid(0, 0); report_startup(); runserver(); /* shutdown */ remove_pidfile(); end_logging(); close_database(); remove_unix_socket(); free_config(); return 0; }
/* *功能:计算运行考核费用分摊 *参数:需要计算运行考核费用分摊的月份 *返回值:-1计算失败,0计算结果有效并插入数据库 * */ int calculate_run_check_cost_collect() { cost_collect_stru *cost_collect17; long long plant_num; printf("\n\n\n"); if(init_database()!=0) return(-1); if(-1==get_unit_info(&cost_collect17,month,&plant_num)) {printf("执行get_unit_info()失败\n");return -1;} if(-1==get_cost_result(month,&cost_collect17, &plant_num)) {printf("执行get_unplan_shutdown_result()失败\n");return -1;} if(-1==write_collect_stru(month, &cost_collect17, &plant_num)) {printf("执行write_collect_stru()失败\n");return -1;} free(cost_collect17); write_act_info("成功","无"); close_database(); printf("\n\n"); }
/* * This is the start of the client handling code. * The server process has accepted a connection and authenticated it. Data from * the client will arrive here via infd and data that should be sent back goes * through outfd. * An instance of NitroHack will run in this process under the control of the * remote player. */ void client_main(int userid, int _infd, int _outfd) { char **gamepaths; int i; infd = _infd; outfd = _outfd; gamefd = -1; init_database(); if (!db_get_user_info(userid, &user_info)) { log_msg("get_user_info error for uid %d!", userid); exit_client("database error"); } gamepaths = init_game_paths(); nh_lib_init(&server_windowprocs, gamepaths); for (i = 0; i < PREFIX_COUNT; i++) free(gamepaths[i]); free(gamepaths); db_restore_options(userid); client_main_loop(); exit_client(NULL); /*NOTREACHED*/ return; }
static void daemon_change_password(std::string &user, std::string &base64_rsa_md5saltsum_old_password, std::string &base64_rsa_md5saltsum_new_password) { std::vector<unsigned char> v; base64_decode(base64_rsa_md5saltsum_old_password, v); std::vector<unsigned char> v2; rsa_decrypt(v, v2, RSA_Public_Key_d, RSA_Public_Key_n); std::string old_passwd; vector_to_string(v2, old_passwd); base64_decode(base64_rsa_md5saltsum_new_password, v); rsa_decrypt(v, v2, RSA_Public_Key_d, RSA_Public_Key_n); std::string new_passwd; vector_to_string(v2, new_passwd); if (new_passwd.length()!=32) { daemon_printf( "%d wrong new password\n", CODE_DENIED ); return; } if (init_database()) { daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED ); return; } std::string sql; if (auth_user != "root") { sql = "SELECT user_md5saltpassword FROM stardict_users WHERE username="******"%d Query failed!\n", CODE_DENIED ); return; } MySQLResult *res = stardictdMain.conn.getResult(); if (!res) { daemon_printf( "%d Get result failed!\n", CODE_DENIED ); return; } DB_ROW row = res->fetchRow(); if (!row) { res->destroy(); daemon_printf( "%d user doesn't exist\n", CODE_DENIED ); return; } if (old_passwd != row[0]) { res->destroy(); daemon_printf( "%d old password is wrong\n", CODE_DENIED ); return; } res->destroy(); } sql = "UPDATE stardict_users SET user_md5saltpassword="******" WHERE username="******"%d Query failed!\n", CODE_DENIED ); return; } daemon_printf( "%d\n", CODE_OK ); }
void print_reason_device_not_supported(void) { char device[PROP_VALUE_MAX]; char build_id[PROP_VALUE_MAX]; const char *check_name; sqlite3_stmt *st; int rc; int i; if (!init_database()) { return; } __system_property_get("ro.product.model", device); __system_property_get("ro.build.display.id", build_id); check_name = NULL; rc = sqlite3_prepare(db, SQL_QUERY_DEVICE, -1, &st, NULL); if (!IS_SQL_ERROR(rc)) { rc = sqlite3_reset(st); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 1, device, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 2, build_id, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = execute_sql(st); } if (!IS_SQL_ERROR(rc)) { check_name = sqlite3_column_text(st, 1); } if (IS_SQL_ERROR(rc)) { printf("%s(%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); } if (check_name) { char check_property_value[PROP_VALUE_MAX]; __system_property_get(check_name, check_property_value); printf("%s (%s %s) is not supported.\n", device, build_id, check_property_value); } else { printf("%s (%s) is not supported.\n", device, build_id); } sqlite3_finalize(st); }
TMNbar_protocol* get_filter_nbar_protocols(int filter_id) { int retc; TMNbar_protocol* return_nbar_protocol = NULL; if(con==NULL) if((retc=init_database())==0) return retc; char query_buffer[QUERY_BUFFER_SIZE]; sprintf(query_buffer, " \ SELECT NbarProtocols.id, NbarProtocols.protocol_name, NbarProtocols.protocol_description, \ NbarProtocols.protocol_id \ FROM NbarProtocols \ INNER JOIN FilterHasNbarProtocols ON FilterHasNbarProtocols.filter_id = '%d' \ AND FilterHasNbarProtocols.nbar_protocol_id = NbarProtocols.id; \ ", filter_id); mysql_query(con, query_buffer); //printf("%s\n", mysql_error(con)); MYSQL_RES* result = mysql_store_result(con); //printf("NBPnum-rows: %d\n", mysql_num_rows(result)); if(mysql_num_rows(result)==0) return NULL; MYSQL_ROW row; TMNbar_protocol* nbar_protocol; while((row = mysql_fetch_row(result))) { TMNbar_protocol* last_nbar_protocol = nbar_protocol; nbar_protocol = (TMNbar_protocol*)malloc(sizeof(TMNbar_protocol)); if(nbar_protocol==NULL) return NULL; nbar_protocol->next=NULL; if(return_nbar_protocol==NULL) return_nbar_protocol = nbar_protocol; else last_nbar_protocol->next = nbar_protocol; if(row[0]!=NULL) nbar_protocol->id = atoi(row[0]); string_cpy(&(nbar_protocol->protocol_name), row[1]); string_cpy(&(nbar_protocol->protocol_description), row[2]); string_cpy(&(nbar_protocol->protocol_id), row[3]); //printf("last_nbar_protocol %d nbar_protocol %d next %d\n", last_nbar_protocol, nbar_protocol, nbar_protocol->next); } return (TMNbar_protocol*) return_nbar_protocol; }
void MainWindow::changeDB(QString fname) { if (fname.isEmpty()) return; close_database(); homedir = fname.mid(0, fname.lastIndexOf(QDir::separator())); dbfile = fname; init_database(); }
int main(int argc, char *argv[]) { const int no_employees = 10; Database people; init_database (people, no_employees); print_database(people, no_employees); sort((int**)people, no_employees, comp_employee, swap_employee); print_database(people, no_employees); return 0; }
bool zathura_init(zathura_t* zathura) { if (zathura == NULL) { return false; } /* create zathura (config/data) directory */ create_directories(zathura); /* load plugins */ zathura_plugin_manager_load(zathura->plugins.manager); /* configuration */ config_load_default(zathura); config_load_files(zathura); /* UI */ if (!init_ui(zathura)) { goto error_free; } /* database */ init_database(zathura); /* bookmarks */ zathura->bookmarks.bookmarks = girara_sorted_list_new2( (girara_compare_function_t)zathura_bookmarks_compare, (girara_free_function_t)zathura_bookmark_free); /* jumplist */ init_jumplist(zathura); /* CSS for index mode */ init_css(zathura); /* Shortcut helpers */ init_shortcut_helpers(zathura); /* Start D-Bus service */ bool dbus = true; girara_setting_get(zathura->ui.session, "dbus-service", &dbus); if (dbus == true) { zathura->dbus = zathura_dbus_new(zathura); } return true; error_free: if (zathura->ui.page_widget != NULL) { g_object_unref(zathura->ui.page_widget); } return false; }
int main(int argc, char* argv[]) { init_database(database, table); init_server(argc, argv); recv_from_client(); close_server(); close_database(); return EXIT_SUCCESS; }
TMFilter* get_application_filters(int application_id) { /*TMFilter* filter = (TMFilter*)malloc(sizeof(TMFilter)); filter->name = "15"; printf("1>%s\n", filter->name); return filter;*/ int retc; TMFilter* return_filter = NULL; if(con==NULL) if((retc=init_database())==0) return retc; char query_buffer[QUERY_BUFFER_SIZE]; sprintf(query_buffer, " \ SELECT Filters.id, Filters.name \ FROM Filters \ WHERE Filters.application_id='%d'; \ ", application_id); mysql_query(con, query_buffer); MYSQL_RES* result = mysql_store_result(con); //printf("num-rows: %d\n", mysql_num_rows(result)); //printf("%d\n", mysql_num_rows(result)); if(mysql_num_rows(result)==0) return NULL; MYSQL_ROW row; TMFilter* filter; while((row = mysql_fetch_row(result))) { TMFilter* last_filter = filter; filter = (TMFilter*)malloc(sizeof(TMFilter)); if(filter==NULL) return NULL; filter->next=NULL; if(return_filter==NULL) return_filter = filter; else last_filter->next = filter; if(row[0]!=NULL) filter->id = atoi(row[0]); string_cpy(&(filter->name), row[1]); filter->access_list = get_filter_access_lists(filter->id); filter->nbar_protocol = get_filter_nbar_protocols(filter->id); } mysql_free_result(result); return (TMFilter*)return_filter; }
TMRouter* get_application_routers(int application_id) { int retc; TMRouter* return_router = NULL; if(con==NULL) if((retc=init_database())==0) return retc; char query_buffer[QUERY_BUFFER_SIZE]; sprintf(query_buffer, " \ SELECT Routers.id, Routers.management_ip, Routers.name, Routers.username, Routers.password, Routers.interfaces \ FROM Routers \ WHERE Routers.application_id='%d'; \ ", application_id); mysql_query(con, query_buffer); //printf("%s\n", mysql_error(con)); MYSQL_RES* result = mysql_store_result(con); //printf("NBPnum-rows: %d\n", mysql_num_rows(result)); if(mysql_num_rows(result)==0) return NULL; MYSQL_ROW row; TMRouter* router; while((row = mysql_fetch_row(result))) { TMRouter* last_router = router; router = (TMRouter*)malloc(sizeof(TMRouter)); if(router==NULL) return NULL; router->next=NULL; if(return_router==NULL) return_router = router; else last_router->next = router; if(row[0]!=NULL) router->id = atoi(row[0]); string_cpy(&(router->management_ip), row[1]); string_cpy(&(router->name), row[2]); string_cpy(&(router->username), row[3]); string_cpy(&(router->password), row[4]); string_cpy(&(router->interfaces), row[5]); } return (TMRouter*) return_router; }
void init() { init_database(name); add_action("enter","enter"); add_action("read","read"); add_action("note","note"); add_action("reply","reply"); add_action("head","head"); add_action("do_lock", "lock"); add_action("do_lock", "nail"); add_action("do_lock", "unlock"); add_action("remove", "remove"); }
int main(/*int argc, char *argv[]*/) { printf("coucou"); FILE *file; file = fopen("Database.txt", "r"); printf("Crash before init"); database *data = init_database(); printf("Crash before read"); int nb_elt = read_data(file, data); printf("Crash before print"); print_database(data, nb_elt); //write_file(data, file); fclose(file); free(data); return 0; }
int main() { int escolha; /*if(verificaArquivos(4) != 4){ inicializaArquivos(1,"0xDEADC0DE,header_size=173,entidade=livro,qtd_campos=5,campos=[id;titulo;editora;anopublicacao;isbn],tamanho=[4,30,30,4,20,], tipo=[int,varchar,varchar,int,varchar],chaves:1*"); inicializaArquivos(2,"0xDEADC0DE,header_size=174,entidade=leitor,qtd_campos=6,campos=[id;nome;fone;endereco;cidade;estado],tamanho=[4,30,30,4,4,4,], tipo=[int,varchar,varchar,int,int,int],chaves:1*"); inicializaArquivos(3,"0xDEADC0DE,header_size=137,entidade=autor,qtd_campos=3,campos=[id;nome;sobrenome],tamanho=[4,30,30,], tipo=[int,varchar,varchar],chaves:1*"); inicializaArquivos(4,"0xDEADC0DE,header_size=134,entidade=autorLivro,qtd_campos=3,campos=[idlivro;idautor;seq],tamanho=[4,4,4,], tipo=[int,int,int],chaves:2*"); } do{ escolha = menuEntidade(); }while(escolha != 0);*/ init_database(); mostrarTabelas(); verificaArquivos(); return 0; }
int MainWindow::open_default_db() { if (!dbfile.isEmpty()) return 0; FILE *fp = fopen(QString2filename(getUserSettingsDir() + QDir::separator() + "defaultdb"), "r"); if (!fp) return 0; char buff[256]; size_t len = fread(buff, 1, 255, fp); fclose(fp); buff[len] = 0; dbfile = filename2QString(buff).trimmed(); if (QFile::exists(dbfile)) return init_database(); return 0; }
/* *测试代码 * * * */ int main(int argc,char **argv) { sprintf(act_info_to_write.sid,"%s",argv[0]+2); if(argc != 2) { printf("please input correct parameter\n"); printf("or %s 2013-05\n",argv[0]); return 0; } strcpy(month,argv[1]); if(init_database()!=0) {printf("init_database failed\n");return(0);} if(-1 == calculate_run_check_cost_collect()) {printf("执行calculate_run_check_cost_collect()失败\n");return 0;} //system("pause"); }
void sql_query (const char *fmt, ...) { va_list ap; char buf[16384]; if (Db) { va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); if (mysql_query(Db, buf) != 0) { // try to re-connect and retry init_database(last_host, last_user, last_pass, last_data); if (mysql_query(Db, buf) != 0) { hxd_log("mysql_query() failed: %s", mysql_error(Db)); hxd_log("mysql_query() query was: %s", buf); } } } }
static void daemon_setlanguage(std::string &lang) { if (userID.empty()) { daemon_printf( "%d unknow user id\n", CODE_DENIED ); return; } if (init_database()) { daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED ); return; } std::string sql; sql = "UPDATE user_basic SET language="; AppendMysql(sql, lang.c_str()); sql += " WHERE id="; sql += userID; if (stardictdMain.conn.query(sql.c_str(), sql.length())) { daemon_printf( "%d query failed\n", CODE_DENIED ); return; } daemon_printf( "%d\n", CODE_OK ); }
static void daemon_getdictmask() { if (userID.empty()) { daemon_printf( "%d unknow user id\n", CODE_USER_NOT_REGISTER ); return; } if (init_database()) { daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED ); return; } std::string sql; sql = "SELECT dictmask FROM user_basic WHERE id="; sql += userID; if (stardictdMain.conn.query(sql.c_str(), sql.length())) { daemon_printf( "%d query failed\n", CODE_DENIED ); return; } MySQLResult *res = stardictdMain.conn.getResult(); if (!res) { daemon_printf( "%d get result failed\n", CODE_DENIED ); return; } DB_ROW row = res->fetchRow(); if (!row) { res->destroy(); daemon_printf( "%d fetch row failed\n", CODE_DENIED ); return; } daemon_printf( "%d\n", CODE_OK ); const char *dictmask = row[0]; char *str = g_strdup_printf("level-%d-user/max_dict_count", userLevel); const int max_dict_count = stardictdMain.conf->get_int(str); g_free(str); std::string dictmask_str = stardictdMain.oLibs.get_dicts_list(dictmask, max_dict_count, userLevel); net_write_str(dictmask_str.c_str()); res->destroy(); }
static void daemon_setcollatefunc(std::string &func) { if (userID.empty()) { daemon_printf( "%d unknow user id\n", CODE_DENIED ); return; } if (userLevel == 0) { bool enable_collate = stardictdMain.conf->get_bool("level-0-user/enable_collate"); if (!enable_collate) { daemon_printf( "%d level 0 user can't set collate function.\n", CODE_DENIED ); return; } } int i = atoi(func.c_str()); if (func.empty() || i<0 || i-1 >= COLLATE_FUNC_NUMS) { daemon_printf( "%d wrong collate func\n", CODE_DENIED ); return; } if (init_database()) { daemon_printf( "%d Connect to MySQL failed!\n", CODE_DENIED ); return; } std::string sql; sql = "UPDATE user_basic SET collatefunc="; gchar *str = g_strdup_printf("%d", i); // func may contain other string, which will cause security problem. sql += str; g_free(str); sql += " WHERE id="; sql += userID; if (stardictdMain.conn.query(sql.c_str(), sql.length())) { daemon_printf( "%d query failed\n", CODE_DENIED ); return; } stardictdMain.SetServerCollateFunc(i); daemon_printf( "%d\n", CODE_OK ); }
int initializing_khan(char * mnt_dir) { //log_msg("In initialize\n"); unmounting(mnt_dir); //Opening root directory and creating if not present //cout<<"khan_root[0] is "<<servers.at(0)<<endl; if(NULL == opendir(servers.at(0).c_str())) { sprintf(msg,"Error msg on opening directory : %s\n",strerror(errno)); //log_msg(msg); //log_msg("Root directory might not exist..Creating\n"); string command = "mkdir " + servers.at(0); if (system(command.c_str()) < 0) { log_msg("Unable to create storage directory...Aborting\n"); exit(1); } } else { fprintf(stderr, "directory opened successfully\n"); } init_database(); //check if we've loaded metadata before string output=database_getval("setup","value"); if(output.compare("true")==0){ log_msg("Database was previously initialized."); tot_time+=(stop.tv_sec-start.tv_sec)+(stop.tv_nsec-start.tv_nsec)/BILLION; return 0; //setup has happened before } //if we have not setup, do so now //log_msg("it hasnt happened, setvalue then setup"); database_setval("setup","value","true"); //load metadata associatons for(int i=0; i<servers.size(); i++){ process_transducers(servers.at(i)); } //load metadata for each file on each server string types=database_getval("allfiles","types"); //cout << "================= types to look for ="<<types<<endl; for(int i=0; i<servers.size(); i++) { if(servers.at(i) == "cloud") { PyObject* myFunction = PyObject_GetAttrString(cloud_interface,(char*)"get_all_titles"); PyObject* myResult = PyObject_CallObject(myFunction, NULL); if(myResult==NULL) { PyErr_PrintEx(0); continue; } int n = PyList_Size(myResult); //cout << "SIZE = " << n << endl << flush; for(int j = 0; j<n; j++) { PyObject* title = PyList_GetItem(myResult, j); char* temp = PyString_AsString(title); if(temp==NULL) { PyErr_PrintEx(0); continue; } string filename = temp; //cout << "Checking " << filename << " ... " << endl << flush; if(database_getval("name",filename)=="null") { string fileid = database_setval("null","name",filename); string ext = strrchr(filename.c_str(),'.')+1; database_setval(fileid,"ext",ext); database_setval(fileid,"server",servers.at(i)); database_setval(fileid,"location",server_ids.at(i)); string attrs=database_getval(ext,"attrs"); string token=""; stringstream ss2(attrs.c_str()); PyObject* myFunction = PyObject_GetAttrString(cloud_interface,(char*)"get_metadata"); while(getline(ss2,token,':')){ if(strcmp(token.c_str(),"null")!=0){ //cout << "========= looking at attr = " << token << endl << flush; PyObject* arglist = PyTuple_New(2); PyTuple_SetItem(arglist, 0, PyString_FromString(filename.c_str())); PyTuple_SetItem(arglist, 1, PyString_FromString(token.c_str())); PyObject* myResult = PyObject_CallObject(myFunction, arglist); //cout << myResult << endl << flush; if(myResult==NULL) { PyErr_PrintEx(0); continue; } char* msg = PyString_AsString(myResult); if(!msg) { PyErr_PrintEx(0); continue; } string val = msg; Py_DECREF(arglist); Py_DECREF(myResult); //cout << "========= got val = " << val << endl << flush; if(val!="na") { database_setval(fileid,token,val); } } } } else { string fileid = database_getval("name", filename); database_setval(fileid,"server",servers.at(i)); database_setval(fileid,"location",server_ids.at(i)); } } } else { glob_t files; glob((servers.at(i)+"/*.*").c_str(),0,NULL,&files); for(int j=0; j<files.gl_pathc; j++) {//for each file string file = files.gl_pathv[j]; string ext = strrchr(file.c_str(),'.')+1; string filename=strrchr(file.c_str(),'/')+1; if(database_getval("name", filename) == "null") { string fileid = database_setval("null","name",filename); database_setval(fileid,"ext",ext); database_setval(fileid,"server",servers.at(i)); database_setval(fileid,"location",server_ids.at(i)); for(int k=0; k<server_ids.size(); k++) { database_setval(fileid, server_ids.at(k), "0"); } if(j%10==0) { cout << "processed file " << j << "\n"; } process_file(servers.at(i), fileid); } else { string fileid = database_getval("name",filename); database_setval(fileid,"server",servers.at(i)); database_setval(fileid,"location",server_ids.at(i)); } } } } //log_msg("At the end of initialize\n"); return 0; }
static device_id_t get_device_id(bool do_regist) { char device[PROP_VALUE_MAX]; char build_id[PROP_VALUE_MAX]; device_id_t device_id; const char *check_name; char name_buf[PROP_NAME_MAX]; sqlite3_stmt *st; int rc; int i; if (!init_database()) { return DEVICE_NOT_SUPPORTED; } __system_property_get("ro.product.model", device); __system_property_get("ro.build.display.id", build_id); device_id = DEVICE_NOT_SUPPORTED; check_name = NULL; rc = sqlite3_prepare(db, SQL_QUERY_DEVICE, -1, &st, NULL); if (!IS_SQL_ERROR(rc)) { rc = sqlite3_reset(st); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 1, device, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 2, build_id, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { for (rc = execute_sql(st); rc == SQLITE_ROW; rc = execute_sql(st)) { const char *check_value; device_id = sqlite3_column_int(st, 0); check_name = sqlite3_column_text(st, 1); check_value = sqlite3_column_text(st, 2); if (!check_name && !check_value) { break; } if (check_name && check_value) { char property_value[PROP_VALUE_MAX]; __system_property_get(check_name, property_value); if (strcmp(property_value, check_value) == 0) { break; } strncpy(name_buf, check_name, sizeof (name_buf) - 1); name_buf[sizeof (name_buf) - 1] = '\0'; check_name = name_buf; } device_id = DEVICE_NOT_SUPPORTED; } } if (IS_SQL_ERROR(rc)) { printf("%s(%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); sqlite3_finalize(st); return device_id; } sqlite3_finalize(st); if (!do_regist || device_id != DEVICE_NOT_SUPPORTED) { return device_id; } return register_device_id(check_name); }
static device_id_t register_device_id(const char *property_name) { char device[PROP_VALUE_MAX]; char build_id[PROP_VALUE_MAX]; char buf[PROP_VALUE_MAX]; const char *property_value; sqlite3_stmt *st; int rc; device_id_t device_id; if (!init_database()) { return DEVICE_NOT_SUPPORTED; } __system_property_get("ro.product.model", device); __system_property_get("ro.build.display.id", build_id); device_id = DEVICE_NOT_SUPPORTED; property_value = NULL; if (property_name) { __system_property_get(property_name, buf); property_value = buf; } rc = sqlite3_prepare(db, SQL_QUERY_LAST_DEVICE_ID, -1, &st, NULL); if (!IS_SQL_ERROR(rc)) { rc = sqlite3_reset(st); } if (!IS_SQL_ERROR(rc)) { for (rc = execute_sql(st); rc == SQLITE_ROW; rc = execute_sql(st)) { device_id = sqlite3_column_int(st, 0) + 1; if (device_id <= DEVICE_ID_REGISTER_START) { device_id = DEVICE_ID_REGISTER_START; } break; } } if (IS_SQL_ERROR(rc)) { printf("%s(%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); sqlite3_finalize(st); return DEVICE_NOT_SUPPORTED; } sqlite3_finalize(st); rc = sqlite3_prepare(db, SQL_REGISTER_DEVICE, -1, &st, NULL); if (!IS_SQL_ERROR(rc)) { rc = sqlite3_reset(st); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_int(st, 1, device_id); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 2, device, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 3, build_id, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 4, property_name, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 5, property_value, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = execute_sql(st); } if (IS_SQL_ERROR(rc)) { printf("%s(%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); sqlite3_finalize(st); return DEVICE_NOT_SUPPORTED; } sqlite3_finalize(st); return device_id; }
int main() { struct dbSysHead head; long fid1, fid2; /* ≥ı ºªØ£¨»ª∫Û¥Ú”°≥ˆµ±«∞œµÕ≥µƒ–≈œ¢ */ init_database(&head); showDesc(&head); // printf("create file1...\n"); fid1 = creatFileSpace(&head);//Œ™Œƒº˛“ª∑÷≈‰ø’º‰ fid2 = creatFileSpace(&head); // 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_); */ // if(initTable(&head, fid1) == 0) 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"); //read customer.tbl and write into our file1, 一次性 loaddata(&head, FIRST_FID); //Scan Table relation * temp_data_dict = new relation[MAX_FILE_NUM]; TableScan(&head, FIRST_FID, temp_data_dict); //get the output of tablescan, temporarily according to datadict1, other than temp_data_dict[1] int buffer_ID_ = - temp_data_dict[0].fileID; //find which buffer int record_num_ = temp_data_dict[0].getRecordNum(); int record_len_ = temp_data_dict[0].getRecordLength(); // RecordCursorTmp t1(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; /* int scanPointer = 0; int dictID = queryFileID(&head, FIRST_FID); char * one_Row_ = (char *)malloc(sizeof(char)*record_len_); while (true == t1.getNextRecord(one_Row_)) { //only scan scanPointer ++; if(scanPointer < 20) getOneRecord(one_Row_, &head.redef[dictID]); //get each attribute value and print } free(one_Row_);*/ loaddata(&head, FIRST_FID + 1); 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(); // RecordCursorTmp t2(&head,1,record_len_,buffer_ID_,record_num_); cout<<buffer_ID_<<"~"<<record_len_<<"~"<<record_num_<<endl; /* scanPointer = 0; dictID = queryFileID(&head, FIRST_FID + 1); char * one_Row_2 = (char *)malloc(sizeof(char)*record_len_); while (true == t2.getNextRecord(one_Row_2)) { //only scan scanPointer ++; if(scanPointer < 20) getOneRecord(one_Row_2, &head.redef[dictID]); //get each attribute value and print } free(one_Row_2);*/ // 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); */ /* relation result; result.init("customer", "TianzhenWu"); result.insertAttribute("name", 2, 64); result.insertAttribute("phone", 2, 64); showRelation(&result); project(&head, &temp_data_dict[0], &result);********/ 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; 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"); } 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; showFileDesc(&head); exit_database(&head); system("pause"); return 0; }
TMApplication* get_application_mysql(int application_id) { int retc; if(con==NULL) if((retc=init_database())==0) return retc; char query_buffer[QUERY_BUFFER_SIZE]; sprintf(query_buffer, " \ SELECT Applications.id, Applications.name, Applications.certificate_id, Applications.analyzer_id, \ Analyzers.name, Analyzers.description, Analyzers.src, \ Certificates.name, Certificates.root_cert_path, Analyzers.args \ FROM Applications \ LEFT JOIN Certificates \ ON Certificates.id = Applications.certificate_id \ LEFT JOIN Analyzers \ ON Analyzers.id = Applications.analyzer_id \ WHERE Applications.id='%d' \ LIMIT 1;", application_id); mysql_query(con, query_buffer); MYSQL_RES* result = mysql_store_result(con); //printf("num-rows: %d\n", mysql_num_rows(result)); if(mysql_num_rows(result)==0) return NULL; TMApplication* application = (TMApplication*)malloc(sizeof(TMApplication)); if(application==NULL) return NULL; MYSQL_ROW* row = mysql_fetch_row(result); if(row[0]!=NULL) application->id = atoi(row[0]); string_cpy(&(application->name), row[1]); application->certificate = (TMCertificate*)malloc(sizeof(TMCertificate)); if(application->certificate==NULL) return NULL; if(row[2]!=NULL) application->certificate->id = atoi(row[2]); string_cpy(&(application->certificate->name), row[7]); string_cpy(&(application->certificate->root_cert_path), row[8]); application->analyzer = (TMAnalyzer*)malloc(sizeof(TMAnalyzer)); if(application->analyzer==NULL) return NULL; if(row[3]!=NULL) { application->analyzer->id = atoi(row[3]); string_cpy(&(application->analyzer->name), row[4]); string_cpy(&(application->analyzer->description), row[5]); string_cpy(&(application->analyzer->src), row[6]); string_cpy(&(application->analyzer->args), row[9]); } mysql_free_result(result); sprintf(query_buffer, " \ SELECT application_config.id, application_config.config_name, application_config.config_value \ FROM application_config \ WHERE application_config.application_id = '%d'", application_id); mysql_query(con, query_buffer); result = mysql_store_result(con); application->config = NULL; if(mysql_num_rows(result)>0) { MYSQL_ROW row; TMApplication_config* config = NULL; while((row = mysql_fetch_row(result))) { //TMApplication_config* config = TMApplication_config* last_config = config; config = (TMApplication_config*)malloc(sizeof(TMApplication_config)); if(config==NULL) exit(1); config->next=NULL; if(last_config==NULL) application->config = config; else last_config->next = config; if(row[0]!=NULL) { config->id = atoi(row[0]); string_cpy(&(config->config_name), row[1]); string_cpy(&(config->config_value), row[2]); } } mysql_free_result(result); } return (TMApplication*) application; //return NULL; }
TMAccess_list* get_filter_access_lists(int filter_id) { int retc; TMAccess_list* return_acl = NULL; if(con==NULL) if((retc=init_database())==0) return retc; char query_buffer[QUERY_BUFFER_SIZE]; sprintf(query_buffer, " \ SELECT AccessLists.id, AccessLists.action, AccessLists.protocol, \ SRC.address as src_address, SRC.mask as src_mask,\ DST.address as dst_address, DST.mask as dst_mask, \ PNS.greater_or_equal, PNS.less_or_equal, \ PND.greater_or_equal, PND.less_or_equal \ FROM AccessLists \ LEFT JOIN IpNetworks SRC \ ON AccessLists.ip_source = SRC.id \ LEFT JOIN IpNetworks DST \ ON AccessLists.ip_destination = DST.id \ LEFT JOIN Ports PNS \ ON AccessLists.pn_source = PNS.id \ LEFT JOIN Ports PND \ ON AccessLists.pn_destination = PND.id \ WHERE AccessLists.filter_id='%d'; \ ", filter_id); mysql_query(con, query_buffer); //printf("%s\n", mysql_error(con)); MYSQL_RES* result = mysql_store_result(con); //printf("FACnum-rows: %d\n", mysql_num_rows(result)); if(mysql_num_rows(result)==0) return NULL; MYSQL_ROW row; TMAccess_list* acl; while((row = mysql_fetch_row(result))) { TMAccess_list* last_acl = acl; acl = (TMAccess_list*)malloc(sizeof(TMAccess_list)); if(acl==NULL) return NULL; acl->next=NULL; if(return_acl==NULL) return_acl = acl; else last_acl->next = acl; //filter->id = atoi(row[0]); if(row[0]!=NULL) acl->id = atoi(row[0]); if(strcmp(row[1], "permit")==0) acl->action = PERMIT; else acl->action = DENY; string_cpy(&(acl->protocol), row[2]); acl->ip_source = (TMIp_network*)malloc(sizeof(TMIp_network)); acl->ip_destination = (TMIp_network*)malloc(sizeof(TMIp_network)); if(acl->ip_source==NULL || acl->ip_destination==NULL) return NULL; string_cpy(&(acl->ip_source->address), row[3]); if(row[4]!=NULL) acl->ip_source->mask = atoi(row[4]); string_cpy(&(acl->ip_destination->address), row[5]); if(row[6]!=NULL) acl->ip_destination->mask = atoi(row[6]); // Source ports if(row[7]!=NULL && row[8]!=NULL) { acl->pn_source = (TMPorts*)malloc(sizeof(TMPorts)); if(acl->pn_source==NULL) return NULL; acl->pn_source->greater_or_equal = atoi(row[7]); acl->pn_source->less_or_equal = atoi(row[8]); //printf(">%d %d\n", acl->pn_source->greater_or_equal, acl->pn_source->less_or_equal); } else { acl->pn_source = NULL; } // Destination ports if(row[9]!=NULL && row[10]!=NULL) { acl->pn_destination = (TMPorts*)malloc(sizeof(TMPorts)); if(acl->pn_destination==NULL) return NULL; acl->pn_destination->greater_or_equal = atoi(row[9]); acl->pn_destination->less_or_equal = atoi(row[10]); //printf(">%d %d\n", acl->pn_destination->greater_or_equal, acl->pn_destination->less_or_equal); } else { acl->pn_destination = NULL; } } mysql_free_result(result); return (TMAccess_list*)return_acl; }
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; }