Databases Reference
In-Depth Information
else
fflush(fhtml);
return 0;
}
See how we flush the write buffer at the end of the statement? When the statement
ends, MySQL removes its table lock from our table and another thread may start
using it. If that thread opens the file and starts reading it, it needs to see all of the
data—we cannot allow half of the inserted rows to sit in the write buffer after the
statement ends.
So far so good, but there is one problem—under LOCK TABLES the method
external_lock() is not called at the beginning of every statement. Because
external_lock() has already locked its file during the LOCK TABLES statement,
MySQL does not see a reason to call external_lock() again as the file is still
locked. It may be fine for file locking and MyISAM, but we need to know when the
statement starts even under LOCK TABLES ! For this very reason MySQL developers
have introduced a separate method, start_stmt() , which is called at the beginning
of every statement under LOCK TABLES . For our engine we can simply call
external_lock() here, to save the data_end offset.
int ha_html::start_stmt(THD *thd, thr_lock_type lock_type)
{
return external_lock(thd, F_WRLCK);
}
There is no end_stmt() method, but we do not need one anyway—we do not have
to flush the write buffer at the end of every statement under LOCK TABLES , because
while LOCK TABLES is in effect no other thread can read the table we are writing to.
ha_html.h
Having written all of the methods, we can complete the class declaration. This is
what our ha_html.h header should look like:
#include <mysql_priv.h>
#define HEADER1 "<html><head><title>"
#define HEADER2 "</title></head><body><table border=1>\n"
#define FOOTER "</table></body></html>"
#define FOOTER_LEN ((int)(sizeof(FOOTER)-1))
typedef struct st_html_share {
const char *name;
THR_LOCK lock;
 
Search WWH ::




Custom Search