|
| 1 | +/***************************************************************************** |
| 2 | +
|
| 3 | +Copyright (c) 2011, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | +
|
| 5 | +This program is free software; you can redistribute it and/or modify it under |
| 6 | +the terms of the GNU General Public License as published by the Free Software |
| 7 | +Foundation; version 2 of the License. |
| 8 | +
|
| 9 | +This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | +
|
| 13 | +You should have received a copy of the GNU General Public License along with |
| 14 | +this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 15 | +Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | +
|
| 17 | +****************************************************************************/ |
| 18 | + |
| 19 | +/**************************************************//** |
| 20 | +@file handler_api.h |
| 21 | +
|
| 22 | +Created 3/14/2011 Jimmy Yang |
| 23 | +*******************************************************/ |
| 24 | + |
| 25 | +#ifndef MYSQL_DML_H |
| 26 | +#define MYSQL_DML_H |
| 27 | + |
| 28 | + |
| 29 | +#define MYSQL_SERVER 1 |
| 30 | + |
| 31 | +#include <my_global.h> |
| 32 | +#include <sql_priv.h> |
| 33 | +#include <stdlib.h> |
| 34 | +#include <ctype.h> |
| 35 | +#include <mysql_version.h> |
| 36 | +#include <mysql/plugin.h> |
| 37 | +#include <my_dir.h> |
| 38 | +#include "my_pthread.h" |
| 39 | +#include "my_sys.h" |
| 40 | +#include "m_string.h" |
| 41 | +#include "sql_plugin.h" |
| 42 | +#include "table.h" |
| 43 | +#include "sql_class.h" |
| 44 | +#include <sql_base.h> |
| 45 | +#include "key.h" |
| 46 | +#include "lock.h" |
| 47 | +#include "transaction.h" |
| 48 | +#include "sql_handler.h" |
| 49 | +#include "handler.h" |
| 50 | + |
| 51 | + |
| 52 | +typedef struct field_arg { |
| 53 | + unsigned int num_arg; |
| 54 | + int* len; |
| 55 | + char** value; |
| 56 | +} field_arg_t; |
| 57 | + |
| 58 | +#define MCI_ADD_FIELD(m_args, m_fld, m_value, m_len) \ |
| 59 | + do { \ |
| 60 | + (m_args)->len[m_fld] = m_len; \ |
| 61 | + (m_args)->value[m_fld] = (char*)(m_value); \ |
| 62 | + } while(0) |
| 63 | + |
| 64 | +#define MCI_CREATE_FIELD(field, num_fld) \ |
| 65 | + do { \ |
| 66 | + field->len = (int*)malloc(num_fld * sizeof(*(field->len)));\ |
| 67 | + memset(field->len, 0, num_fld * sizeof(*(field->len))); \ |
| 68 | + field->value = (char**)malloc(num_fld \ |
| 69 | + * sizeof(*(field->value)));\ |
| 70 | + field->num_arg = num_fld; \ |
| 71 | + } while(0) |
| 72 | + |
| 73 | +#define MCI_FREE_FIELD(field) \ |
| 74 | + do { \ |
| 75 | + free(field->len); \ |
| 76 | + free(field->value); \ |
| 77 | + field->num_arg = 0; \ |
| 78 | + } while(0) |
| 79 | + |
| 80 | +extern "C" { |
| 81 | +/**********************************************************************//** |
| 82 | +Creates a THD object. |
| 83 | +@return a pointer to the THD object, NULL if failed */ |
| 84 | +void* |
| 85 | +handler_create_thd(void); |
| 86 | +/*====================*/ |
| 87 | + |
| 88 | +/**********************************************************************//** |
| 89 | +Creates a MySQL TABLE object with specified database name and table name. |
| 90 | +@return a pointer to the TABLE object, NULL if does not exist */ |
| 91 | +void* |
| 92 | +handler_open_table( |
| 93 | +/*===============*/ |
| 94 | + void* thd, /*!< in: THD* */ |
| 95 | + const char* db_name, /*!< in: database name */ |
| 96 | + const char* table_name, /*!< in: table name */ |
| 97 | + int lock_mode); /*!< in: lock mode */ |
| 98 | + |
| 99 | +/**********************************************************************//** |
| 100 | +Wrapper of function binlog_log_row() to binlog an operation on a row */ |
| 101 | +void |
| 102 | +handler_binlog_row( |
| 103 | +/*===============*/ |
| 104 | + void* my_table); /*!< in: Table metadata */ |
| 105 | + |
| 106 | +/**********************************************************************//** |
| 107 | +Flush binlog from cache to binlog file */ |
| 108 | +void |
| 109 | +handler_binlog_flush( |
| 110 | +/*=================*/ |
| 111 | + void* my_thd, /*!< in: THD* */ |
| 112 | + void* my_table); /*!< in: TABLE structure */ |
| 113 | + |
| 114 | +/**********************************************************************//** |
| 115 | +Flush binlog from cache to binlog file */ |
| 116 | +void |
| 117 | +handler_binlog_flush( |
| 118 | +/*=================*/ |
| 119 | + void* my_thd, /*!< in: THD* */ |
| 120 | + void* my_table); /*!< in: Table metadata */ |
| 121 | + |
| 122 | +/**********************************************************************//** |
| 123 | +Reset TABLE->record[0] */ |
| 124 | +void |
| 125 | +handler_rec_init( |
| 126 | + void* table); /*!< in: Table metadata */ |
| 127 | + |
| 128 | +/**********************************************************************//** |
| 129 | +Set up a char based field in TABLE->record[0] */ |
| 130 | +void |
| 131 | +handler_rec_setup_str( |
| 132 | +/*==================*/ |
| 133 | + void* table, /*!< in/out: TABLE structure */ |
| 134 | + int field_id, /*!< in: Field ID for the field */ |
| 135 | + const char* str, /*!< in: string to set */ |
| 136 | + int len); /*!< in: length of string */ |
| 137 | + |
| 138 | +/**********************************************************************//** |
| 139 | +Set up an integer field in TABLE->record[0] */ |
| 140 | +void |
| 141 | +handler_rec_setup_int( |
| 142 | +/*==================*/ |
| 143 | + void* table, /*!< in/out: TABLE structure */ |
| 144 | + int field_id, /*!< in: Field ID for the field */ |
| 145 | + int value, /*!< in: value to set */ |
| 146 | + bool unsigned_flag); /*!< in: whether it is unsigned */ |
| 147 | +/**********************************************************************//** |
| 148 | +Unlock a table and commit the transaction |
| 149 | +return 0 if fail to commit the transaction */ |
| 150 | +int |
| 151 | +handler_unlock_table( |
| 152 | +/*=================*/ |
| 153 | + void* my_thd, /*!< in: thread */ |
| 154 | + void* my_table, /*!< in: Table metadata */ |
| 155 | + int my_lock_mode); /*!< in: lock mode */ |
| 156 | +/**********************************************************************//** |
| 157 | +close an handler */ |
| 158 | +void |
| 159 | +handler_close_thd( |
| 160 | +/*==============*/ |
| 161 | + void* my_thd); /*!< in: thread */ |
| 162 | +} |
| 163 | + |
| 164 | +/**********************************************************************//** |
| 165 | +binlog a row operation */ |
| 166 | +extern |
| 167 | +int |
| 168 | + binlog_log_row( |
| 169 | +/*============*/ |
| 170 | + TABLE* table, /*!< in: ptr to TABLE */ |
| 171 | + const uchar *before_record, /*!< in: Before image of record */ |
| 172 | + const uchar *after_record, /*!< in: Current image of record */ |
| 173 | + Log_func* log_func); /*!< in: Log function */ |
| 174 | + |
| 175 | +extern void ha_close_connection(THD* thd); |
| 176 | + |
| 177 | +#ifdef HANDLER_API_MEMCACHED |
| 178 | +/**********************************************************************//** |
| 179 | +Search table for a record with particular search criteria |
| 180 | +@return a pointer to table->record[0] */ |
| 181 | +uchar* |
| 182 | +handler_select_rec( |
| 183 | +/*===============*/ |
| 184 | + THD* thd, /*!< in: thread */ |
| 185 | + TABLE* table, /*!< in: TABLE structure */ |
| 186 | + field_arg_t* srch_args, /*!< in: field to search */ |
| 187 | + int idx_to_use); /*!< in: index to use */ |
| 188 | +/**********************************************************************//** |
| 189 | +Insert a record to the table |
| 190 | +return 0 if successfully inserted */ |
| 191 | +int |
| 192 | +handler_insert_rec( |
| 193 | +/*===============*/ |
| 194 | + THD* thd, /*!< in: thread */ |
| 195 | + TABLE* table, /*!< in: TABLE structure */ |
| 196 | + field_arg_t* store_args); /*!< in: inserting row data */ |
| 197 | +/**********************************************************************//** |
| 198 | +Update a record |
| 199 | +return 0 if successfully inserted */ |
| 200 | +int |
| 201 | +handler_update_rec( |
| 202 | +/*===============*/ |
| 203 | + THD* thd, /*!< in: thread */ |
| 204 | + TABLE* table, /*!< in: TABLE structure */ |
| 205 | + field_arg_t* store_args); /*!< in: update row data */ |
| 206 | + |
| 207 | +/**********************************************************************//** |
| 208 | +Delete a record |
| 209 | +return 0 if successfully inserted */ |
| 210 | +int |
| 211 | +handler_delete_rec( |
| 212 | +/*===============*/ |
| 213 | + THD* thd, /*!< in: thread */ |
| 214 | + TABLE* table); /*!< in: TABLE structure */ |
| 215 | + |
| 216 | +/**********************************************************************//** |
| 217 | +Lock a table |
| 218 | +return A lock structure pointer on success, NULL on error */ |
| 219 | +MYSQL_LOCK * |
| 220 | +handler_lock_table( |
| 221 | +/*===============*/ |
| 222 | + THD* thd, /*!< in: thread */ |
| 223 | + TABLE* table, /*!< in: Table metadata */ |
| 224 | + enum thr_lock_type lock_mode); /*!< in: lock mode */ |
| 225 | + |
| 226 | +#endif /* HANDLER_API_MEMCACHED */ |
| 227 | +#endif |
| 228 | + |
0 commit comments