Exemple #1
0
int main() 
{
    mysql_connect(); 

    list_drivers();
    list_data_sources();
    list_driver_information();
    list_tables();

    execute_query("select * from junk");
    execute_query("select count(*), sum(a) from junk");
    execute_query("select a, a+3, 3.141592654 from junk");
    execute_query("select j1.a, j2.a from junk j1 natural join junk j2");

    mysql_disconnect();
}
Exemple #2
0
/**
 * <A short one line description>
 *
 * <Longer description>
 * <May span multiple lines or paragraphs as needed>
 *
 * @param  Description of method's or function's input parameter
 * @param  ...
 * @return Description of the return value
 */
int main(int argc, char* argv[])
{
	int ch;
    /* keypress character */
	printf("Welcome to poorman's db, type ? for help\n");
	printf(TABLE_OPERATIONS_PROMPT);
    printf("keypress = %08x\n ", ch);
	
	create_table();
	return 0;
	while((ch = getchar()) != EOF){
		switch (ch)
		{
			case 0x31:
				create_table();			
				break;
			case 0x32:
				delete_table();			
				break;
			case 0x33:
				list_tables();			
				break;
			case 0x34:
				select_table();
				break;
			case 0x35:
				return 0;
				break;
			default:
				printf("Command not recognized.\n Type ? for help\n");
				continue;
		}
	}

	return 0;
	
#if 0
	struct record rec;

	sprintf(rec.field[3], "onurkom\n");
	
    printf("--->%s\n", rec.field[3]);
	//printf("size of fx is %d\n", sizeof(rec.field));
    return 0;

#endif
#if 0
	char fx[4][16] = {"1asdasd\n", "2adsasdas\n", "3asdsadas\n", "4asdadasd\n"};
	struct record rec;
    sprintf(fx[3], "onur\n");
   printf("--->%s\n", fx[3]);
	printf("size of fx is %d\n", sizeof(fx));
	char S[10][11];
	int i,j,k;
	char A;
	for (i=0;i<=9;i++){
		scanf ("%s",A);
		for (j=0;j<=10;j++)
		{
			S[i][j]=A;
		}
	}

	for (i=0;i<=9;i++){
		for (j=0;j<=10;j++)
		{
			printf("i=%d j=%d data=%s\n", i,j,S[i][j]);
		}
	}
#endif
#if 0	
	int i,j,k=0;

	for(i=0; i<4; i++)
		for(j=0; j<4; j++)
		{
			sprintf((rec.field[j][i]), "y%d\n", k);
			printf("field %d %d is now %d\n", i,j,k);
			k++;
		}
	
	for(i=0; i<4; i++)

		for(j=0; j<4; j++)
		{
			printf("i=%d j=%d field=%s\n", i,j,rec.field[i][j]);
		}
#endif
	printf("here\n");
	return 0;
}
Exemple #3
0
int main(int argc, char **argv)
{
  int error;
  my_bool first_argument_uses_wildcards=0;
  char *wild;
  MYSQL mysql;
  MY_INIT(argv[0]);
  sf_leaking_memory=1; /* don't report memory leaks on early exits */
  if (load_defaults("my",load_default_groups,&argc,&argv))
    exit(1);

  get_options(&argc,&argv);

  sf_leaking_memory=0; /* from now on we cleanup properly */
  wild=0;
  if (argc)
  {
    char *pos= argv[argc-1], *to;
    for (to= pos ; *pos ; pos++, to++)
    {
      switch (*pos) {
      case '*':
	*pos= '%';
	first_argument_uses_wildcards= 1;
	break;
      case '?':
	*pos= '_';
	first_argument_uses_wildcards= 1;
	break;
      case '%':
      case '_':
	first_argument_uses_wildcards= 1;
	break;
      case '\\':
	pos++;
      default: break;
      }
      *to= *pos;
    }    
    *to= *pos; /* just to copy a '\0'  if '\\' was used */
  }
  if (first_argument_uses_wildcards)
    wild= argv[--argc];
  else if (argc == 3)			/* We only want one field */
    wild= argv[--argc];

  if (argc > 2)
  {
    fprintf(stderr,"%s: Too many arguments\n",my_progname);
    exit(1);
  }
  mysql_init(&mysql);
  if (opt_compress)
    mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
#ifdef HAVE_OPENSSL
  if (opt_use_ssl)
    mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
		  opt_ssl_capath, opt_ssl_cipher);
  mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
                (char*)&opt_ssl_verify_server_cert);
#endif
  if (opt_protocol)
    mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
#ifdef HAVE_SMEM
  if (shared_memory_base_name)
    mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
#endif
  mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);

  if (opt_plugin_dir && *opt_plugin_dir)
    mysql_options(&mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);

  if (opt_default_auth && *opt_default_auth)
    mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth);

  if (!(mysql_real_connect(&mysql,host,user,opt_password,
			   (first_argument_uses_wildcards) ? "" :
                           argv[0],opt_mysql_port,opt_mysql_unix_port,
			   0)))
  {
    fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql));
    exit(1);
  }
  mysql.reconnect= 1;

  switch (argc) {
  case 0:  error=list_dbs(&mysql,wild); break;
  case 1:
    if (opt_status)
      error=list_table_status(&mysql,argv[0],wild);
    else
      error=list_tables(&mysql,argv[0],wild);
    break;
  default:
    if (opt_status && ! wild)
      error=list_table_status(&mysql,argv[0],argv[1]);
    else
      error=list_fields(&mysql,argv[0],argv[1],wild);
    break;
  }
  mysql_close(&mysql);			/* Close & free connection */
  my_free(opt_password);
#ifdef HAVE_SMEM
  my_free(shared_memory_base_name);
#endif
  my_end(my_end_arg);
  exit(error ? 1 : 0);
  return 0;				/* No compiler warnings */
}