⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ha_tina.cc

📁 这是linux下运行的mysql软件包,可用于linux 下安装 php + mysql + apach 的网络配置
💻 CC
📖 第 1 页 / 共 2 页
字号:
}/*   Open a database file. Keep in mind that tables are caches, so  this will not be called for every request. Any sort of positions  that need to be reset should be kept in the ::extra() call.*/int ha_tina::open(const char *name, int mode, uint test_if_locked){  DBUG_ENTER("ha_tina::open");  if (!(share= get_share(name, table)))    DBUG_RETURN(1);  thr_lock_data_init(&share->lock,&lock,NULL);  ref_length=sizeof(off_t);  DBUG_RETURN(0);}/*  Close a database file. We remove ourselves from the shared strucutre.  If it is empty we destroy it and free the mapped file.*/int ha_tina::close(void){  DBUG_ENTER("ha_tina::close");  DBUG_RETURN(free_share(share));}/*   This is an INSERT. At the moment this handler just seeks to the end  of the file and appends the data. In an error case it really should  just truncate to the original position (this is not done yet).*/int ha_tina::write_row(byte * buf){  int size;  DBUG_ENTER("ha_tina::write_row");  statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);  if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)    table->timestamp_field->set_time();  size= encode_quote(buf);  if (my_write(share->data_file, buffer.ptr(), size, MYF(MY_WME | MY_NABP)))    DBUG_RETURN(-1);  /*     Ok, this is means that we will be doing potentially bad things     during a bulk insert on some OS'es. What we need is a cleanup    call for ::write_row that would let us fix up everything after the bulk    insert. The archive handler does this with an extra mutx call, which    might be a solution for this.  */  if (get_mmap(share, 0) > 0)     DBUG_RETURN(-1);  records++;  DBUG_RETURN(0);}/*   This is called for an update.  Make sure you put in code to increment the auto increment, also   update any timestamp data. Currently auto increment is not being  fixed since autoincrements have yet to be added to this table handler.  This will be called in a table scan right before the previous ::rnd_next()  call.*/int ha_tina::update_row(const byte * old_data, byte * new_data){  int size;  DBUG_ENTER("ha_tina::update_row");  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,		      &LOCK_status);  if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)    table->timestamp_field->set_time();  size= encode_quote(new_data);  if (chain_append())    DBUG_RETURN(-1);  if (my_write(share->data_file, buffer.ptr(), size, MYF(MY_WME | MY_NABP)))    DBUG_RETURN(-1);  DBUG_RETURN(0);}/*   Deletes a row. First the database will find the row, and then call this method.  In the case of a table scan, the previous call to this will be the ::rnd_next()  that found this row.  The exception to this is an ORDER BY. This will cause the table handler to walk  the table noting the positions of all rows that match a query. The table will  then be deleted/positioned based on the ORDER (so RANDOM, DESC, ASC).*/int ha_tina::delete_row(const byte * buf){  DBUG_ENTER("ha_tina::delete_row");  statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);  if (chain_append())    DBUG_RETURN(-1);  --records;  DBUG_RETURN(0);}/*  Fill buf with value from key. Simply this is used for a single index read   with a key.*/int ha_tina::index_read(byte * buf, const byte * key,                        uint key_len __attribute__((unused)),                        enum ha_rkey_function find_flag                        __attribute__((unused))){  DBUG_ENTER("ha_tina::index_read");  DBUG_ASSERT(0);  DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);}/*  Fill buf with value from key. Simply this is used for a single index read   with a key.  Whatever the current key is we will use it. This is what will be in "index".*/int ha_tina::index_read_idx(byte * buf, uint index, const byte * key,                            uint key_len __attribute__((unused)),                            enum ha_rkey_function find_flag                            __attribute__((unused))){  DBUG_ENTER("ha_tina::index_read_idx");  DBUG_ASSERT(0);  DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);}/*  Read the next position in the index.*/int ha_tina::index_next(byte * buf){  DBUG_ENTER("ha_tina::index_next");  DBUG_ASSERT(0);  DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);}/*  Read the previous position in the index.*/int ha_tina::index_prev(byte * buf){  DBUG_ENTER("ha_tina::index_prev");  DBUG_ASSERT(0);  DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);}/*  Read the first position in the index*/int ha_tina::index_first(byte * buf){  DBUG_ENTER("ha_tina::index_first");  DBUG_ASSERT(0);  DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);}/*  Read the last position in the index  With this we don't need to do a filesort() with index.  We just read the last row and call previous.*/int ha_tina::index_last(byte * buf){  DBUG_ENTER("ha_tina::index_last");  DBUG_ASSERT(0);  DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);}/*   All table scans call this first.   The order of a table scan is:  ha_tina::store_lock  ha_tina::external_lock  ha_tina::info  ha_tina::rnd_init  ha_tina::extra  ENUM HA_EXTRA_CACHE   Cash record in HA_rrnd()  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::rnd_next  ha_tina::extra  ENUM HA_EXTRA_NO_CACHE   End cacheing of records (def)  ha_tina::external_lock  ha_tina::extra  ENUM HA_EXTRA_RESET   Reset database to after open  Each call to ::rnd_next() represents a row returned in the can. When no more   rows can be returned, rnd_next() returns a value of HA_ERR_END_OF_FILE.   The ::info() call is just for the optimizer.*/int ha_tina::rnd_init(bool scan){  DBUG_ENTER("ha_tina::rnd_init");  current_position= next_position= 0;  records= 0;  records_is_known= 0;  chain_ptr= chain;#ifdef HAVE_MADVISE  if (scan)    (void)madvise(share->mapped_file,share->file_stat.st_size,MADV_SEQUENTIAL);#endif  DBUG_RETURN(0);}/*  ::rnd_next() does all the heavy lifting for a table scan. You will need to populate *buf  with the correct field data. You can walk the field to determine at what position you   should store the data (take a look at how ::find_current_row() works). The structure  is something like:  0Foo  Dog  Friend  The first offset is for the first attribute. All space before that is reserved for null count.  Basically this works as a mask for which rows are nulled (compared to just empty).  This table handler doesn't do nulls and does not know the difference between NULL and "". This  is ok since this table handler is for spreadsheets and they don't know about them either :)*/int ha_tina::rnd_next(byte *buf){  DBUG_ENTER("ha_tina::rnd_next");  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,		      &LOCK_status);  current_position= next_position;  if (!share->mapped_file)     DBUG_RETURN(HA_ERR_END_OF_FILE);  if (HA_ERR_END_OF_FILE == find_current_row(buf) )     DBUG_RETURN(HA_ERR_END_OF_FILE);  records++;  DBUG_RETURN(0);}/*  In the case of an order by rows will need to be sorted.  ::position() is called after each call to ::rnd_next(),   the data it stores is to a byte array. You can store this  data via my_store_ptr(). ref_length is a variable defined to the   class that is the sizeof() of position being stored. In our case    its just a position. Look at the bdb code if you want to see a case   where something other then a number is stored.*/void ha_tina::position(const byte *record){  DBUG_ENTER("ha_tina::position");  my_store_ptr(ref, ref_length, current_position);  DBUG_VOID_RETURN;}/*   Used to fetch a row from a posiion stored with ::position().   my_get_ptr() retrieves the data for you.*/int ha_tina::rnd_pos(byte * buf, byte *pos){  DBUG_ENTER("ha_tina::rnd_pos");  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,		      &LOCK_status);  current_position= my_get_ptr(pos,ref_length);  DBUG_RETURN(find_current_row(buf));}/*  ::info() is used to return information to the optimizer.  Currently this table handler doesn't implement most of the fields  really needed. SHOW also makes use of this data*/void ha_tina::info(uint flag){  DBUG_ENTER("ha_tina::info");  /* This is a lie, but you don't want the optimizer to see zero or 1 */  if (!records_is_known && records < 2)     records= 2;  DBUG_VOID_RETURN;}/*  Grab bag of flags that are sent to the able handler every so often.  HA_EXTRA_RESET and HA_EXTRA_RESET_STATE are the most frequently called.  You are not required to implement any of these.*/int ha_tina::extra(enum ha_extra_function operation){  DBUG_ENTER("ha_tina::extra");  DBUG_RETURN(0);}/*   This is no longer used.*/int ha_tina::reset(void){  DBUG_ENTER("ha_tina::reset");  ha_tina::extra(HA_EXTRA_RESET);  DBUG_RETURN(0);}/*  Called after deletes, inserts, and updates. This is where we clean up all of  the dead space we have collected while writing the file. */int ha_tina::rnd_end(){  DBUG_ENTER("ha_tina::rnd_end");  records_is_known= 1;  /* First position will be truncate position, second will be increment */  if ((chain_ptr - chain)  > 0)  {    tina_set *ptr;    off_t length;    /*       Setting up writable map, this will contain all of the data after the      get_mmap call that we have added to the file.    */    if (get_mmap(share, 1) > 0)       DBUG_RETURN(-1);    length= share->file_stat.st_size;    /*      The sort handles updates/deletes with random orders.      It also sorts so that we move the final blocks to the      beginning so that we move the smallest amount of data possible.    */    qsort(chain, (size_t)(chain_ptr - chain), sizeof(tina_set), (qsort_cmp)sort_set);    for (ptr= chain; ptr < chain_ptr; ptr++)    {      memmove(share->mapped_file + ptr->begin, share->mapped_file + ptr->end,              length - (size_t)ptr->end);      length= length - (size_t)(ptr->end - ptr->begin);    }    /* Truncate the file to the new size */    if (my_chsize(share->data_file, length, 0, MYF(MY_WME)))      DBUG_RETURN(-1);    if (munmap(share->mapped_file, length))      DBUG_RETURN(-1);    /* We set it to null so that get_mmap() won't try to unmap it */    share->mapped_file= NULL;    if (get_mmap(share, 0) > 0)       DBUG_RETURN(-1);  }  DBUG_RETURN(0);}/*   DELETE without WHERE calls it*/int ha_tina::delete_all_rows(){  DBUG_ENTER("ha_tina::delete_all_rows");  if (!records_is_known)    return (my_errno=HA_ERR_WRONG_COMMAND);  int rc= my_chsize(share->data_file, 0, 0, MYF(MY_WME));  if (get_mmap(share, 0) > 0)     DBUG_RETURN(-1);  records=0;  DBUG_RETURN(rc);}/*  Always called by the start of a transaction (or by "lock tables");*/int ha_tina::external_lock(THD *thd, int lock_type){  DBUG_ENTER("ha_tina::external_lock");  DBUG_RETURN(0);          // No external locking}/*   Called by the database to lock the table. Keep in mind that this  is an internal lock.*/THR_LOCK_DATA **ha_tina::store_lock(THD *thd,                                    THR_LOCK_DATA **to,                                    enum thr_lock_type lock_type){  if (lock_type != TL_IGNORE && lock.type == TL_UNLOCK)    lock.type=lock_type;  *to++= &lock;  return to;}/*   Create a table. You do not want to leave the table open after a call to  this (the database will call ::open() if it needs to).*/int ha_tina::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info){  char name_buff[FN_REFLEN];  File create_file;  DBUG_ENTER("ha_tina::create");  if ((create_file= my_create(fn_format(name_buff,name,"",".CSV",MY_REPLACE_EXT|MY_UNPACK_FILENAME),0,                              O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)    DBUG_RETURN(-1);  my_close(create_file,MYF(0));  DBUG_RETURN(0);}#endif /* enable CSV */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -