Exemplo n.º 1
0
static int uw_password_ok(char *user, char *passwd) 
{
  MYSQL_RES *result;

  if (open_database() == 0) {
    gchar buffer[256];
    MYSQL_ROW row;

    sprintf(buffer, "select id from contact where username = '******' and password = '******'", user, passwd);
    if (mysql_query(mysql, buffer)) {
      close_database();
      LOG(LOG_ERR, "buffer: %s", mysql_error(mysql));
      return(FALSE);
    }
    result = mysql_store_result(mysql);
    if (!result) {
      close_database();
      if (debug) LOG(LOG_DEBUG, "user %s, pwd %s not found", user, passwd);
      return(FALSE);
    }
    if ((row = mysql_fetch_row(result))) {
      int id;

      id = atoi(row[0]);
      if (debug) LOG(LOG_DEBUG, "user %s, pwd %s resulted in id %d", user, passwd, id);
      printf("\n");
    }
    mysql_free_result(result);
    close_database();
  }
  return(TRUE);
}
Exemplo n.º 2
0
int run(void)
{
  dbi_conn conn;

  if (!cache) {
    cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
  }
  
  LOG(LOG_INFO, "reading info from database"); 
  uw_setproctitle("reading info from database");
  conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME), 
			OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (conn) {
    refresh_database(conn);
    close_database(conn);
  }

  if (g_hash_table_size(cache) > 0) {
    LOG(LOG_INFO, "running %d probes", g_hash_table_size(cache));
    uw_setproctitle("running %d probes", g_hash_table_size(cache));
    run_actual_probes(); /* this runs the actual probes */

    LOG(LOG_INFO, "writing results"); 
    uw_setproctitle("writing results");
    write_results();
  }

  return(g_hash_table_size(cache));
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
    int opt = 0;
    int all = 0;
    unsigned int lb = 2, rb = -1;
	while ((opt = getopt_long(argc, argv, "al:r:", NULL, NULL))
			!= -1) {
		switch (opt) {
            case 'a':
                /* all distances */
                all = 1;
                break;
            case 'l':
                lb = atoi(optarg);
                break;
            case 'r':
                rb = atoi(optarg);
                break;
            default:
                return -1;
        }
    }

    assert(lb >= 2);
    open_database();

    if(all == 1)
        distance_between_all_chunk_references(lb, rb);
    else
        distance_between_first_two_chunk_references(lb, rb);

    close_database();

    return 0;
}
Exemplo n.º 4
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");
}
Exemplo n.º 5
0
int run(void)
{
  database *db;

  if (!cache) {
    cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
  }
  
  LOG(LOG_INFO, "reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID); 
  uw_setproctitle("reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID);
  db = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME), 
			OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (db) {
    refresh_database(db);
    close_database(db);
  }

  if (g_hash_table_size(cache) > 0) {
    LOG(LOG_INFO, "running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
    uw_setproctitle("running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
    run_actual_probes(); /* this runs the actual probes */

    LOG(LOG_INFO, "writing results"); 
    uw_setproctitle("writing results");
    write_results();
  }

  return(g_hash_table_size(cache));
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    int opt = 0;
    unsigned int lb = 1, rb =-1;
    int distribution = 0;
	while ((opt = getopt_long(argc, argv, "l:r:d", NULL, NULL))
			!= -1) {
		switch (opt) {
            case 'l':
                lb = atoi(optarg);
                break;
            case 'r':
                rb = atoi(optarg);
                break;
            case 'd':
                distribution = 1;
                break;
            default:
                return -1;
        }
    }

    open_database();

    if(distribution)
        get_chunksize_distribution(lb, rb);
    else
        avg_chunksize();

    close_database();

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char *argv[])
{

	
	strcpy(act_info.prog_id,argv[0]);	
        //creep_capacity = 10;
   // strcpy(act_info.prog_id,argv[0]);
	strcpy(date, argv[1]);	
	init_prog();
        printf("here\n");
	get_unit_info();

	
	get_limit();
	check();
	init_to_downlimit_power();
	print_unit("用最小出力初始化电厂出力后打印");
	
	cal_unit_gen();	
	
	printf("\n\n\n");
	

	
    //write_act_info( 1, "执行定电量负荷分配程序成功");
	free_memory();	
    close_database();



	printf("\n\n");
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
	if(open_database())
		create_medialib();
	else {
		g_print("错误:无法打开数据库。");
		return 1;
	}
	link_t mlink = {NULL, 0};
	link_t plink = {NULL, 0};
	load_medialib(&mlink, 0);
	
	main_core(GENERAL_MEDIALIB_INIT, &mlink);
	main_core(GENERAL_PLAYLIST_INIT, &plink);

	gtk_init(&argc, &argv);
	InterFace ui;
	ui.winMain = create_winMain(&ui);
	ui.diaMedialib = create_diaMedialib(&ui);
	ui.diaPlaylist = create_diaPlaylist(&ui);
	ui.diaVolume = create_diaVolume(&ui);
	gtk_widget_show(ui.winMain);
	g_signal_connect(G_OBJECT(ui.winMain), "delete_event",
			G_CALLBACK(gtk_main_quit), NULL);
	gtk_main();

	link_del_all(&mlink);
	link_del_all(&plink);
	close_database();
	return 0;
}
Exemplo n.º 10
0
int
main(int argc, char **argv)
{
    int fd, database_fd, database_size;
    krb5_error_code retval;
    krb5_context context;
    krb5_creds *my_creds;
    krb5_auth_context auth_context;

    setlocale(LC_ALL, "");
    retval = krb5_init_context(&context);
    if (retval) {
        com_err(argv[0], retval, _("while initializing krb5"));
        exit(1);
    }
    parse_args(argc, argv);
    get_tickets(context);

    database_fd = open_database(context, file, &database_size);
    open_connection(context, slave_host, &fd);
    kerberos_authenticate(context, &auth_context, fd, my_principal, &my_creds);
    xmit_database(context, auth_context, my_creds, fd, database_fd,
                  database_size);
    update_last_prop_file(slave_host, file);
    printf(_("Database propagation to %s: SUCCEEDED\n"), slave_host);
    krb5_free_cred_contents(context, my_creds);
    close_database(context, database_fd);
    exit(0);
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
    int opt = 0;
    unsigned int lb = 2, rb =-1;
    int task = 0;
	while ((opt = getopt_long(argc, argv, "l:r:t", NULL, NULL))
			!= -1) {
		switch (opt) {
            case 'l':
                lb = atoi(optarg);
                break;
            case 'r':
                rb = atoi(optarg);
                break;
            case 't':
                task = 1;
                break;
            default:
                return -1;
        }
    }

    /* makes no sense to analyze reference number 1 */
    assert(lb > 1);
    open_database();

    if(task == 1)
        get_file2ref_ratio(lb, rb);
    else
        analyze_references_source(lb, rb);

    close_database();

    return 0;
}
Exemplo n.º 12
0
void
ui_open_datafile()
{
    char *filename;

    filename = ask_filename(_("File to open: "));

    if(!filename || ! *filename) {
        free(filename);
        refresh_screen();
        return;
    }

    if(opt_get_bool(BOOL_AUTOSAVE))
        save_database();
    else if(statusline_ask_boolean(_("Save current database"), FALSE))
        save_database();

    close_database();

    load_database(filename);

    if(list_is_empty()) {
        statusline_msg(_("Sorry, the specified file appears not to be a valid abook addressbook"));
        load_database(datafile);
    } else {
        free(datafile);
        datafile = xstrdup(filename);
    }

    refresh_screen();
    free(filename);

    alternative_datafile = TRUE;
}
Exemplo n.º 13
0
int find_expired_probes(struct dbspec *dbspec)
{
  xmlDocPtr doc;
  xmlNodePtr probe;
  dbi_result result;
  dbi_conn conn;
  int count = 0;
  char buf[10];

  sprintf(buf, "%d", dbspec->port);

  conn = open_database(OPT_ARG(DBTYPE), dbspec->host, buf, dbspec->db,
                     dbspec->user, dbspec->password);
  if (!conn) return 0;

  doc = UpwatchXmlDoc("result", NULL);

  // find all expired probes, but skip those for which processing
  // has been stopped for some reason
  result = db_query(conn, 0, "select probe.name, pr_status.probe, " 
                             "       pr_status.server, pr_status.color, "
                             "       pr_status.expires "
                             "from   pr_status, probe "
                             "where  probe.id = pr_status.class and color <> 400 "
                             "       and expires < UNIX_TIMESTAMP()-30 "
                             "       and expires < probe.lastseen"
                             "       and probe.expiry = 'yes'");
  if (!result) goto errexit;

  while (dbi_result_next_row(result)) {
    char buffer[256];
    time_t now = time(NULL);

    probe = xmlNewChild(xmlDocGetRootElement(doc), NULL, dbi_result_get_string(result, "name"), NULL);
    xmlSetProp(probe, "realm", dbspec->realm);
    xmlSetProp(probe, "id", dbi_result_get_string(result, "probe"));
    xmlSetProp(probe, "server", dbi_result_get_string(result, "server"));
    sprintf(buffer, "%u", (int) now);	xmlSetProp(probe, "date", buffer);
    xmlSetProp(probe, "expires", dbi_result_get_string(result, "expires"));

    xmlNewChild(probe, NULL, "color", "400");  // PURPLE
    xmlNewChild(probe, NULL, "prevcolor", dbi_result_get_string(result, "color"));

    LOG(LOG_INFO, "%s: purpled %s %d", dbspec->realm, dbi_result_get_string(result, "name"), 
                                                      dbi_result_get_uint(result, "probe"));
    count++;
  }
  if (count) {
    xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
    spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(OUTPUT), doc, NULL);
    LOG(LOG_INFO, "%s: purpled %u probes", dbspec->realm, count);
  }

errexit:
  if (result) dbi_result_free(result);
  if (conn) close_database(conn);
  if (doc) xmlFreeDoc(doc);
  return count;
}
Exemplo n.º 14
0
void
ui_clear_database()
{
    if(statusline_ask_boolean(_("Clear WHOLE database"), FALSE)) {
        close_database();
        refresh_list();
    }
}
Exemplo n.º 15
0
int PrepareProcedures(char* schema) 
{
	new_database();
	str sql = _("SELECT * from functions_in('%c');", schema);
	int res = query(sql);
	if (res < 0) {
		dblog("%s",db_error());
		close_database(db);
		return 1;
	}
	stored_procedures = new_headers();
	for (int i = 0; i < res && i < MAX_HEADERS; ++i) {
		str proc = fetch(i,0);
		append_header(stored_procedures,proc,_("SELECT * FROM %s(",proc));
	}
	close_database(db);
	return 0;
}
Exemplo n.º 16
0
void MainWindow::changeDB(QString fname)
{
	if (fname.isEmpty())
		return;
	close_database();
	homedir = fname.mid(0, fname.lastIndexOf(QDir::separator()));
	dbfile = fname;
	init_database();
}
Exemplo n.º 17
0
int main(int argc, char* argv[])  {
	init_database(database, table);
	init_server(argc, argv);

	recv_from_client();

	close_server();
	close_database();

	return EXIT_SUCCESS;
}
Exemplo n.º 18
0
void result_obtainer::Get_Result()
{
    map_table *map_ptr = &Result_list;
    open_database();
    const char* sql = pre_sql.c_str();
    /* Execute SQL statement */
    rc = sqlite3_exec(db, sql, callback, (void*)map_ptr, &zErrMsg);
    if( rc != SQLITE_OK ){
        cout << sql << endl;
        fprintf(stderr, "SQL error: %s\n", zErrMsg);
        sqlite3_free(zErrMsg);
    }
    close_database();
}
Exemplo n.º 19
0
int main(int argc, char *argv[])
{
	/* dedup? */
	int dedup = 0;
	/* weighted by file/chunk size? */
	int weighted = 0;
	/* chunk level or file level */
	int file_level = 0;

	char *pophash = NULL;

	int opt = 0;
	while ((opt = getopt_long(argc, argv, "fwdp:", NULL, NULL))
			!= -1) {
		switch (opt) {
			case'f':
				file_level = 1;
				break;
			case 'd':
				dedup = 1;
				break;
			case 'w':
				weighted = 1;
				break;
			case 'p':
				pophash = optarg;
				break;
			default:
				fprintf(stderr, "invalid option\n");
				return -1;
		}
	}

	open_database();

	if (!file_level) {
		if (!dedup)
			chunk_nodedup_simd_trace(&argv[optind], argc - optind,  weighted);
		else
			chunk_dedup_simd_trace(&argv[optind], argc - optind, weighted, pophash);
	} else {
		if (!dedup)
			file_nodedup_simd_trace(&argv[optind], argc - optind, weighted);
		else
			file_dedup_simd_trace(&argv[optind], argc - optind, weighted, pophash);
	}
	close_database();

	return 0;
}
int main (int argc, char *argv[])
{
   const char *database;
   if (argc < 2)
     database = "wikidatawiki";
   else
     database = argv[1];

   MYSQL *mysql = open_named_database (database);
   print_dumpdate (mysql);
   
   make_list (mysql, FILENAME_BIRTH, "birth", 569);
   make_list (mysql, FILENAME_DEATH, "death", 570);
   close_database (mysql);
}
Exemplo n.º 21
0
int
load_database(char *filename)
{
	FILE *in;

	if(database != NULL)
		close_database();

	if ((in = abook_fopen(filename, "r")) == NULL)
		return -1;

	parse_database(in);

	return (items == 0) ? 2 : 0;
}
Exemplo n.º 22
0
int main (int argc, char *argv[])
{
   const char *database;
   if (argc < 2)
     database = "wikidatawiki";
   else
     database = argv[1];

   setlocale (LC_CTYPE, "");   
   MYSQL *mysql = open_named_database (database);
   print_dumpdate (mysql);
   long_texts (mysql, "label", "l", "Item labels");
   long_texts (mysql, "descr", "d", "Item descriptions");
   long_texts (mysql, "alias", "a", "Item aliases");
   long_texts (mysql, "plabel", "pl", "Property labels");
   long_texts (mysql, "pdescr", "pd", "Property descriptions");
   long_texts (mysql, "palias", "pa", "Property aliases");
   close_database (mysql);
   return 0;
}
Exemplo n.º 23
0
void stop_server(){

    /** public function - see header */

    char time_stamp_str[9]="";
    char verbose_date_stamp_str[50]="";
    time_t stop_time=time(NULL);

    //close the db if it's open
    if(db) close_database(GET_CALL_INFO);

    get_time_stamp_str(stop_time, time_stamp_str);
    get_verbose_date_str(stop_time, verbose_date_stamp_str);

    fprintf(stderr, "SERVER STOP at %s on %s\ncheck 'error.log' for details\n", time_stamp_str, verbose_date_stamp_str);

    log_event(EVENT_ERROR, "SERVER STOP at %s on %s\n", time_stamp_str, verbose_date_stamp_str);

    exit(EXIT_FAILURE);
}
Exemplo n.º 24
0
int main(int argc, char *argv[])
{
    int opt = 0;
    int flag = FLAG_IDENTICAL_FILES;
    while ((opt = getopt_long(argc, argv, "isdr", NULL, NULL))
            != -1) {
        switch (opt) {
            case 'i':
                flag = FLAG_IDENTICAL_FILES;
                break;
            case 's':
                flag = FLAG_SIMILAR_FILES;
                break;
            case 'd':
                flag = FLAG_DISTINCT_FILES;
                break;
            case 'r':
                flag = FLAG_INTRA_REDUNDANT_FILES;
                break;
            default:
                return -1;
        }
    }

    open_database();

    if(flag == FLAG_IDENTICAL_FILES)
        collect_identical_files();
    else if(flag == FLAG_SIMILAR_FILES)
        collect_similar_files();
    else if(flag == FLAG_DISTINCT_FILES)
        collect_distinct_files();
    else if(flag == FLAG_INTRA_REDUNDANT_FILES)
        collect_intra_redundant_files();

    close_database();

    return 0;
}
Exemplo n.º 25
0
//************************************************************************
// read pr_status file for expired probes. Construct fake results
// for those.
//***********************************************************************
int run(void)
{
  dbi_result result;
  dbi_conn conn;
  int count = 0;

  conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME),
                        OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (!conn) return 0;

  LOG(LOG_INFO, "processing ..");
  uw_setproctitle("reading info from database");
  result = db_query(conn, 0, "select pr_realm.id, pr_realm.name, pr_realm.host, "
                              "       pr_realm.port, pr_realm.db, pr_realm.user, "
                              "       pr_realm.password "
                              "from   pr_realm "
                              "where  pr_realm.id > 1");
  if (result) {
    while (dbi_result_next_row(result)) {
      struct dbspec db;

      db.domid = dbi_result_get_uint(result, "id");
      db.realm = dbi_result_get_string(result, "name");
      db.host = dbi_result_get_string(result, "host");
      db.port = dbi_result_get_uint(result, "port");
      db.db = dbi_result_get_string(result, "db");
      db.user = dbi_result_get_string(result, "user");
      db.password = dbi_result_get_string(result, "password");
      uw_setproctitle("checking %s", dbi_result_get_string(result, "name"));
      LOG(LOG_DEBUG, "checking %s", dbi_result_get_string(result, "name"));
      count += find_expired_probes(&db);
    }
    dbi_result_free(result);
  }
  close_database(conn);
  LOG(LOG_INFO, "sleeping");
  return count;
}
Exemplo n.º 26
0
main()
{
  printf("hello\n");
  char* ptr = malloc(5);
  convertLengthTo2Bytes(ptr, 5);

  printf("%d\n", ptr[1]);

  
  open_database("compare.dat");
  char* in =  "Name913221111111111111222222222222222222221222111111111111122222222222222222222N12221111111111111222222222222222222222222222222222226Name412221111111111111222222222222222222221222111111111111122222222222222222222N12221111111111111222222222222222222222222222222222221Name112221111111111111222222222222222222221222111111111111122222222222222222222N12221111111111111222222222222222222222222222222222226";
  char* coma = compareSongsToClient(in, 2);
  char* comb = compareSongsToServer(in, 2);

  int lena = getLength(coma);
  coma += 2;
  for(int i = 0; i < lena; i++)
  {
    printf("song %s\n", coma);
    coma += SONG_LENGTH;
    printf("sha %s\n", coma);
    coma += SHA_LENGTH;
  }
  //printf("a: %s\n", coma);

  int lenb = getLength(comb);
  comb += 2;
  printf("\nnext\n");
  for(int i = 0; i < lenb; i++)
  {
    printf("song %s\n", comb);
    comb += SONG_LENGTH;
    printf("sha %s\n", comb);
    comb += SHA_LENGTH;
  }
  close_database();
}
Exemplo n.º 27
0
void exit_client(const char *err)
{
    const char *msg = err ? err : "";
    json_t *exit_obj;
    
    if (err)
	log_msg("Client error: %s. Exit.", err);
    
    if (outfd != -1) {
	exit_obj = json_object();
	
	json_object_set_new(exit_obj, "error", err ? json_true() : json_false());
	json_object_set_new(exit_obj, "message", json_string(msg));
	if (can_send_msg)
	    client_msg("server_error", exit_obj);
	else
	    json_decref(exit_obj);
	
	usleep(100); /* try to make sure the server process handles write() before close(). */
	close(infd);
	close(outfd);
	infd = outfd = -1;
    }
    
    termination_flag = 3; /* make sure the command loop exits if nh_exit_game jumps there */
    if (!sigsegv_flag)
	nh_exit_game(EXIT_FORCE_SAVE); /* might not return here */
    nh_lib_exit();
    close_database();
    if (user_info.username)
	free(user_info.username);
    free_config();
    reset_cached_diplaydata();
    end_logging();
    exit(err != NULL);
}
Exemplo n.º 28
0
	}
	file = menuBar()->addMenu(tr("&File"));
	file->addAction(tr("&New DataBase"), this, SLOT(new_database()),
			QKeySequence::New)
			->setEnabled(OpenDb::hasSqLite());
	file->addAction(tr("&Open DataBase"), this, SLOT(load_database()),
			QKeySequence::Open)
			->setEnabled(OpenDb::hasSqLite());
	file->addAction(tr("Open Remote DataBase"),
			this, SLOT(openRemoteSqlDB()))
			->setEnabled(OpenDb::hasRemoteDrivers());
	file->addMenu(historyMenu);
	file->addAction(tr("Set as default DataBase"), this,
				SLOT(default_database()));
	acList += file->addAction(tr("&Close DataBase"), this,
		SLOT(close_database()), QKeySequence(QKeySequence::Close));

	a = new QAction(tr("Options"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(setOptions()));
	a->setMenuRole(QAction::PreferencesRole);
	file->addAction(a);
	acList += a;

	file->addMenu(languageMenu);
	file->addSeparator();
	a = new QAction(tr("Exit"), this);
	connect(a, SIGNAL(triggered()), qApp, SLOT(quit()));
	a->setMenuRole(QAction::QuitRole);
	file->addAction(a);

	import = menuBar()->addMenu(tr("I&mport"));
Exemplo n.º 29
0
int main (int argc, char *argv[])
{
   const char *database;
   if (argc < 2)
     database = "wikidatawiki";
   else
     database = argv[1];

   MYSQL *mysql = open_named_database (database);
   print_dumpdate (mysql);

   MYSQL_ROW row;
   MYSQL_RES *result = 0;

   typedef struct  {
      int property;
      const char *allowed_values;
      const char *name;
   } taxon;
     
   taxon taxon_list[] = {
      { 89, "7432", "species" },
      { 74, "34740", "genus" },
      { 71, "35409", "family"  },
      { 70, "36602, 10861678", "order"  },
      { 77, "37517, 713623", "class"  },
      { 76, "38348", "phylum" },
      { 75, "36732", "kingdom" },
      { 273, "146481", "domain" },
      { 0, "", ""   }, // end of list
   };
   
   for (taxon *t = taxon_list ; t->property ; ++t)
     {
	result = do_query_use
	  (mysql,
	      "SELECT "
	      " s1.s_item, "
	      " (SELECT l_text FROM label WHERE s1.s_item = l_id AND l_lang = 'en'), "
	      " s2.s_item, "
	      " (SELECT l_text FROM label WHERE s2.s_item = l_id AND l_lang = 'en'), "
	      " s2.s_item_value, "
	      " (SELECT l_text FROM label WHERE s2.s_item_value = l_id AND l_lang = 'en') "
	      "FROM statement s1 " // s1 : use of taxon property
	      "JOIN statement s2 " // s2 : the taxon rank property for the value of s1  
	      "ON s1.s_property = %d "
	      "   AND s1.s_item_value = s2.s_item "
	      "   AND s2.s_property = 105 " // P105 = taxon rank
	      "   AND s2.s_item_value NOT IN (%s) "
	      // "LIMIT 100"
	      ,
	      t->property, t->allowed_values);

	printf ("\n== Conflicting %s values ==\n\n", t->name);
	
	printf ("Items used as value for the [[P:P%d|%s property]] which have "
		"a conflicting [[P:P105|taxon rank property]].\n\n",
		t->property, t->name);
	printf ("{| class=wikitable\n");
	printf ("! Item \n");
	printf ("! %s value\n", t->name);
	printf ("! the value's taxon rank value\n");
	int count = 0;
	while (NULL != (row = mysql_fetch_row (result)))
	  {
	     ++ count;
	     if (count > 100)
	       continue;
	     const char *item1 = row[0];
	     const char *label1 = row[1];
	     const char *item2 = row[2];
	     const char *label2 = row[3];
	     const char *rank = row[4];
	     const char *ranklabel = row[5];
	     printf ("|-\n");
	     printf ("| [[Q%s]] (%s)\n", item1, label1 ? label1 : "?");
	     printf ("| [[Q%s]] (%s)\n", item2, label2 ? label2 : "?");
	     printf ("| [[Q%s]] (%s)\n", rank, ranklabel ? ranklabel : "?");
	  }
	printf ("|}\n");
	printf ("Found %d cases.", count);
	if (count > 100)
	  printf (" (Output limited to 100 cases. Ask if more is wanted.)\n");
	printf ("\n");
     }
   
   mysql_free_result (result);
   close_database (mysql);
   return 0;
}
Exemplo n.º 30
0
void MainWindow::init_menu()
{
	QMenu *file, *help, *import, *token;

	file = menuBar()->addMenu(tr("&File"));
	file->addAction(tr("&New DataBase"), this, SLOT(new_database()),
		QKeySequence::New);
	file->addAction(tr("&Open DataBase"), this, SLOT(load_database()),
		QKeySequence::Open);
	file->addAction(tr("Generate DH parameter"), this,
				 SLOT(generateDHparam()));
	acList += file->addAction(tr("&Close DataBase"), this,
		SLOT(close_database()), QKeySequence(QKeySequence::Close));
	acList += file->addAction(tr("&Dump DataBase"), this,
				SLOT(dump_database()));
	acList += file->addAction(tr("C&hange DataBase password"), this,
				SLOT(changeDbPass()));
	acList += file->addAction(tr("&Import old db_dump"), this,
				SLOT(import_dbdump()));
	acList += file->addAction(tr("&Undelete items"), this,
				SLOT(undelete()));
	file->addSeparator();
	acList += file->addAction(tr("Options"), this, SLOT(setOptions()));
	file->addSeparator();
	file->addAction(tr("Exit"), qApp, SLOT(quit()), Qt::ALT+Qt::Key_F4);

	import = menuBar()->addMenu(tr("I&mport"));
	import->addAction(tr("Keys"), this,
				SLOT(on_BNimportKey_clicked()) );
	import->addAction(tr("Requests"), this,
				SLOT(on_BNimportReq_clicked()) );
	import->addAction(tr("Certificates"), this,
				SLOT(on_BNimportCert_clicked()) );
	import->addAction(tr("PKCS#12"), this,
				SLOT(on_BNimportPKCS12_clicked()) );
	import->addAction(tr("PKCS#7"), this,
				SLOT(on_BNimportPKCS7_clicked()) );
	import->addAction(tr("Template"), this,
				SLOT(on_BNimportTemp_clicked()) );
	import->addAction(tr("Revocation list"), this,
				SLOT(on_BNimportCrl_clicked()) );
	import->addAction(tr("PEM file"), this,
				SLOT(loadPem()) );
	import->addAction(tr("paste PEM file"), this,
				SLOT(pastePem()) );

	token = menuBar()->addMenu(tr("&Token"));
	token->addAction(tr("&Manage Security token"), this,
				SLOT(manageToken()));
	token->addAction(tr("&Init Security token"),  this,
				SLOT(initToken()));
	token->addAction(tr("&Change PIN"), this,
				SLOT(changePin()) );
	token->addAction(tr("Change &SO PIN"), this,
				SLOT(changeSoPin()) );
	token->addAction(tr("Init PIN"), this,
				SLOT(initPin()) );

	help = menuBar()->addMenu(tr("&Help") );
	help->addAction(tr("&Content"), this, SLOT(help()),
			QKeySequence::HelpContents);
	help->addAction(tr("&About"), this, SLOT(about()) );
	help->addAction(tr("Donations"), this, SLOT(donations()) );
	wdList += import;
	scardList += token;
}