~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/events_ms.cc

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2010 PrimeBase Technologies GmbH, Germany
3
 
 *
4
 
 *  This program is free software; you can redistribute it and/or modify
5
 
 *  it under the terms of the GNU General Public License as published by
6
 
 *  the Free Software Foundation; version 2 of the License.
7
 
 *
8
 
 *  This program is distributed in the hope that it will be useful,
9
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 *  GNU General Public License for more details.
12
 
 *
13
 
 *  You should have received a copy of the GNU General Public License
14
 
 *  along with this program; if not, write to the Free Software
15
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16
 
 *
17
 
 * Barry Leslie
18
 
 *
19
 
 * 2010-06-01
20
 
 */
21
 
 
22
 
#include "config.h"
23
 
#include <string>
24
 
#include <inttypes.h>
25
 
 
26
 
#include <drizzled/session.h>
27
 
#include <drizzled/field/blob.h>
28
 
 
29
 
#include "cslib/CSConfig.h"
30
 
#include "cslib/CSGlobal.h"
31
 
#include "cslib/CSStrUtil.h"
32
 
#include "cslib/CSThread.h"
33
 
 
34
 
#include "events_ms.h"
35
 
#include "parameters_ms.h"
36
 
#include "engine_ms.h"
37
 
 
38
 
using namespace drizzled;
39
 
using namespace plugin;
40
 
using namespace std;
41
 
 
42
 
 
43
 
//==================================
44
 
// My table event observers: 
45
 
#ifdef OLD_WAY
46
 
static bool insertRecord(TableEventData &data, unsigned char *new_row)
47
 
{
48
 
        Field_blob *field;
49
 
        unsigned char *blob_rec;
50
 
        char *blob_url, *possible_blob_url;
51
 
        char safe_url[PBMS_BLOB_URL_SIZE+1];
52
 
        PBMSBlobURLRec blob_url_buffer;
53
 
        size_t packlength, i, length, org_length;
54
 
        int32_t err;
55
 
        PBMSResultRec result;
56
 
        
57
 
        for (i= 0; i < data.table.sizeBlobFields(); i++) {
58
 
                field = data.table.getBlobFieldAt(i);
59
 
 
60
 
                // Get the blob record:
61
 
                blob_rec = new_row + field->offset(data.table.getInsertRecord());
62
 
                packlength = field->pack_length() - data.table.getBlobPtrSize();
63
 
 
64
 
                length = field->get_length(blob_rec);
65
 
                memcpy(&possible_blob_url, blob_rec +packlength, sizeof(char*));
66
 
                org_length = field->get_length(blob_rec);
67
 
                
68
 
                // Signal PBMS to record a new reference to the BLOB.
69
 
                // If 'blob' is not a BLOB URL then it will be stored in the repositor as a new BLOB
70
 
                // and a reference to it will be created.
71
 
                if (MSEngine::couldBeURL(possible_blob_url, length) == false) {
72
 
                        err = MSEngine::createBlob(data.table.getSchemaName(), data.table.getTableName(), possible_blob_url, length, &blob_url_buffer, &result);
73
 
                        if (err) {
74
 
                                // If it fails log the error and continue to try and release any other BLOBs in the row.
75
 
                                fprintf(stderr, "PBMSEvents: createBlob(\"%s.%s\") error (%d):'%s'\n", 
76
 
                                        data.table.getSchemaName(), data.table.getTableName(), result.mr_code,  result.mr_message);
77
 
                                        
78
 
                                return true;
79
 
                        }                               
80
 
                        blob_url = blob_url_buffer.bu_data;
81
 
                } else {
82
 
                        // The BLOB URL may not be null terminate, if so
83
 
                        // then copy it to a safe buffer and terminate it.
84
 
                        if (possible_blob_url[length]) {
85
 
                                memcpy(safe_url, possible_blob_url, length);
86
 
                                safe_url[length] = 0;
87
 
                                blob_url = safe_url;
88
 
                        } else
89
 
                                blob_url = possible_blob_url;
90
 
                }
91
 
                
92
 
                // Signal PBMS to delete the reference to the BLOB.
93
 
                err = MSEngine::referenceBlob(data.table.getSchemaName(), data.table.getTableName(), &blob_url_buffer, blob_url, field->position(), &result);
94
 
                if (err) {
95
 
                        // If it fails log the error and continue to try and release any other BLOBs in the row.
96
 
                        fprintf(stderr, "PBMSEvents: referenceBlob(\"%s.%s\", \"%s\" ) error (%d):'%s'\n", 
97
 
                                data.table.getSchemaName(), data.table.getTableName(), blob_url, result.mr_code,  result.mr_message);
98
 
                                
99
 
                        return true;
100
 
                }
101
 
                
102
 
                // The URL is modified on insert so if the BLOB length changed reset it. 
103
 
                // This will happen if the BLOB data was replaced with a BLOB reference. 
104
 
                length = strlen(blob_url_buffer.bu_data)  +1;
105
 
                if ((length != org_length) || memcmp(blob_url_buffer.bu_data, possible_blob_url, length)) {
106
 
                        char *blob = possible_blob_url; // This is the BLOB as the server currently sees it.
107
 
                        
108
 
                        if (length != org_length) {
109
 
                                field->store_length(blob_rec, packlength, length);
110
 
                        }
111
 
                        
112
 
                        if (length > org_length) {
113
 
                                // This can only happen if the BLOB URL is actually larger than the BLOB itself.
114
 
                                blob = (char *) data.session.alloc(length);
115
 
                                memcpy(blob_rec+packlength, &blob, sizeof(char*));
116
 
                        }                       
117
 
                        memcpy(blob, blob_url_buffer.bu_data, length);
118
 
                } 
119
 
        }
120
 
 
121
 
        return false;
122
 
}
123
 
 
124
 
//---
125
 
static bool deleteRecord(TableEventData &data, const unsigned char *old_row)
126
 
{
127
 
        Field_blob *field;
128
 
        const char *blob_rec;
129
 
        unsigned char *blob_url;
130
 
        size_t packlength, i, length;
131
 
        int32_t err;
132
 
        PBMSResultRec result;
133
 
        bool call_failed = false;
134
 
        
135
 
        for (i= 0; i < data.table.sizeBlobFields(); i++) {
136
 
                field = data.table.getBlobFieldAt(i);
137
 
 
138
 
                // Get the blob record:
139
 
                blob_rec = (char *)old_row + field->offset(data.table.getInsertRecord());
140
 
                packlength = field->pack_length() - data.table.getBlobPtrSize();
141
 
 
142
 
                length = field->get_length((unsigned char *)blob_rec);
143
 
                memcpy(&blob_url, blob_rec +packlength, sizeof(char*));
144
 
                
145
 
                // Check to see if this is a valid URL.
146
 
                if (MSEngine::couldBeURL(blob_url, length)) {
147
 
                
148
 
                        // The BLOB URL may not be null terminate, if so
149
 
                        // then copy it to a safe buffer and terminate it.
150
 
                        char safe_url[PBMS_BLOB_URL_SIZE+1];
151
 
                        if (blob_url[length]) {
152
 
                                memcpy(safe_url, blob_url, length);
153
 
                                safe_url[length] = 0;
154
 
                                blob_url = safe_url;
155
 
                        }
156
 
                        
157
 
                        // Signal PBMS to delete the reference to the BLOB.
158
 
                        err = MSEngine::dereferenceBlob(data.table.getSchemaName(), data.table.getTableName(), blob_url, &result);
159
 
                        if (err) {
160
 
                                // If it fails log the error and continue to try and release any other BLOBs in the row.
161
 
                                fprintf(stderr, "PBMSEvents: dereferenceBlob(\"%s.%s\") error (%d):'%s'\n", 
162
 
                                        data.table.getSchemaName(), data.table.getTableName(), result.mr_code,  result.mr_message);
163
 
                                        
164
 
                                call_failed = true;
165
 
                        }
166
 
                }
167
 
        }
168
 
 
169
 
        return call_failed;
170
 
}
171
 
#endif
172
 
 
173
 
static bool insertRecord(const char *db, const char *table_name, char *possible_blob_url,  size_t length, 
174
 
        Session &session, Field_blob *field, unsigned char *blob_rec, size_t packlength)
175
 
{
176
 
        char *blob_url;
177
 
        char safe_url[PBMS_BLOB_URL_SIZE+1];
178
 
        PBMSBlobURLRec blob_url_buffer;
179
 
        size_t org_length = length;
180
 
        int32_t err;
181
 
        PBMSResultRec result;
182
 
        
183
 
        // Tell PBMS to record a new reference to the BLOB.
184
 
        // If 'blob' is not a BLOB URL then it will be stored in the repositor as a new BLOB
185
 
        // and a reference to it will be created.
186
 
        
187
 
        if (MSEngine::couldBeURL(possible_blob_url, length) == false) {
188
 
                err = MSEngine::createBlob(db, table_name, possible_blob_url, length, &blob_url_buffer, &result);
189
 
                if (err) {
190
 
                        // If it fails log the error and continue to try and release any other BLOBs in the row.
191
 
                        fprintf(stderr, "PBMSEvents: createBlob(\"%s.%s\") error (%d):'%s'\n", 
192
 
                                db, table_name, result.mr_code,  result.mr_message);
193
 
                                
194
 
                        return true;
195
 
                }                               
196
 
                blob_url = blob_url_buffer.bu_data;
197
 
        } else {
198
 
                // The BLOB URL may not be null terminate, if so
199
 
                // then copy it to a safe buffer and terminate it.
200
 
                if (possible_blob_url[length]) {
201
 
                        memcpy(safe_url, possible_blob_url, length);
202
 
                        safe_url[length] = 0;
203
 
                        blob_url = safe_url;
204
 
                } else
205
 
                        blob_url = possible_blob_url;
206
 
        }
207
 
        
208
 
        // Tell PBMS to add a reference to the BLOB.
209
 
        err = MSEngine::referenceBlob(db, table_name, &blob_url_buffer, blob_url, field->position(), &result);
210
 
        if (err) {
211
 
                // If it fails log the error and continue to try and release any other BLOBs in the row.
212
 
                fprintf(stderr, "PBMSEvents: referenceBlob(\"%s.%s\", \"%s\" ) error (%d):'%s'\n", 
213
 
                        db, table_name, blob_url, result.mr_code,  result.mr_message);
214
 
                        
215
 
                return true;
216
 
        }
217
 
        
218
 
        // The URL is modified on insert so if the BLOB length changed reset it. 
219
 
        // This will happen if the BLOB data was replaced with a BLOB reference. 
220
 
        length = strlen(blob_url_buffer.bu_data)  +1;
221
 
        if ((length != org_length) || memcmp(blob_url_buffer.bu_data, possible_blob_url, length)) {
222
 
                char *blob = possible_blob_url; // This is the BLOB as the server currently sees it.
223
 
                
224
 
                if (length != org_length) {
225
 
                        field->store_length(blob_rec, packlength);
226
 
                }
227
 
                
228
 
                if (length > org_length) {
229
 
                        // This can only happen if the BLOB URL is actually larger than the BLOB itself.
230
 
                        blob = (char *) session.getMemRoot()->allocate(length);
231
 
                        memcpy(blob_rec+packlength, &blob, sizeof(char*));
232
 
                }                       
233
 
                memcpy(blob, blob_url_buffer.bu_data, length);
234
 
        } 
235
 
 
236
 
        return false;
237
 
}
238
 
 
239
 
//---
240
 
static bool deleteRecord(const char *db, const char *table_name, char *blob_url,  size_t length)
241
 
{
242
 
        int32_t err;
243
 
        char safe_url[PBMS_BLOB_URL_SIZE+1];
244
 
        PBMSResultRec result;
245
 
        bool call_failed = false;
246
 
        
247
 
        // Check to see if this is a valid URL.
248
 
        if (MSEngine::couldBeURL(blob_url, length)) {
249
 
        
250
 
                // The BLOB URL may not be null terminate, if so
251
 
                // then copy it to a safe buffer and terminate it.
252
 
                if (blob_url[length]) {
253
 
                        memcpy(safe_url, blob_url, length);
254
 
                        safe_url[length] = 0;
255
 
                        blob_url = safe_url;
256
 
                }
257
 
                
258
 
                // Signal PBMS to delete the reference to the BLOB.
259
 
                err = MSEngine::dereferenceBlob(db, table_name, blob_url, &result);
260
 
                if (err) {
261
 
                        // If it fails log the error and continue to try and release any other BLOBs in the row.
262
 
                        fprintf(stderr, "PBMSEvents: dereferenceBlob(\"%s.%s\") error (%d):'%s'\n", 
263
 
                                db, table_name, result.mr_code,  result.mr_message);
264
 
                                
265
 
                        call_failed = true;
266
 
                }
267
 
        }
268
 
 
269
 
        return call_failed;
270
 
}
271
 
 
272
 
//---
273
 
static bool observeBeforeInsertRecord(BeforeInsertRecordEventData &data)
274
 
{
275
 
        Field_blob *field;
276
 
        unsigned char *blob_rec;
277
 
        char *blob_url;
278
 
        size_t packlength, i, length;
279
 
 
280
 
        for (i= 0; i < data.table.sizeBlobFields(); i++) {
281
 
                field = data.table.getBlobFieldAt(i);
282
 
                
283
 
                if (field->is_null_in_record(data.row))
284
 
                        continue;
285
 
                        
286
 
                // Get the blob record:
287
 
                packlength = field->pack_length() - data.table.getBlobPtrSize();
288
 
 
289
 
                blob_rec = (unsigned char *)data.row + field->offset(data.table.getInsertRecord());
290
 
                length = field->get_length(blob_rec);
291
 
                memcpy(&blob_url, blob_rec +packlength, sizeof(char*));
292
 
 
293
 
                if (insertRecord(data.table.getSchemaName(), data.table.getTableName(), 
294
 
                        blob_url, length, data.session, field, blob_rec, packlength))
295
 
                        return true;
296
 
        }
297
 
 
298
 
        return false;
299
 
}
300
 
 
301
 
//---
302
 
static bool observeAfterInsertRecord(AfterInsertRecordEventData &data)
303
 
{
304
 
        bool has_blob = false;
305
 
        
306
 
        for (uint32_t i= 0; (i < data.table.sizeBlobFields()) && (has_blob == false); i++) {
307
 
                Field_blob *field = data.table.getBlobFieldAt(i);
308
 
                
309
 
                if ( field->is_null_in_record(data.row) == false)
310
 
                        has_blob = true;
311
 
        }
312
 
        
313
 
        if  (has_blob)
314
 
                MSEngine::callCompleted(data.err == 0);
315
 
        
316
 
        return false;
317
 
}
318
 
 
319
 
//---
320
 
static bool observeBeforeUpdateRecord(BeforeUpdateRecordEventData &data)
321
 
{
322
 
        Field_blob *field;
323
 
        uint32_t field_offset;
324
 
        const unsigned char *old_blob_rec;
325
 
        unsigned char *new_blob_rec= NULL;
326
 
        char *old_blob_url, *new_blob_url;
327
 
        size_t packlength, i, old_length= 0, new_length= 0;
328
 
        const unsigned char *old_row = data.old_row;
329
 
        unsigned char *new_row = data.new_row;
330
 
        const char *db = data.table.getSchemaName();
331
 
        const char *table_name = data.table.getTableName();
332
 
        bool old_null, new_null;
333
 
 
334
 
        for (i= 0; i < data.table.sizeBlobFields(); i++) {
335
 
                field = data.table.getBlobFieldAt(i);
336
 
                
337
 
                new_null = field->is_null_in_record(new_row);           
338
 
                old_null = field->is_null_in_record(old_row);
339
 
                
340
 
                if (new_null && old_null)
341
 
                        continue;
342
 
                
343
 
                // Check to see if the BLOB data was updated.
344
 
 
345
 
                // Get the blob records:
346
 
                field_offset = field->offset(data.table.getInsertRecord());
347
 
                packlength = field->pack_length() - data.table.getBlobPtrSize();
348
 
 
349
 
                if (new_null) {
350
 
                        new_blob_url = NULL;
351
 
                } else {
352
 
                        new_blob_rec = new_row + field_offset;
353
 
                        new_length = field->get_length(new_blob_rec);
354
 
                        memcpy(&new_blob_url, new_blob_rec +packlength, sizeof(char*));
355
 
                }
356
 
                
357
 
                if (old_null) {
358
 
                        old_blob_url = NULL;
359
 
                } else {
360
 
                        old_blob_rec = old_row + field_offset;
361
 
                        old_length = field->get_length(old_blob_rec);
362
 
                        memcpy(&old_blob_url, old_blob_rec +packlength, sizeof(char*));
363
 
                }
364
 
                
365
 
                // Check to see if the BLOBs are the same.
366
 
                // I am assuming that if the BLOB pointer is different then teh BLOB has changed.
367
 
                // Zero length BLOBs are a special case because they may have a NULL data pointer,
368
 
                // to catch this and distiguish it from a NULL BLOB I do a check to see if one field was NULL:
369
 
                // (old_null != new_null)
370
 
                if ((old_blob_url != new_blob_url) || (old_null != new_null)) {
371
 
                        
372
 
                        // The BLOB was updated so delete the old one and insert the new one.
373
 
                        if ((old_null == false) && deleteRecord(db, table_name, old_blob_url, old_length))
374
 
                                return true;
375
 
                                
376
 
                        if ((new_null == false) && insertRecord(db, table_name, new_blob_url, new_length, data.session, field, new_blob_rec, packlength))
377
 
                                return true;
378
 
 
379
 
                }
380
 
                
381
 
        }
382
 
 
383
 
        return false;
384
 
}
385
 
 
386
 
//---
387
 
static bool observeAfterUpdateRecord(AfterUpdateRecordEventData &data)
388
 
{
389
 
        bool has_blob = false;
390
 
        const unsigned char *old_row = data.old_row;
391
 
        const unsigned char *new_row = data.new_row;
392
 
        
393
 
        for (uint32_t i= 0; (i < data.table.sizeBlobFields()) && (has_blob == false); i++) {
394
 
                Field_blob *field = data.table.getBlobFieldAt(i);               
395
 
                bool new_null = field->is_null_in_record(new_row);              
396
 
                bool old_null = field->is_null_in_record(old_row);
397
 
                
398
 
                if ( (new_null == false) || (old_null == false)) {
399
 
                        const unsigned char *blob_rec;                  
400
 
                        size_t field_offset = field->offset(data.table.getInsertRecord());
401
 
                        size_t packlength = field->pack_length() - data.table.getBlobPtrSize();
402
 
                        char *old_blob_url, *new_blob_url;
403
 
                        
404
 
                        blob_rec = new_row + field_offset;
405
 
                        memcpy(&new_blob_url, blob_rec +packlength, sizeof(char*));
406
 
 
407
 
                        blob_rec = old_row + field_offset;
408
 
                        memcpy(&old_blob_url, blob_rec +packlength, sizeof(char*));
409
 
 
410
 
                        has_blob = ((old_blob_url != new_blob_url) || (old_null != new_null));
411
 
                }
412
 
        }
413
 
        
414
 
        if  (has_blob)
415
 
                MSEngine::callCompleted(data.err == 0);
416
 
 
417
 
  return false;
418
 
}
419
 
 
420
 
//---
421
 
static bool observeAfterDeleteRecord(AfterDeleteRecordEventData &data)
422
 
{
423
 
        Field_blob *field;
424
 
        const unsigned char *blob_rec;
425
 
        char *blob_url;
426
 
        size_t packlength, i, length;
427
 
        bool call_failed = false;
428
 
        bool has_blob = false;
429
 
        
430
 
        if (data.err != 0)
431
 
                return false;
432
 
 
433
 
        for (i= 0; (i < data.table.sizeBlobFields()) && (call_failed == false); i++) {
434
 
                field = data.table.getBlobFieldAt(i);
435
 
                
436
 
                if (field->is_null_in_record(data.row))
437
 
                        continue;
438
 
                        
439
 
                has_blob = true;        
440
 
                // Get the blob record:
441
 
                packlength = field->pack_length() - data.table.getBlobPtrSize();
442
 
 
443
 
                blob_rec = data.row + field->offset(data.table.getInsertRecord());
444
 
                length = field->get_length(blob_rec);
445
 
                memcpy(&blob_url, blob_rec +packlength, sizeof(char*));
446
 
 
447
 
                if (deleteRecord(data.table.getSchemaName(), data.table.getTableName(), blob_url, length))
448
 
                        call_failed = true;
449
 
        }
450
 
        
451
 
        if (has_blob)
452
 
                MSEngine::callCompleted(call_failed == false);
453
 
                
454
 
        return call_failed;
455
 
}
456
 
 
457
 
//==================================
458
 
// My session event observers: 
459
 
static bool observeAfterDropDatabase(AfterDropDatabaseEventData &data)
460
 
{
461
 
        PBMSResultRec result;
462
 
        if (data.err != 0)
463
 
                return false;
464
 
 
465
 
        if (MSEngine::dropDatabase(data.db.c_str(), &result) != 0) {
466
 
                fprintf(stderr, "PBMSEvents: dropDatabase(\"%s\") error (%d):'%s'\n", 
467
 
                        data.db.c_str(), result.mr_code,  result.mr_message);
468
 
        }
469
 
        
470
 
        // Always return no error for after drop database. What could the server do about it?
471
 
        return false;
472
 
}
473
 
 
474
 
//==================================
475
 
// My schema event observers: 
476
 
static bool observeAfterDropTable(AfterDropTableEventData &data)
477
 
{
478
 
        PBMSResultRec result;
479
 
        if (data.err != 0)
480
 
                return false;
481
 
 
482
 
        if (MSEngine::dropTable(data.table.getSchemaName().c_str(), data.table.getTableName().c_str(), &result) != 0) {
483
 
                fprintf(stderr, "PBMSEvents: dropTable(\"%s.%s\") error (%d):'%s'\n", 
484
 
                        data.table.getSchemaName().c_str(), data.table.getTableName().c_str(), result.mr_code,  result.mr_message);
485
 
                return true;
486
 
        }
487
 
        MSEngine::callCompleted(true);
488
 
        
489
 
        return false;
490
 
}
491
 
 
492
 
//---
493
 
static bool observeAfterRenameTable(AfterRenameTableEventData &data)
494
 
{
495
 
        PBMSResultRec result;
496
 
        if (data.err != 0)
497
 
                return false;
498
 
 
499
 
        const char *from_db = data.from.getSchemaName().c_str();
500
 
        const char *from_table = data.from.getTableName().c_str();
501
 
        const char *to_db = data.to.getSchemaName().c_str();
502
 
        const char *to_table = data.to.getTableName().c_str();
503
 
        
504
 
        if (MSEngine::renameTable(from_db, from_table, to_db, to_table, &result) != 0) {
505
 
                fprintf(stderr, "PBMSEvents: renameTable(\"%s.%s\" To \"%s.%s\") error (%d):'%s'\n", 
506
 
                        from_db, from_table, to_db, to_table, result.mr_code,  result.mr_message);
507
 
                return true;
508
 
        }
509
 
        MSEngine::callCompleted(true);
510
 
        
511
 
        return false;
512
 
}
513
 
 
514
 
//==================================
515
 
/* This is where I register which table events my pluggin is interested in.*/
516
 
void PBMSEvents::registerTableEventsDo(TableShare &table_share, EventObserverList &observers)
517
 
{
518
 
  if ((PBMSParameters::isPBMSEventsEnabled() == false) 
519
 
    || (PBMSParameters::isBLOBTable(table_share.getSchemaName(), table_share.getTableName()) == false))
520
 
    return;
521
 
    
522
 
  if (table_share.blob_fields > 0) {
523
 
          registerEvent(observers, BEFORE_INSERT_RECORD, PBMSParameters::getBeforeInsertEventPosition()); // I want to be called first if passible
524
 
          registerEvent(observers, AFTER_INSERT_RECORD); 
525
 
          registerEvent(observers, BEFORE_UPDATE_RECORD, PBMSParameters::getBeforeUptateEventPosition());
526
 
          registerEvent(observers, AFTER_UPDATE_RECORD); 
527
 
          registerEvent(observers, AFTER_DELETE_RECORD);
528
 
 }
529
 
}
530
 
 
531
 
//==================================
532
 
/* This is where I register which schema events my pluggin is interested in.*/
533
 
void PBMSEvents::registerSchemaEventsDo(const std::string &db, EventObserverList &observers)
534
 
{
535
 
  if ((PBMSParameters::isPBMSEventsEnabled() == false) 
536
 
    || (PBMSParameters::isBLOBDatabase(db.c_str()) == false))
537
 
    return;
538
 
    
539
 
  registerEvent(observers, AFTER_DROP_TABLE);
540
 
  registerEvent(observers, AFTER_RENAME_TABLE);
541
 
}
542
 
 
543
 
//==================================
544
 
/* This is where I register which schema events my pluggin is interested in.*/
545
 
void PBMSEvents::registerSessionEventsDo(Session &, EventObserverList &observers)
546
 
{
547
 
  if (PBMSParameters::isPBMSEventsEnabled() == false) 
548
 
    return;
549
 
    
550
 
  registerEvent(observers, AFTER_DROP_DATABASE);
551
 
}
552
 
 
553
 
//==================================
554
 
/* The event observer.*/
555
 
bool PBMSEvents::observeEventDo(EventData &data)
556
 
{
557
 
  bool result= false;
558
 
  
559
 
  switch (data.event) {
560
 
  case AFTER_DROP_DATABASE:
561
 
    result = observeAfterDropDatabase((AfterDropDatabaseEventData &)data);
562
 
    break;
563
 
    
564
 
  case AFTER_DROP_TABLE:
565
 
    result = observeAfterDropTable((AfterDropTableEventData &)data);
566
 
    break;
567
 
    
568
 
  case AFTER_RENAME_TABLE:
569
 
    result = observeAfterRenameTable((AfterRenameTableEventData &)data);
570
 
    break;
571
 
    
572
 
  case BEFORE_INSERT_RECORD:
573
 
     result = observeBeforeInsertRecord((BeforeInsertRecordEventData &)data);
574
 
    break;
575
 
    
576
 
  case AFTER_INSERT_RECORD:
577
 
    result = observeAfterInsertRecord((AfterInsertRecordEventData &)data);
578
 
    break;
579
 
    
580
 
 case BEFORE_UPDATE_RECORD:
581
 
    result = observeBeforeUpdateRecord((BeforeUpdateRecordEventData &)data);
582
 
    break;
583
 
             
584
 
  case AFTER_UPDATE_RECORD:
585
 
    result = observeAfterUpdateRecord((AfterUpdateRecordEventData &)data);
586
 
    break;
587
 
    
588
 
  case AFTER_DELETE_RECORD:
589
 
    result = observeAfterDeleteRecord((AfterDeleteRecordEventData &)data);
590
 
    break;
591
 
 
592
 
  default:
593
 
    fprintf(stderr, "PBMSEvents: Unexpected event '%s'\n", EventObserver::eventName(data.event));
594
 
 
595
 
  }
596
 
  
597
 
  return result;
598
 
}
599