Пример #1
0
int main(int argc, char **argv) {

    char *queryp;
    int bool_balance;

    sanitize_input(&argc, argv);

    if (argv[1][0] == 's') {
        print_summary(argv[2]);
        exit(0);
    }

    mysql_start();

    bool_balance = check_balance(&argc, argv);

    queryp = forge_query(&argc, argv);

    mysql_insert(queryp);

    if (bool_balance)
        calculate_balance(&argc, argv);

    mysql_stop();

    return 0;
}
Пример #2
0
int print_summary(char *category)
{
	printf("Printing Summary\n");
	mysql_start();

	if (category) {
		snprintf(query, BUFSIZE, "select id, day, upper(category), format(amount/100,2), description from acct where"
				" category = '%s'", category);
		mysql_select(query);
		printf("Total: $");
		snprintf(query, BUFSIZE, "select sum(format(amount/100,2)) from acct where"
				" category = '%s'", category);
		mysql_select(query);
	}
	else {
		mysql_select("select id, day, upper(category), format(amount/100,2), description from acct");
		printf("Balance: $");
		mysql_select_last("select format(amount/100,2) from balance");
		printf("\n");
	}

	mysql_stop();

	return 0;
}
Пример #3
0
/******************************************************************************

  mysql_restart()

  Restart the mysql servers.

******************************************************************************/
void mysql_restart()
{
  log_info("Restarting the MySQL server(s): %u", ++restarts);

  mysql_stop();

  mysql_start();
}
Пример #4
0
/******************************************************************************

  main()
  
******************************************************************************/
int main(int argc, char **argv)
{
  int is_ignore_list = 0;
  // setup
  setup(argv[0]);
  
  /* The --ignore option is comma saperated list of test cases to skip and
     should be very first command line option to the test suite. 

     The usage is now:
     mysql_test_run --ignore=test1,test2 test3 test4
     where test1 and test2 are test cases to ignore
     and test3 and test4 are test cases to run.
  */
  if (argc >= 2 && !strnicmp(argv[1], "--ignore=", sizeof("--ignore=")-1))
  {
    char *temp, *token;
    temp= strdup(strchr(argv[1],'=') + 1);
    for (token=str_tok(temp, ","); token != NULL; token=str_tok(NULL, ","))
    {
      if (strlen(ignore_test) + strlen(token) + 2 <= PATH_MAX-1)
        sprintf(ignore_test+strlen(ignore_test), " %s ", token);
      else
      {
        free(temp);
        die("ignore list too long.");
      }
    }
    free(temp);
    is_ignore_list = 1;
  }
  // header
  log_msg("MySQL Server %s, for %s (%s)\n\n", VERSION, SYSTEM_TYPE, MACHINE_TYPE);
  
  log_msg("Initializing Tests...\n");
  
  // install test databases
  mysql_install_db();
  
  log_msg("Starting Tests...\n");
  
  log_msg("\n");
  log_msg(HEADER);
  log_msg(DASH);

  if ( argc > 1 + is_ignore_list )
  {
    int i;

    // single test
    single_test = TRUE;

    for (i = 1 + is_ignore_list; i < argc; i++)
    {
      // run given test
      run_test(argv[i]);
    }
  }
  else
  {
    // run all tests
    DIR *dir = opendir(test_dir);
    DIR *entry;
    char test[NAME_MAX];
    char *p;
    
    // single test
    single_test = FALSE;    

    if (dir == NULL)
    {
      die("Unable to open tests directory.");
    }
    
    while((entry = readdir(dir)) != NULL)
    {
      if (!S_ISDIR(entry->d_type))
      {
        strcpy(test, strlwr(entry->d_name));
        
        // find the test suffix
        if ((p = strindex(test, TEST_SUFFIX)) != NULL)
        {
          // null terminate at the suffix
          *p = '\0';

          // run test
          run_test(test);
        }
      }
    }
    
    closedir(dir);
  }

  // stop server
  mysql_stop();

  log_msg(DASH);
  log_msg("\n");

  log_msg("Ending Tests...\n");

  // report stats
  report_stats();

  // close log
  if (log_fd) fclose(log_fd);

  // keep results up
  pressanykey();

  return 0;
}