void LocalDomainAccessStore::reset() { JOYNR_LOG_DEBUG(logger, "execute: entering reset store"); QSqlQuery dropDomainRole("DROP TABLE IF EXISTS DomainRole", db); QSqlQuery dropMasterAcl("DROP TABLE IF EXISTS MasterACL", db); QSqlQuery dropMediatorAcl("DROP TABLE IF EXISTS MediatorACL", db); QSqlQuery dropOwnerAcl("DROP TABLE IF EXISTS OwnerACL", db); QSqlQuery vacuum("VACUUM", db); bool success = false; success = dropDomainRole.exec(); assert(success); success = dropMasterAcl.exec(); assert(success); success = dropMediatorAcl.exec(); assert(success); success = dropOwnerAcl.exec(); assert(success); success = vacuum.exec(); assert(success); }
bool DBService::exec(const QString& sql,bool vaccum) { // qDebug()<<"exec sql : "<<sql; bool res = false; if(!open()) { qDebug()<<database.lastError(); return res; } else { QSqlQuery sql_query(database); sql_query.exec("PRAGMA foreign_keys = ON"); if(!sql_query.exec(sql)) { qDebug()<<sql_query.lastError(); } else { qDebug()<<"inserted!"; if(vaccum) vacuum(); // sql_query.exec("VACUUM"); res = true; } } close(); return res; }
/* * Auto-stats employs this sub-routine to issue an analyze on a specific relation. */ static void autostats_issue_analyze(Oid relationOid) { VacuumStmt *analyzeStmt = NULL; RangeVar *relation = NULL; /* * If this user does not own the table, then auto-stats will not issue the * analyze. */ if (!(pg_class_ownercheck(relationOid, GetUserId()) || (pg_database_ownercheck(MyDatabaseId, GetUserId()) && !IsSharedRelation(relationOid)))) { elog(DEBUG3, "Auto-stats did not issue ANALYZE on tableoid %d since the user does not have table-owner level permissions.", relationOid); return; } relation = makeRangeVar(get_namespace_name(get_rel_namespace(relationOid)), get_rel_name(relationOid), -1); analyzeStmt = makeNode(VacuumStmt); /* Set up command parameters */ analyzeStmt->vacuum = false; analyzeStmt->full = false; analyzeStmt->analyze = true; analyzeStmt->freeze_min_age = -1; analyzeStmt->verbose = false; analyzeStmt->rootonly = false; analyzeStmt->relation = relation; /* not used since we pass relids list */ analyzeStmt->va_cols = NIL; vacuum(analyzeStmt, NIL, NULL, false, false); pfree(analyzeStmt); }
void fw_simGeo_fix_materials() { Int_t base_element_offset = TGeoMaterial::Class()->GetDataMemberOffset("fElement"); TString vacuum("materials:Vacuum"); TGeoMaterial *m; TIter it(FWGeometryTableViewManager_GetGeoManager()->GetListOfMaterials()); while ((m = (TGeoMaterial*) it()) != 0) { // Fixes if (vacuum == m->GetName()) { m->SetZ(0); } TGeoMixture *mix = dynamic_cast<TGeoMixture*>(m); if (mix == 0) { if ( ! m->GetBaseElement()) { *(TGeoElement**)(((char*)m) + base_element_offset) = g_element_table->GetElement(m->GetZ()); } } } }
void RebuildIndexesThread::run() { QString strError; if (!vacuum(strError)){ emit showError(strError); return; } showStatus(tr("Database successfully vacuumed!")); exec(); }
bool DBService::exec(const QStringList& sqlInserts,bool vaccum) { QTime time; time.start(); bool res = true; if(!open()) { qDebug()<<database.lastError(); return false; } else { database.transaction(); QSqlQuery sql_query(database); sql_query.exec("PRAGMA foreign_keys = ON"); for(int i = 0;i < sqlInserts.count();i++) { // qDebug()<<"exec sql : "<<sqlInserts[i]; sql_query.prepare(sqlInserts[i]); if(!sql_query.exec()) { qDebug()<<sql_query.lastError(); res = false; break; } else { // qDebug()<<"inserted!" << i; } // qDebug("%d,%d",i,sqlInserts.count()); } qDebug()<<"elapsed 0:"<<time.elapsed()/1000.0; if(res) { database.commit(); if(vaccum) vacuum(); } else database.rollback(); } close(); qDebug()<<"elapsed 1:"<<time.elapsed()/1000.0; return res; }
bool SQLiteAdminTools::vacuum(const KexiDB::ConnectionData& data, const QString& databaseName) { clearError(); KexiDB::DriverManager manager; KexiDB::Driver *drv = manager.driver(data.driverName); QString title(i18n("Could not compact database \"%1\".", QDir::toNativeSeparators(databaseName))); if (!drv) { setError(&manager, title); return false; } SQLiteVacuum vacuum(data.dbPath() + QDir::separator() + databaseName); tristate result = vacuum.run(); if (!result) { setError(title); return false; } else //success or cancelled return true; }
/* * Primary entry point for manual VACUUM and ANALYZE commands * * This is mainly a preparation wrapper for the real operations that will * happen in vacuum(). */ void ExecVacuum(VacuumStmt *vacstmt, bool isTopLevel) { VacuumParams params; /* sanity checks on options */ Assert(vacstmt->options & (VACOPT_VACUUM | VACOPT_ANALYZE)); Assert((vacstmt->options & VACOPT_VACUUM) || !(vacstmt->options & (VACOPT_FULL | VACOPT_FREEZE))); Assert((vacstmt->options & VACOPT_ANALYZE) || vacstmt->va_cols == NIL); Assert(!(vacstmt->options & VACOPT_SKIPTOAST)); /* * All freeze ages are zero if the FREEZE option is given; otherwise pass * them as -1 which means to use the default values. */ if (vacstmt->options & VACOPT_FREEZE) { params.freeze_min_age = 0; params.freeze_table_age = 0; params.multixact_freeze_min_age = 0; params.multixact_freeze_table_age = 0; } else { params.freeze_min_age = -1; params.freeze_table_age = -1; params.multixact_freeze_min_age = -1; params.multixact_freeze_table_age = -1; } /* user-invoked vacuum is never "for wraparound" */ params.is_wraparound = false; /* user-invoked vacuum never uses this parameter */ params.log_min_duration = -1; /* Now go through the common routine */ vacuum(vacstmt->options, vacstmt->relation, InvalidOid, ¶ms, vacstmt->va_cols, NULL, isTopLevel); }
int main(int argc, char **argv) { sqlite3 *db; int option_index, option; if( argc < 3 ){ print_help(NULL); return 1; } db = NULL; option_index = 0; static struct option long_options[] = { {"batch", 0, 0, 'b'}, {"clean", 2, 0, 'c'}, {"export", 2, 0, 'e'}, {"h", 0, 0, 'h'}, {"help", 0, 0, 'h'}, {"import", 2, 0, 'i'}, {"sql", 1, 0, 's'}, {"stats", 2, 0, 't'}, {"statistics", 2, 0, 't'}, {"verify", 2, 0, 'v'}, {"vacuum", 2, 0, 'c'}, // TODO: implement options like '-e essid' to limit // operations to a certain essid where possible {"essid", 1, 0, 'd'}, {0, 0, 0, 0 } }; option = getopt_long( argc, argv, "bc:d:e:hi:s:t:v:", long_options, &option_index ); if( option > 0 ) { switch (option) { case 'b': // Batch if ( check_for_db(&db, argv[1], 0, 1) ) { return 1; } batch_process(db); break; case 'c': // Clean if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } vacuum(db, (argc > 3 && strcasecmp(argv[3],"all") == 0) ? 1 : 0); break; case 'e': if (argc < 4) { print_help("You must specify an export format."); } else if (strcmp(argv[3],"cowpatty")==0) { if (argc < 6) { print_help("You must specify essid and output file."); } else { // Export if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } export_cowpatty(db,argv[4],argv[5]); } } else { print_help("Invalid export format specified."); } break; case ':' : case '?' : case 'h': // Show help print_help(NULL); break; case 'i': // Import if (argc < 5) { print_help("You must specifiy an import format and a file."); } else if (strcasecmp(argv[3], IMPORT_COWPATTY) == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_cowpatty(db,argv[4]); } else if (strcasecmp(argv[3], IMPORT_ESSID) == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_ascii(db, IMPORT_ESSID,argv[4]); } else if (strcasecmp(argv[3], IMPORT_PASSWD) == 0 || strcasecmp(argv[3],"password") == 0) { if ( check_for_db(&db, argv[1], 1, 0) ) { return 1; } import_ascii(db,IMPORT_PASSWD, argv[4]); } else { print_help("Invalid import format specified."); return 1; } break; case 's': // SQL // We don't know if the SQL order is changing the file or not if ( check_for_db(&db, argv[1], 0, 0) ) { return 1; } sql_stdout(db, argv[3], 0); break; case 't': // Stats if ( check_for_db(&db, argv[1], 0, 1) ) { return 1; } show_stats(db, (argv[3] == NULL) ? 0 : 1); break; case 'v': // Verify if ( check_for_db(&db, argv[1], 0, (argc > 3 && strcasecmp(argv[3],"all")==0) ? 0 : 1) ) { return 1; } verify(db, (argc > 3 && strcasecmp(argv[3],"all")==0) ? 1 : 0); break; default: print_help("Invalid option"); break; } } else { print_help(NULL); } if (db) sqlite3_close(db); return 0; }
int main(int argc, char *argv[]) { char lower[PATH_MAX] = ""; char upper[PATH_MAX] = ""; bool verbose = false; static struct option long_options[] = { { "lowerdir", required_argument, 0, 'l' }, { "upperdir", required_argument, 0, 'u' }, { "help", no_argument , 0, 'h' }, { "verbose", no_argument , 0, 'v' }, { 0, 0, 0, 0 } }; int opt = 0; int long_index = 0; while ((opt = getopt_long_only(argc, argv, "", long_options, &long_index)) != -1) { switch (opt) { case 'l': if (realpath(optarg, lower) == NULL) { lower[0] = '\0'; } break; case 'u': if (realpath(optarg, upper) == NULL) { upper[0] = '\0'; } break; case 'h': print_help(); return EXIT_SUCCESS; case 'v': verbose = true; break; default: fprintf(stderr, "Option %c is not supported.\n", opt); goto see_help; } } if (lower[0] == '\0') { fprintf(stderr, "Lower directory not specified.\n"); goto see_help; } if (!directory_exists(lower)) { fprintf(stderr, "Lower directory cannot be opened.\n"); goto see_help; } if (upper[0] == '\0') { fprintf(stderr, "Upper directory not specified.\n"); goto see_help; } if (!directory_exists(upper)) { fprintf(stderr, "Lower directory cannot be opened.\n"); goto see_help; } if (!check_xattr_trusted(upper)) { fprintf(stderr, "The program cannot write trusted.* xattr. Try run again as root.\n"); return EXIT_FAILURE; } if (check_mounted(lower, upper)) { return EXIT_FAILURE; } if (optind == argc - 1) { int out; char filename_template[] = "overlay-tools-XXXXXX.sh"; FILE *script = NULL; if (strcmp(argv[optind], "diff") == 0) { out = diff(lower, upper, verbose); } else if (strcmp(argv[optind], "vacuum") == 0) { script = create_shell_script(filename_template); if (script == NULL) { fprintf(stderr, "Script file cannot be created.\n"); return EXIT_FAILURE; } out = vacuum(lower, upper, verbose, script); } else if (strcmp(argv[optind], "merge") == 0) { script = create_shell_script(filename_template); if (script == NULL) { fprintf(stderr, "Script file cannot be created.\n"); return EXIT_FAILURE; } out = merge(lower, upper, verbose, script); } else { fprintf(stderr, "Action not supported.\n"); goto see_help; } if (script != NULL) { printf("The script %s is created. Run the script to do the actual work please. Remember to run it when the OverlayFS is not mounted.\n", filename_template); fclose(script); } if (out) { fprintf(stderr, "Action aborted due to fatal error.\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; } fprintf(stderr, "Please specify one action.\n"); see_help: fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]); return EXIT_FAILURE; }