List:Internals« Previous MessageNext Message »
From:ycy0011 Date:November 28 2002 1:26am
Subject:Re: data structrue
View as plain text  

>---------------example.c--------------------------------------
>#include "fulltext.h"
>
>
>int main()
>{
>  MI_INFO *mi;
>  char* buf;
>  int rec_len;
>  int lookup_n[] = { 2,4,3,-1};
>  int *n_p;
>  
>  
>  my_init();
>  /* open the table*/
>  if (!(mi=mi_open("example",O_RDWR,HA_OPEN_ABORT_IF_LOCKED)))
                     ^^^^^^^
      Sorry, I have a question about this line.
      You don't tell the program which database to use.
      How can it works? Or I should put the table example in some
      directory?

>  {
>    die("Could not open example table");
>  }
>  rec_len = mi->s->base.reclength;
>  printf("record length is %d\n", rec_len);
>  if (!(buf=(char*)my_malloc(rec_len,MYF(MY_WME))))
>    die("Out of memory");
>  /* start scan */
>  if (mi_scan_init(mi))
>  {
>    die("Scan initialization failed");
>  }
>  printf("Scanning the table:\n");
>  for (;;)
>  {
>    int error = mi_scan(mi,buf);
>    if (error)
>    {
>      if (error != HA_ERR_END_OF_FILE)
>      {
>       fprintf(stderr, "Error reading record: error code=%d\n", error);
>       exit(1);
>      }
>      break;
>    }
>    print_record(buf);
>  }
>  printf("Performing a lookup on the primary key\n");
>  for (n_p=lookup_n;*n_p != -1; n_p++)
>  {
>    char key[N_LEN];
>    int error;
>    int4store(key,*n_p);
>    error=mi_rkey(mi,buf,PRIMARY_KEY_NUM,key,N_LEN,HA_READ_KEY_EXACT);
>    printf("Key %d: ", *n_p);
>    if (error)
>    {
>      if (error != HA_ERR_KEY_NOT_FOUND)
>      {
>	fprintf(stderr,"Read error from handler: %d\n", error);
>	exit(1);
>      }
>      else
>	printf("Not found\n");
>    }
>    else
>      print_record(buf);
>  }
>  
>  my_free(buf,MYF(0));
>  mi_close(mi);
>}

regards

==================================================================
Sinamail付費信箱,20MB、50MB、100MB
      功能一樣讚  容量由你選   新浪給你最好的!



Thread
Re: data structrueycy001128 Nov
  • Re: data structrueSasha Pachev28 Nov