Merge lp:~2591kuldeep/libdrizzle/libdrizzle-binlogapi into lp:libdrizzle

Proposed by kuldeep porwal
Status: Needs review
Proposed branch: lp:~2591kuldeep/libdrizzle/libdrizzle-binlogapi
Merge into: lp:libdrizzle
Diff against target: 3507 lines (+3312/-0)
35 files modified
docs/binlogapi/colum_value.rst (+37/-0)
docs/binlogapi/event_data.rst (+69/-0)
docs/binlogapi/event_header.rst (+26/-0)
docs/binlogapi/event_interface.rst (+10/-0)
docs/binlogapi/helper.rst (+209/-0)
docs/binlogapi/query_event.rst (+110/-0)
docs/binlogapi/row_event.rst (+196/-0)
docs/binlogapi/row_iterator.rst (+37/-0)
docs/binlogapi/table_map_event.rst (+130/-0)
docs/binlogapi/xid_event.rst (+75/-0)
docs/examples/binlog-read-api.rst (+110/-0)
libdrizzle-5.1/binlog_client.h (+15/-0)
libdrizzle-5.1/binlogapi.h (+36/-0)
libdrizzle-5.1/column_value.h (+39/-0)
libdrizzle-5.1/drizzle_client.h (+1/-0)
libdrizzle-5.1/event_data.h (+69/-0)
libdrizzle-5.1/event_header.h (+67/-0)
libdrizzle-5.1/event_interface.h (+51/-0)
libdrizzle-5.1/helper.h (+155/-0)
libdrizzle-5.1/include.am (+15/-0)
libdrizzle-5.1/query_event.h (+155/-0)
libdrizzle-5.1/row_event.h (+181/-0)
libdrizzle-5.1/row_iterator.h (+35/-0)
libdrizzle-5.1/table_map_event.h (+203/-0)
libdrizzle-5.1/xid_event.h (+95/-0)
libdrizzle/commonapi.h (+1/-0)
libdrizzle/event_data.cc (+61/-0)
libdrizzle/event_header.cc (+67/-0)
libdrizzle/helper.cc (+286/-0)
libdrizzle/include.am (+15/-0)
libdrizzle/query_event.cc (+126/-0)
libdrizzle/row_event.cc (+297/-0)
libdrizzle/row_iterator.cc (+16/-0)
libdrizzle/table_map_event.cc (+235/-0)
libdrizzle/xid_event.cc (+82/-0)
To merge this branch: bzr merge lp:~2591kuldeep/libdrizzle/libdrizzle-binlogapi
Reviewer Review Type Date Requested Status
Wim Lewis (community) Needs Fixing
Stewart Smith (community) Approve
Review via email: mp+180569@code.launchpad.net

Description of the change

Currently only have api to read header for MySQL binlog events. I have built the extended api to read event data also. (libdrizzle/binlogevent)

To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote :

Approved with simple changes of adding copyright headers in all new source files (and modifying existing ones).

review: Approve
126. By kuldeep <kuldeep@kuldeep-laptop>

xid event added

127. By kuldeep <kuldeep@kuldeep-laptop>

copyright headers added

128. By kuldeep <kuldeep@kuldeep-laptop>

Bug fix for Row Event and modified api a bit for row_iterator

129. By kuldeep <kuldeep@kuldeep-laptop>

exception handling

130. By kuldeep <kuldeep@kuldeep-laptop>

Adding Tested code on local environment, now we can access the new api functions within library

131. By kuldeep <kuldeep@kuldeep-laptop>

Documentation Done, Resolved few dangling pointer bugs

132. By kuldeep <kuldeep@kuldeep-laptop>

Example added

Revision history for this message
Wim Lewis (wiml-omni) wrote :

Some observations on the unmarshaling code in helper.cc:

+uint32_t getByte3(int pos,const unsigned char* data)
+{
+ if((int)(sizeof(data)-pos)<3)
+ {

I don't think this is doing what you want, since sizeof(data) will just return the size of a pointer on the machine, not the size of the data buffer pointed to by data. If you want to know that, you'll need to pass it in to the function somehow, e.g. as a "data_len" argument.

The gratuitous cast to (int) is sometimes a sign of badness. size_t is not the same size as int on all platforms, for example. What is the actual range of possible values for pos? IMHO it would be better to write this conditional so as not to need a cast, for example
   if ((pos+3) > size_of_data_buffer)

assuming that both pos and size_of_data_buffer are of integer types guaranteed to be large enough to hold the size of a data buffer.

+ return UINT_MAX;

Returning an in-range error value for this kind of error makes me uncomfortable. For getByte4(), etc, how does the caller know whether the call succeeded?

For these particular functions, the only way they can fail is if there isn't enough data in the buffer. Since that the caller will have to test for the error return and handle it, it makes just as much sense for the check to be the caller's responsibility. This ends up requiring no more code at the calling site (in fact, it can use less code, if you can combine several checks) and simplifies getByteN()'s API (since you don't have to figure out how to return an error indication that is distinguishable from a success indication).

+ tmpMask=((uint32_t)data[pos]&tmpMask);

There are some macros in <libdrizzle-5.1/constants.h> for doing this kind of unpacking; you may be able to simplify the code by using them.

review: Needs Fixing

Unmerged revisions

132. By kuldeep <kuldeep@kuldeep-laptop>

Example added

131. By kuldeep <kuldeep@kuldeep-laptop>

Documentation Done, Resolved few dangling pointer bugs

130. By kuldeep <kuldeep@kuldeep-laptop>

Adding Tested code on local environment, now we can access the new api functions within library

129. By kuldeep <kuldeep@kuldeep-laptop>

exception handling

128. By kuldeep <kuldeep@kuldeep-laptop>

Bug fix for Row Event and modified api a bit for row_iterator

127. By kuldeep <kuldeep@kuldeep-laptop>

copyright headers added

126. By kuldeep <kuldeep@kuldeep-laptop>

xid event added

125. By kuldeep <kuldeep@kuldeep-laptop>

Added binlogevent api

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'docs/binlogapi'
2=== added file 'docs/binlogapi/colum_value.rst'
3--- docs/binlogapi/colum_value.rst 1970-01-01 00:00:00 +0000
4+++ docs/binlogapi/colum_value.rst 2013-09-23 11:52:14 +0000
5@@ -0,0 +1,37 @@
6+ColumnValue
7+===========
8+
9+Introduction
10+------------
11+
12+Binlog API contains class which gives structure for column value of any row event.
13+
14+.. autoclass:: ColumnValue
15+
16+ :members: value,is_null,col_num
17+
18+
19+
20+Constructor
21+-----------
22+
23+.. cc:function:: ColumnValue(std::string st,bool _bool,int col_n)
24+
25+ Set's the data member respectively.
26+
27+
28+Getter Function
29+---------------
30+
31+.. cc:function:: getValue()
32+
33+ returns Value of column as string
34+
35+.. cc:function:: isNull()
36+
37+ return column is null or not
38+
39+.. cc:fucntion:: getColumnNum()
40+
41+ return position of column in original schema.
42+
43
44=== added file 'docs/binlogapi/event_data.rst'
45--- docs/binlogapi/event_data.rst 1970-01-01 00:00:00 +0000
46+++ docs/binlogapi/event_data.rst 2013-09-23 11:52:14 +0000
47@@ -0,0 +1,69 @@
48+Event Data
49+==========
50+
51+Introduction
52+------------
53+
54+This class is capable to return the objects for different events with their corresponding header and data parsed.
55+
56+.. warnings::
57+ This API will only work for Row Based Logs
58+
59+.. autoclass:: EventData
60+
61+ :members: _data
62+
63+Constructor
64+-----------
65+
66+It will initialize the EventData object with given MySQL binary log data. we can update this later with setData(below)
67+
68+
69+Getter Functions
70+----------------
71+
72+.. cc:function:: void getTableMap(TableMapEvent& tableMap)
73+
74+ This function will fill the tablemap object with event raw data
75+ :param tableMap: reference to TableMapEvent object
76+
77+.. cc:function:: void getWriteEvent(RowEvent& writeEvent)
78+
79+ This function will fill the writeEvent object with event raw data
80+
81+ :param writeEvent: reference to RowEvent object
82+
83+.. cc:function:: void getUpdateEvent(RowEvent& updateEvent)
84+
85+ This function will fill the updateEvent object with event raw data
86+
87+ :param updateEvent: reference to RowEvent object
88+
89+.. cc:function:: void getDeleteEvent(RowEvent& deleteEvent)
90+
91+ This function will fill the deleteEvent object with event raw data
92+
93+ :param deleteEvent: reference to RowEvent object
94+
95+.. cc:function:: void getQueryEvent(RowEvent& queryEvent)
96+
97+ This function will fill the queryEvent object with event raw data
98+
99+ :param queryEvent: reference to RowEvent object
100+
101+.. cc:function:: void getXidEvent(XidEvent& xidEvent)
102+
103+ This function will fill the xidEvent object with event raw data
104+
105+ :param xidEvent: reference to XidEvent object
106+
107+
108+Setter Function
109+---------------
110+
111+.. cc:function:: void setdata(const unsigned char* data)
112+
113+ This function will update the MySQL binary log data in event data object whenever we read a new binlog
114+
115+ :param data: binary Data for a MySQL binlog
116+
117
118=== added file 'docs/binlogapi/event_header.rst'
119--- docs/binlogapi/event_header.rst 1970-01-01 00:00:00 +0000
120+++ docs/binlogapi/event_header.rst 2013-09-23 11:52:14 +0000
121@@ -0,0 +1,26 @@
122+EventHeader
123+==========
124+
125+
126+Introduction
127+------------
128+
129+This class parses the data and set all the header varibles.
130+
131+.. autoclass:: EventHeader
132+
133+ :members: timestamp,type,server_id,event_size,log_pos,flag
134+
135+Constructor
136+-----------
137+
138+It will initialize all its data members to -1
139+
140+
141+Setter Functions
142+----------------
143+
144+
145+.. cc:function:: int setHeader(unsigned const char* data)
146+
147+ Set the parsed values of timestamp,type,server_id,event_size,log_pos,flag into given object.
148
149=== added file 'docs/binlogapi/event_interface.rst'
150--- docs/binlogapi/event_interface.rst 1970-01-01 00:00:00 +0000
151+++ docs/binlogapi/event_interface.rst 2013-09-23 11:52:14 +0000
152@@ -0,0 +1,10 @@
153+Event_Interface Functions
154+=========================
155+
156+Introduction
157+------------
158+
159+Every event type must implement this. Provide event interface for every event.
160+
161+
162+
163
164=== added file 'docs/binlogapi/helper.rst'
165--- docs/binlogapi/helper.rst 1970-01-01 00:00:00 +0000
166+++ docs/binlogapi/helper.rst 2013-09-23 11:52:14 +0000
167@@ -0,0 +1,209 @@
168+Helper Functions
169+================
170+
171+Introduction
172+------------
173+
174+Helper contains functions which give binlog api the capabilities to parse binary MySQL logs.
175+
176+.. warning::
177+ You should call any binlogapi functions with the raw data for corresponding event otherwise you may end up getting INT_MAX or INT_MIN type of values which may or may not be erroneous.
178+
179+
180+MySQL Fields
181+------------
182+
183+.. cc:type:: enum_field_types
184+
185+ An ENUM of the possible MySQL field types
186+
187+ .. py:data:: MYSQL_TYPE_DECIMAL
188+
189+ .. py:data:: MYSQL_TYPE_TINY
190+
191+ .. py:data:: MYSQL_TYPE_SHORT
192+
193+ .. py:data:: MYSQL_TYPE_LONG
194+
195+ .. py:data:: MYSQL_TYPE_FLOAT
196+
197+ .. py:data:: MYSQL_TYPE_DOUBLE
198+
199+ .. py:data:: MYSQL_TYPE_NULL
200+
201+ .. py:data:: MYSQL_TYPE_TIMESTAMP
202+
203+ .. py:data:: MYSQL_TYPE_LONGLONG
204+
205+ .. py:data:: MYSQL_TYPE_INT24
206+
207+ .. py:data:: MYSQL_TYPE_DATE
208+
209+ .. py:data:: MYSQL_TYPE_TIME
210+
211+ .. py:data:: MYSQL_TYPE_DATETIME
212+
213+ .. py:data:: MYSQL_TYPE_YEAR
214+
215+ .. py:data:: MYSQL_TYPE_NEWDATE
216+
217+ .. py:data:: MYSQL_TYPE_VARCHAR
218+
219+ .. py:data:: MYSQL_TYPE_BIT
220+
221+ .. py:data:: MYSQL_TYPE_NEWDECIMAL
222+
223+ .. py:data:: MYSQL_TYPE_ENUM
224+
225+ .. py:data:: MYSQL_TYPE_SET
226+
227+ .. py:data:: MYSQL_TYPE_TINY_BLOB
228+
229+ .. py:data:: MYSQL_TYPE_MEDIUM_BLOB
230+
231+ .. py:data:: MYSQL_TYPE_LONG_BLOB
232+
233+ .. py:data:: MYSQL_TYPE_BLOB
234+
235+ .. py:data:: MYSQL_TYPE_VAR_STRING
236+
237+ .. py:data:: MYSQL_TYPE_STRING
238+
239+ .. py:data:: MYSQL_TYPE_GEOMETRY
240+
241+.. cc:type:: enum_field_bytes
242+
243+ An ENUM of formats in which Field types are stored
244+
245+ .. py:data:: LEN_ENC_STR
246+
247+ Length Encoded String
248+
249+ .. py:data:: READ_1_BYTE
250+
251+ .. py:data:: READ_2_BYTE
252+
253+ .. py:data:: READ_4_BYTE
254+
255+ .. py:data:: READ_8_BYTE
256+
257+ .. py:data:: NOT_FOUND
258+
259+ No format for corresponding field type present
260+
261+.. cc:type:: enum_event_type
262+
263+ An ENUM for possible Event Types
264+
265+ .. py:data:: TABLE_MAP_EVENT
266+
267+ .. py:data:: WRITE_ROWS_EVENTv1
268+
269+ v1 is for version number
270+
271+ .. py:data:: UPDATE_ROWS_EVENTv1
272+
273+ v1 is for version number
274+
275+ .. py:data:: DELETE_ROWS_EVENTv1
276+
277+ v1 is for version number
278+
279+.. cc:type:: enum_col_type
280+
281+ An ENUM for getting the filed type in abstract level.
282+
283+ .. py:data:: STRING
284+
285+ Type is string
286+
287+ .. py:data:: INT
288+
289+ Type is INTEGER
290+
291+Functions
292+---------
293+
294+.. cc:function:: bool getNextBit(uint8_t& val)
295+
296+ Returns the next bit of the number (LSB)
297+
298+ :param val: The number
299+
300+.. cc:function:: uint16_t getByte2(int pos,const unsigned char* data)
301+
302+ get 2 byte number from raw data
303+
304+ :param pos: Start psosition
305+ :param data: Raw Data of binlog
306+
307+.. cc:function:: uint32_t getByte3(int pos,const unsigned char* data)
308+
309+ get 3 byte number from raw data
310+
311+ :param pos: Start psosition
312+ :param data: Raw Data of binlog
313+
314+.. cc:function:: uint32_t getByte4(int pos,const unsigned char* data)
315+
316+ get 4 byte number from raw data
317+
318+ :param pos: Start psosition
319+ :param data: Raw Data of binlog
320+
321+.. cc:function:: uint64_t getByte6(int pos,const unsigned char* data)
322+
323+ get 6 byte number from raw data
324+
325+ :param pos: Start psosition
326+ :param data: Raw Data of binlog
327+
328+.. cc:function:: uint64_t getByte8(int pos,const unsigned char* data)
329+
330+ get 8 byte number from raw data
331+
332+ :param pos: Start psosition
333+ :param data: Raw Data of binlog
334+
335+.. cc:function:: char * getString(int pos,int len,const unsigned char * data)
336+
337+ Gets the string of specified length
338+
339+ :param pos: Start position
340+ :param len: Length of string to read
341+ :param data: Raw data from which we have to read the string
342+
343+.. cc:function:: uint64_t getEncodedLen(int& pos,const unsigned char * data)
344+
345+ This will decode the Length Encoded string and returns the number of byted we should read. It will also update the start pos.
346+
347+ :param pos: reference to start position
348+ :param data: Raw data which conatins LenEncoded string
349+
350+.. cc:function:: int lookup_metadata_field_size(enum_field_types field_type)
351+
352+ Returns the Meta len of given field type
353+
354+ :param field_type: The field type (enum)
355+
356+.. cc:function:: string getIntToStr(uint64_t num)
357+
358+ converts int to string
359+
360+ :param num: The integer
361+
362+.. cc:function:: int getBoolArray(bool arr[],const unsigned char data[],int start_pos,int _byte,int _bit)
363+
364+ Returns the count of columns not present and also fills the 'arr' with column present bitmap
365+
366+ :param arr: reference to boolean array representing column present bitmap
367+ :param data: Raw data
368+ :param start_pos: start position
369+ :param _byte: total number of bytes to read (remember column count can be less than _byte*8)
370+ :param _bit: Total number of bits(column count) to read
371+
372+.. cc:function:: enum_field_bytes lookup_field_bytes(enum_field_types field_type)
373+
374+ Returns the enum of field bytes which should be read for corresponding column/field type
375+
376+ :param field_type: Field type enum
377
378=== added file 'docs/binlogapi/query_event.rst'
379--- docs/binlogapi/query_event.rst 1970-01-01 00:00:00 +0000
380+++ docs/binlogapi/query_event.rst 2013-09-23 11:52:14 +0000
381@@ -0,0 +1,110 @@
382+QueryEvent
383+==========
384+
385+Introduction
386+------------
387+
388+This class parse the query event.
389+
390+.. autoclass:: QueryEvent
391+
392+ :members: proxy_id, execution_time, schema_length, error_code
393+
394+Constructor
395+-----------
396+
397+It will initialize all its data members to -1
398+
399+Getter Functions
400+----------------
401+
402+
403+.. cc:function::uint32_t getTimestamp()
404+
405+
406+ Returns the timestamp for given event
407+
408+.. cc:function:: uint8_t getType()
409+
410+
411+ Returns the Type for given event
412+
413+.. cc:function:: uint32_t getServerId()
414+
415+
416+ Returns the timestamp for given event
417+
418+.. cc:function:: uint32_t getEventSize()
419+
420+
421+ Returns the Event Size for given event
422+
423+.. cc:function:: uint32_t getLogPos()
424+
425+
426+ Returns the Log Position for next event
427+
428+.. cc:function:: uint32_t getFlagH()
429+
430+
431+ Returns the binlog Event Flag from header
432+
433+
434+.. cc:function:: uint32_t getProxyId()
435+
436+
437+ Returns the proxy id of master
438+
439+.. cc:function:: uint32_t getExecutionTime()
440+
441+
442+ Returns the execution time for the event
443+
444+.. cc:function:: uint32_t getSchemaLength()
445+
446+
447+ Returns the schema length for query
448+
449+.. cc:function:: uint32_t getErrorCode()
450+
451+
452+ Returns the binlog error code for query event
453+
454+
455+Setter Functions
456+----------------
457+
458+.. cc:function:: void initWithData(const unsigned char * data)
459+
460+ Get the raw data and call all the setter functions with appropriate value
461+
462+ :param data: Raw data from binlog
463+
464+.. cc:function:: void setProxyId(uint32_t value)
465+
466+
467+ sets the parsed proxy id of master into its object
468+
469+ :param value: parsed proxy id
470+
471+.. cc:function:: void setExecutionTime(uint32_t value)
472+
473+
474+ sets the execution time for the event into its object
475+
476+ :param value: parsed Execution time
477+
478+.. cc:function:: void setSchemaLength(uint32_t value)
479+
480+
481+ sets the Schema length into its object
482+
483+ :param value: parsed Schema length
484+
485+.. cc:function:: void setErrorCode(uint32_t value)
486+
487+
488+ sets the error code for the event into its object
489+
490+ :param value: parsed Error Code
491+
492
493=== added file 'docs/binlogapi/row_event.rst'
494--- docs/binlogapi/row_event.rst 1970-01-01 00:00:00 +0000
495+++ docs/binlogapi/row_event.rst 2013-09-23 11:52:14 +0000
496@@ -0,0 +1,196 @@
497+RowEvent
498+========
499+
500+
501+Introduction
502+------------
503+
504+This class parse the row event.
505+
506+.. autoclass:: RowEvent
507+
508+ :members: column_type,table_id,flag,column_count,column_null_bitmap, column_bitmap,null_bitmap,rows,row_event_type
509+
510+Constructor
511+-----------
512+
513+It will initialize all its data members to NULL/-1
514+
515+Getter Functions
516+----------------
517+
518+.. cc:function:: void initWithData(const unsigned char * data)
519+
520+ Get the raw data and call all the setter functions with appropriate value
521+
522+ :param data: Raw data from binlog
523+
524+.. cc:function::uint32_t getTimestamp()
525+
526+
527+ Returns the timestamp for given event
528+
529+.. cc:function:: uint8_t getType()
530+
531+
532+ Returns the Type for given event
533+
534+.. cc:function:: uint32_t getServerId()
535+
536+
537+ Returns the timestamp for given event
538+
539+.. cc:function:: uint32_t getEventSize()
540+
541+
542+ Returns the Event Size for given event
543+
544+.. cc:function:: uint32_t getLogPos()
545+
546+
547+ Returns the Log Position for given event
548+
549+.. cc:function:: uint32_t getFlagH()
550+
551+
552+ Returns the flag header for given event
553+
554+
555+
556+Getter Functions
557+----------------
558+
559+.. cc:function:: void initWithData(const unsigned char * data)
560+
561+ Get the raw data and call all the setter functions with appropriate value
562+
563+ :param data: Raw data from binlog
564+
565+.. cc:function::uint32_t getTimestamp()
566+
567+
568+ Returns the timestamp for given event
569+
570+.. cc:function:: uint8_t getType()
571+
572+
573+ Returns the Type for given event
574+
575+.. cc:function:: uint32_t getServerId()
576+
577+
578+ Returns the timestamp for given event
579+
580+.. cc:function:: uint32_t getEventSize()
581+
582+
583+ Returns the Event Size for given event
584+
585+.. cc:function:: uint32_t getLogPos()
586+
587+
588+ Returns the Log Position for given event
589+
590+.. cc:function:: uint32_t getFlagH()
591+
592+
593+ Returns the flag header for given event
594+
595+
596+Getter Functions
597+----------------
598+
599+.. cc:function:: void initWithData(const unsigned char * data)
600+
601+ Get the raw data and call all the setter functions with appropriate value
602+
603+ :param data: Raw data from binlog
604+
605+.. cc:function::uint32_t getTimestamp()
606+
607+
608+ Returns the timestamp for given event
609+
610+.. cc:function:: uint8_t getType()
611+
612+
613+ Returns the Type for given event
614+
615+.. cc:function:: uint32_t getServerId()
616+
617+
618+ Returns the timestamp for given event
619+
620+.. cc:function:: uint32_t getEventSize()
621+
622+
623+ Returns the Event Size for given event
624+
625+.. cc:function:: uint32_t getLogPos()
626+
627+
628+ Returns the Log Position for given event
629+
630+.. cc:function:: uint32_t getFlagH()
631+
632+
633+ Returns the flag header for given event
634+
635+.. cc:function:: uint64_t getTableId()
636+
637+ Return the table id for given event
638+
639+.. cc:function:: uint16_t getFlagPh()
640+
641+ Return the flag of post header for given event
642+
643+.. cc:function:: uint64_t getColumnCount()
644+
645+ Return the number of columns for given event
646+
647+.. cc:function:: bool * getColumnPresentBitmap()
648+
649+ Return the column present bitmap for given event
650+
651+.. cc:function:: RowVector getRows()
652+
653+ Return the rowvector for given event
654+
655+.. cc:function:: int getRowEventType()
656+
657+ Return the event type for given event. There are three kind of evens in row event - Insert,Delete,Update
658+
659+
660+Setter Functions
661+----------------
662+
663+.. cc:function:: void setTableId(uint64_t value)
664+
665+ Set the parsed value of table_id into given object.
666+
667+.. cc:function:: void setFlagPh(uint16_t value)
668+
669+ Set the parsed value of flag into given object.
670+
671+.. cc:function:: void setColumnCount(uint64_t value)
672+
673+ Set the parsed value of column_count into given object.
674+
675+
676+
677+.. cc:function:: TODO
678+
679+ (Update Event)Set the parsed value of column_null_bitmap into given object.
680+
681+.. cc:function:: void setColumnPresentBitmap(bool * value)
682+
683+ Set the parsed value of column_bitmap into given object.
684+
685+.. cc:function:: void setNullBitmap(bool * value)
686+
687+ Set the parsed value of null_bitmap into given object.
688+
689+
690+.. cc:function:: void RowEvent::setRowEventType(int value)
691+
692+ Set the parsed value of row_event_type into given object.
693
694=== added file 'docs/binlogapi/row_iterator.rst'
695--- docs/binlogapi/row_iterator.rst 1970-01-01 00:00:00 +0000
696+++ docs/binlogapi/row_iterator.rst 2013-09-23 11:52:14 +0000
697@@ -0,0 +1,37 @@
698+RowIterator
699+===========
700+
701+Introduction
702+------------
703+
704+This class creates the iterator datatypes to iterate on different rows for a RowEvent.
705+
706+.. warnings::
707+ This will work only in case of Row Based Logging
708+
709+
710+.. autoclass:: RowIterator
711+
712+ :members: vec_rows, vec_col_val
713+
714+Constructor
715+-----------
716+
717+It will initialize all its data members to NULL
718+
719+DataTypes
720+---------
721+
722+.. c:type:: RowVector
723+
724+ Its a vector of ColumnValue vector i.e vector<vector<ColumnValue> >
725+
726+.. c:type:: Row
727+
728+ Its a vector of ColumnValue i.e vector<ColumnValue>
729+
730+
731+
732+
733+
734+
735
736=== added file 'docs/binlogapi/table_map_event.rst'
737--- docs/binlogapi/table_map_event.rst 1970-01-01 00:00:00 +0000
738+++ docs/binlogapi/table_map_event.rst 2013-09-23 11:52:14 +0000
739@@ -0,0 +1,130 @@
740+TableMapEvent
741+=============
742+
743+Introduction
744+------------
745+
746+This class parse the tablemap event.
747+
748+.. autoclass:: TableMapEvent
749+
750+ :members: table_id,flag,schema_name_len,schema_name,table_name_len,table_name,column_count,column_type_def,column_meta_data
751+
752+Constructor
753+-----------
754+
755+It will intialize all its data member to NULL/-1.
756+
757+
758+Getter Functions
759+----------------
760+
761+
762+.. cc:function:: void initWithData(const unsigned char * data)
763+
764+ Get the raw data and call all the setter functions with appropriate value
765+
766+ :param data: Raw data from binlog
767+
768+.. cc:function::uint32_t getTimestamp()
769+
770+
771+ Returns the timestamp for given event
772+
773+.. cc:function:: uint8_t getType()
774+
775+
776+ Returns the Type for given event
777+
778+.. cc:function:: uint32_t getServerId()
779+
780+
781+ Returns the timestamp for given event
782+
783+.. cc:function:: uint32_t getEventSize()
784+
785+
786+ Returns the Event Size for given event
787+
788+.. cc:function:: uint32_t getLogPos()
789+
790+
791+ Returns the Log Position for given event
792+
793+.. cc:function:: uint32_t getFlagH()
794+
795+
796+ Returns the flag header for given event
797+
798+.. cc:function:: uint64_t getTableId()
799+
800+ Return the numeric table id for given event
801+
802+.. cc:funciton:: uint16_t getFlagPh()
803+
804+
805+ Return the flag of post header for given event
806+
807+.. cc:function:: int getSchemaNameLen()
808+
809+
810+ Return the length of the schema name for given event
811+
812+.. cc:function:: char * getSchemaName()
813+
814+ Return the schema name for given event
815+
816+.. cc:function:: int getTableNameLen()
817+
818+ Return the table name length for given event
819+
820+.. cc:function:: char * getTableName()
821+
822+ Return the table name for given event
823+
824+.. cc:function:: uint64_t getColumnCount()
825+
826+ Return the number of column for given event
827+
828+.. cc:function:: uint8_t * getColumnTypeDef()
829+
830+ Return the column definations (one byte per field type) for given event
831+
832+Setter Functions
833+----------------
834+
835+.. cc:function:: void setTableId(uint64_t value)
836+
837+ Set the parsed value of table_id into given object.
838+
839+.. cc:function:: void setFlagPh(uint16_t value)
840+
841+ Set the parsed value of flag into given object.
842+
843+.. cc:function:: void setSchemaNameLen(uint8_t value)
844+
845+ Set the parsed value of schena_name_len into given object.
846+
847+.. cc:function::void setSchemaName(char *value)
848+
849+ Set the parsed value of schema_name into given object.
850+
851+.. cc:function::void setTableNameLen(uint8_t value)
852+
853+ Set the parsed value of table_name_len into given object.
854+
855+.. cc:function:: void setTableName(char *value)
856+
857+ Set the parsed value of table_name into given object.
858+
859+.. cc:function:: void setColumnCount(uint64_t value)
860+
861+ Set the parsed value of column_count into given object.
862+
863+.. cc:function:: void setColumnTypeDef(uint8_t * value)
864+
865+ Set the parsed value of column_type_def into given object.
866+
867+.. cc:function:: TODO
868+
869+ Set the parsed value of column_meta_data into given object.
870
871=== added file 'docs/binlogapi/xid_event.rst'
872--- docs/binlogapi/xid_event.rst 1970-01-01 00:00:00 +0000
873+++ docs/binlogapi/xid_event.rst 2013-09-23 11:52:14 +0000
874@@ -0,0 +1,75 @@
875+XidEvent
876+==========
877+
878+Introduction
879+------------
880+
881+This class parse the XidEvent
882+
883+.. autoclass:: XidEvent
884+
885+ :members: Xid
886+
887+Constructor
888+-----------
889+
890+It will initialize all its data members to -1
891+
892+Getter Functions
893+----------------
894+
895+
896+.. cc:function::uint32_t getTimestamp()
897+
898+
899+ Returns the timestamp for given event
900+
901+.. cc:function:: uint8_t getType()
902+
903+
904+ Returns the Type for given event
905+
906+.. cc:function:: uint32_t getServerId()
907+
908+
909+ Returns the timestamp for given event
910+
911+.. cc:function:: uint32_t getEventSize()
912+
913+
914+ Returns the Event Size for given event
915+
916+.. cc:function:: uint32_t getLogPos()
917+
918+
919+ Returns the Log Position for next event
920+
921+.. cc:function:: uint32_t getFlagH()
922+
923+
924+ Returns the binlog Event Flag from header
925+
926+
927+.. cc:function:: uint64_t getXid()
928+
929+
930+ Returns the master's transaction id for event
931+
932+
933+Setter Functions
934+----------------
935+
936+.. cc:function:: void initWithData(const unsigned char * data)
937+
938+ Get the raw data and call all the setter functions with appropriate value
939+
940+ :param data: Raw data from binlog
941+
942+.. cc:function:: void setXid(uint64_t value)
943+
944+
945+ sets the parsed transaction id of event into its object
946+
947+ :param value: parsed Transaction id
948+
949+
950
951=== added file 'docs/examples/binlog-read-api.rst'
952--- docs/examples/binlog-read-api.rst 1970-01-01 00:00:00 +0000
953+++ docs/examples/binlog-read-api.rst 2013-09-23 11:52:14 +0000
954@@ -0,0 +1,110 @@
955+
956+Binlog Retrieval
957+================
958+
959+.. code-block:: c
960+
961+/**
962+ * Basic Example to show the use of api
963+ */
964+
965+#include<iostream>
966+#include <libdrizzle-5.1/libdrizzle.h>
967+#include <libdrizzle-5.1/binlogapi.h>
968+#include <stdio.h>
969+#include <stdlib.h>
970+#include <errno.h>
971+#include <inttypes.h>
972+#include<string.h>
973+
974+
975+
976+using namespace binlogevent;
977+
978+TableMapEvent tableMap;
979+XidEvent xevent;
980+
981+void binlog_error(drizzle_return_t ret, drizzle_st *con, void *context)
982+{
983+
984+ (void) context;
985+ if (ret != DRIZZLE_RETURN_EOF)
986+ {
987+ printf("Error retrieving binlog: %s\n", drizzle_error(con));
988+ }
989+
990+}
991+
992+void binlog_event(drizzle_binlog_event_st *event, void *context)
993+{
994+
995+ (void) context;
996+ uint32_t length;
997+ uint8_t type;
998+ int i;
999+ const unsigned char* data;
1000+ uint32_t ts = drizzle_binlog_event_timestamp(event);
1001+ length= drizzle_binlog_event_length(event);
1002+ type= drizzle_binlog_event_type(event);
1003+ cout<<(int)type<<endl;
1004+
1005+ if(type==16)
1006+ {
1007+ data= drizzle_binlog_event_raw_data(event);
1008+ EventData event_raw_data(data);
1009+ event_raw_data.getXidEvent(xevent);
1010+ printf("AS->%lu\n",xevent.getTimestamp());
1011+
1012+
1013+ }
1014+
1015+ if((int)type==19) //TABLE_MAP_EVENT)
1016+ {
1017+ data= drizzle_binlog_event_raw_data(event);
1018+ EventData event_raw_data(data);
1019+ event_raw_data.getTableMap(tableMap);
1020+ cout << "Timestamp by data and raw_data :" << tableMap.getTableName() << ": " << ts << endl;
1021+ uint8_t *val= tableMap.getColumnTypeDef();
1022+ for(int i=0;i< tableMap.getColumnCount();i++)
1023+ {
1024+ cout<< (int)val[i]<<endl;
1025+ }
1026+ }
1027+ if(type==23) //WRITE_ROW_EVENTv1
1028+ {
1029+ data= drizzle_binlog_event_raw_data(event);
1030+ EventData event_raw_data(data);
1031+ RowEvent writeEvent(tableMap.getColumnTypeDef());
1032+ event_raw_data.getWriteEvent(writeEvent);
1033+ cout << "col count by data and raw_data :" << writeEvent.getTimestamp() << ": " << writeEvent.getColumnCount() << endl;
1034+ cout << "QUIT event type: 23" << endl;
1035+ }
1036+
1037+}
1038+
1039+int main(void)
1040+{
1041+ drizzle_st *con;
1042+ drizzle_binlog_st *binlog;
1043+ drizzle_return_t ret;
1044+
1045+ con= drizzle_create("localhost", 3306, "root", "iiit", "", NULL);
1046+ ret= drizzle_connect(con);
1047+ if (ret != DRIZZLE_RETURN_OK)
1048+ {
1049+ printf("Could not connect to server: %s\n", drizzle_error(con));
1050+ return EXIT_FAILURE;
1051+ }
1052+
1053+ binlog= drizzle_binlog_init(con, binlog_event, binlog_error, NULL, true);
1054+
1055+ //ret= drizzle_binlog_start(binlog, 0, "mysql-bin.000150", 0);
1056+ ret= drizzle_binlog_start(binlog, 0, "", 0);
1057+
1058+ if (ret != DRIZZLE_RETURN_OK)
1059+ {
1060+ return EXIT_FAILURE;
1061+ }
1062+ drizzle_quit(con);
1063+ return EXIT_SUCCESS;
1064+}
1065
1066=== added file 'libdrizzle-5.1/binlog_client.h'
1067--- libdrizzle-5.1/binlog_client.h 1970-01-01 00:00:00 +0000
1068+++ libdrizzle-5.1/binlog_client.h 2013-09-23 11:52:14 +0000
1069@@ -0,0 +1,15 @@
1070+
1071+/* Visibility must come first */
1072+#include <libdrizzle-5.1/visibility.h>
1073+
1074+#include <libdrizzle-5.1/event_data.h>
1075+#include <libdrizzle-5.1/table_map_event.h>
1076+#include <libdrizzle-5.1/xid_event.h>
1077+#include <libdrizzle-5.1/event_interface.h>
1078+#include <libdrizzle-5.1/event_header.h>
1079+#include <libdrizzle-5.1/helper.h>
1080+#include <libdrizzle-5.1/query_event.h>
1081+#include <libdrizzle-5.1/row_event.h>
1082+#include <libdrizzle-5.1/row_iterator.h>
1083+#include <libdrizzle-5.1/column_value.h>
1084+
1085
1086=== added file 'libdrizzle-5.1/binlogapi.h'
1087--- libdrizzle-5.1/binlogapi.h 1970-01-01 00:00:00 +0000
1088+++ libdrizzle-5.1/binlogapi.h 2013-09-23 11:52:14 +0000
1089@@ -0,0 +1,36 @@
1090+/* Drizzle Client Library
1091+ * Copyright (C) 2012-2013 Drizzle Developer Group
1092+ * All rights reserved.
1093+ *
1094+ * Redistribution and use in source and binary forms, with or without
1095+ * modification, are permitted provided that the following conditions are
1096+ * met:
1097+ *
1098+ * * Redistributions of source code must retain the above copyright
1099+ * notice, this list of conditions and the following disclaimer.
1100+ *
1101+ * * Redistributions in binary form must reproduce the above
1102+ * copyright notice, this list of conditions and the following disclaimer
1103+ * in the documentation and/or other materials provided with the
1104+ * distribution.
1105+ *
1106+ * * The names of its contributors may not be used to endorse or
1107+ * promote products derived from this software without specific prior
1108+ * written permission.
1109+ *
1110+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1111+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1112+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1113+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1114+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1115+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1116+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1117+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1118+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1119+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1120+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1121+ */
1122+
1123+#pragma once
1124+
1125+#include <libdrizzle-5.1/binlog_client.h>
1126
1127=== added file 'libdrizzle-5.1/column_value.h'
1128--- libdrizzle-5.1/column_value.h 1970-01-01 00:00:00 +0000
1129+++ libdrizzle-5.1/column_value.h 2013-09-23 11:52:14 +0000
1130@@ -0,0 +1,39 @@
1131+/*
1132+ * Copyright (C) 2013 Drizzle Developer Group
1133+ * Copyright (C) 2013 Kuldeep Porwal
1134+ * All rights reserved.
1135+ *
1136+ * Use and distribution licensed under the BSD license. See
1137+ * the COPYING file in the parent directory for full text.
1138+ *
1139+ * summary: column value info
1140+ *
1141+ */
1142+#include<iostream>
1143+#include<string>
1144+
1145+#ifndef COLUMN_VALUE
1146+#define COLUMN_VALUE
1147+namespace binlogevent
1148+{
1149+ class ColumnValue
1150+ {
1151+ public:
1152+ ColumnValue(std::string st,bool _bool,int col_n)
1153+ {
1154+ value=st;
1155+ is_null = _bool;
1156+ col_num = col_n;
1157+ }
1158+
1159+ std::string getValue() {return value; } // Check: str.empty() is true so int value otherwise string value.
1160+ bool isNull() { return is_null;}
1161+ int getColumnNum() {return col_num;}
1162+
1163+ private:
1164+ std::string value;
1165+ bool is_null;
1166+ int col_num;
1167+ };
1168+}
1169+#endif
1170
1171=== modified file 'libdrizzle-5.1/drizzle_client.h'
1172--- libdrizzle-5.1/drizzle_client.h 2013-01-27 11:55:48 +0000
1173+++ libdrizzle-5.1/drizzle_client.h 2013-09-23 11:52:14 +0000
1174@@ -67,6 +67,7 @@
1175 #include <libdrizzle-5.1/statement.h>
1176 #include <libdrizzle-5.1/version.h>
1177
1178+
1179 #ifdef __cplusplus
1180 extern "C" {
1181 #endif
1182
1183=== added file 'libdrizzle-5.1/event_data.h'
1184--- libdrizzle-5.1/event_data.h 1970-01-01 00:00:00 +0000
1185+++ libdrizzle-5.1/event_data.h 2013-09-23 11:52:14 +0000
1186@@ -0,0 +1,69 @@
1187+/*
1188+ * Copyright (C) 2013 Drizzle Developer Group
1189+ * Copyright (C) 2013 Kuldeep Porwal
1190+ * All rights reserved.
1191+ *
1192+ * Use and distribution licensed under the BSD license. See
1193+ * the COPYING file in the parent directory for full text.
1194+ *
1195+ * summary: Returns objects of every event
1196+ *
1197+ */
1198+#include<iostream>
1199+#include<cstring>
1200+#include<inttypes.h>
1201+
1202+#include"table_map_event.h"
1203+#include"row_event.h"
1204+#include"query_event.h"
1205+#include"xid_event.h"
1206+
1207+
1208+using namespace std;
1209+//using namespace binlogevent;
1210+
1211+namespace binlogevent
1212+{
1213+ class EventData
1214+ {
1215+ public:
1216+
1217+ EventData(const unsigned char* data)
1218+ {
1219+ _data=data;
1220+ }
1221+
1222+ ~EventData()
1223+ {
1224+ }
1225+ /** Method which sets the field values
1226+ * for table map event. calls initWithData
1227+ * of TableMapEvent
1228+ *
1229+ * @param[in] tableMap A reference to TableMapEvent object.
1230+ */
1231+ DRIZZLE_API
1232+ void getTableMap(TableMapEvent& tableMap);
1233+ DRIZZLE_API
1234+ void getWriteEvent(RowEvent& writeEvent);
1235+ DRIZZLE_API
1236+ void getUpdateEvent(RowEvent& updateEvent);
1237+ DRIZZLE_API
1238+ void getDeleteEvent(RowEvent& deleteEvent);
1239+ DRIZZLE_API
1240+ void getQueryEvent(QueryEvent& queryEvent);
1241+ DRIZZLE_API
1242+ void getXidEvent(XidEvent& xidEvent);
1243+
1244+ DRIZZLE_API
1245+ void setData(const unsigned char* _data);
1246+
1247+
1248+ private:
1249+ /* Raw Event Data */
1250+ const unsigned char* _data;
1251+
1252+
1253+ };
1254+} /*namespace binlogevent*/
1255+
1256
1257=== added file 'libdrizzle-5.1/event_header.h'
1258--- libdrizzle-5.1/event_header.h 1970-01-01 00:00:00 +0000
1259+++ libdrizzle-5.1/event_header.h 2013-09-23 11:52:14 +0000
1260@@ -0,0 +1,67 @@
1261+/*
1262+ * Copyright (C) 2013 Drizzle Developer Group
1263+ * Copyright (C) 2013 Kuldeep Porwal
1264+ * All rights reserved.
1265+ *
1266+ * Use and distribution licensed under the BSD license. See
1267+ * the COPYING file in the parent directory for full text.
1268+ *
1269+ * summary: parsing of header (common for each event)
1270+ *
1271+ */
1272+#include<iostream>
1273+#include<cstring>
1274+#include<inttypes.h>
1275+
1276+#ifndef HELPER
1277+#define HELPER
1278+
1279+#include"helper.h"
1280+
1281+#endif
1282+
1283+
1284+using namespace std;
1285+
1286+#ifndef EVENT_HEADER
1287+#define EVENT_HEADER
1288+
1289+namespace binlogevent
1290+{
1291+ class EventHeader
1292+ {
1293+ public:
1294+
1295+ EventHeader():
1296+ timestamp(-1),
1297+ type(-1),
1298+ server_id(-1),
1299+ event_size(-1),
1300+ log_pos(-1),
1301+ flag(-1)
1302+ {
1303+ }
1304+
1305+ ~EventHeader()
1306+ {
1307+ }
1308+
1309+ int setHeader(unsigned const char* data);
1310+
1311+ friend class TableMapEvent;
1312+ friend class RowEvent;
1313+ friend class QueryEvent;
1314+ friend class XidEvent;
1315+
1316+ private:
1317+ uint32_t timestamp; // timestamp of event
1318+ uint8_t type; // type of event
1319+ uint32_t server_id; // server-id of the originating mysql-server. Used to filter out events in circular replication
1320+ uint32_t event_size;//size of the event (header, post-header, body)
1321+ uint32_t log_pos; // position of next event
1322+ uint16_t flag; //header
1323+
1324+
1325+ };
1326+} /*namespace binlogevent*/
1327+#endif
1328
1329=== added file 'libdrizzle-5.1/event_interface.h'
1330--- libdrizzle-5.1/event_interface.h 1970-01-01 00:00:00 +0000
1331+++ libdrizzle-5.1/event_interface.h 2013-09-23 11:52:14 +0000
1332@@ -0,0 +1,51 @@
1333+/*
1334+ * Copyright (C) 2013 Drizzle Developer Group
1335+ * Copyright (C) 2013 Kuldeep Porwal
1336+ * All rights reserved.
1337+ *
1338+ * Use and distribution licensed under the BSD license. See
1339+ * the COPYING file in the parent directory for full text.
1340+ *
1341+ * summary: creation of Event object (global)
1342+ *
1343+ */
1344+#include<iostream>
1345+#include<cstring>
1346+#include<inttypes.h>
1347+
1348+#ifndef event_header
1349+#define event_header
1350+#include"event_header.h"
1351+#endif
1352+
1353+using namespace std;
1354+//using namespace binlogevent;
1355+
1356+#ifndef EVENT_INTERFACE
1357+#define EVENT_INTERFACE
1358+
1359+namespace binlogevent
1360+{
1361+ class Events
1362+ {
1363+
1364+ public:
1365+
1366+ Events()
1367+ {
1368+ }
1369+ ~Events()
1370+ {
1371+ }
1372+
1373+ /** Every event class should implement
1374+ * this function.
1375+ *
1376+ * @param[in] data Raw event data.
1377+ */
1378+
1379+ EventHeader header;
1380+
1381+ };
1382+}
1383+#endif
1384
1385=== added file 'libdrizzle-5.1/helper.h'
1386--- libdrizzle-5.1/helper.h 1970-01-01 00:00:00 +0000
1387+++ libdrizzle-5.1/helper.h 2013-09-23 11:52:14 +0000
1388@@ -0,0 +1,155 @@
1389+/*
1390+ * Copyright (C) 2013 Drizzle Developer Group
1391+ * Copyright (C) 2013 Kuldeep Porwal
1392+ * All rights reserved.
1393+ *
1394+ * Use and distribution licensed under the BSD license. See
1395+ * the COPYING file in the parent directory for full text.
1396+ *
1397+ *
1398+ */
1399+
1400+#include<limits.h>
1401+
1402+#ifndef HELPERS
1403+#define HELPERS
1404+typedef enum{
1405+ MYSQL_TYPE_DECIMAL,
1406+ MYSQL_TYPE_TINY,
1407+ MYSQL_TYPE_SHORT,
1408+ MYSQL_TYPE_LONG,
1409+ MYSQL_TYPE_FLOAT,
1410+ MYSQL_TYPE_DOUBLE,
1411+ MYSQL_TYPE_NULL,
1412+ MYSQL_TYPE_TIMESTAMP,
1413+ MYSQL_TYPE_LONGLONG,
1414+ MYSQL_TYPE_INT24,
1415+ MYSQL_TYPE_DATE,
1416+ MYSQL_TYPE_TIME,
1417+ MYSQL_TYPE_DATETIME,
1418+ MYSQL_TYPE_YEAR,
1419+ MYSQL_TYPE_NEWDATE,
1420+ MYSQL_TYPE_VARCHAR,
1421+ MYSQL_TYPE_BIT,
1422+ MYSQL_TYPE_NEWDECIMAL,
1423+ MYSQL_TYPE_ENUM,
1424+ MYSQL_TYPE_SET,
1425+ MYSQL_TYPE_TINY_BLOB,
1426+ MYSQL_TYPE_MEDIUM_BLOB,
1427+ MYSQL_TYPE_LONG_BLOB,
1428+ MYSQL_TYPE_BLOB,
1429+ MYSQL_TYPE_VAR_STRING,
1430+ MYSQL_TYPE_STRING,
1431+ MYSQL_TYPE_GEOMETRY
1432+}enum_field_types;
1433+
1434+typedef enum{
1435+ LEN_ENC_STR = -1,
1436+ READ_1_BYTE = 1,
1437+ READ_2_BYTE = 2,
1438+ READ_4_BYTE = 4,
1439+ READ_8_BYTE = 8,
1440+ NOT_FOUND = 0
1441+}enum_field_bytes;
1442+
1443+typedef enum{
1444+ TABLE_MAP_EVENT = 19,
1445+ WRITE_ROWS_EVENTv1 = 23,
1446+ UPDATE_ROWS_EVENTv1,
1447+ DELETE_ROWS_EVENTv1
1448+}enum_event_type;
1449+
1450+typedef enum{
1451+ STRING = 1,
1452+ INT = 2
1453+}enum_col_type;
1454+
1455+
1456+#define mask(__b) \
1457+ ((uint32_t)(__b)==32 ? 0xffffffff : \
1458+ ((uint32_t)(__b)==24 ? 0xffffff : \
1459+ ((uint32_t)(__b)==16 ? 0xffff : \
1460+ ((uint32_t)(__b)==8 ? 0xff : 0xffffffffffffffff ))))
1461+
1462+#define bytes_col_count(__b) \
1463+ ((uint64_t)(__b)<0xfb ? 1 : \
1464+ ((uint64_t)(__b)==0xfc ? 2 : \
1465+ ((uint64_t)(__b)==0xfd ? 3 : 8)))
1466+
1467+DRIZZLE_API
1468+bool getNextBit(uint8_t& val);
1469+/**
1470+ * get 2 byte number from raw data
1471+ *
1472+ * @param[in] pos Start reading from pos.
1473+ * @param[in] data Raw data from binglog.
1474+ *
1475+ *@retval 2 byte number
1476+ */
1477+ DRIZZLE_API
1478+uint16_t getByte2(int pos,const unsigned char* data);
1479+/**
1480+ * get 4 byte number from raw data
1481+ *
1482+ * @param[in] pos Start reading from pos.
1483+ * @param[in] data Raw data from binglog.
1484+ *
1485+ *@retval 4 byte number
1486+ */
1487+ DRIZZLE_API
1488+uint32_t getByte4(int pos,const unsigned char* data);
1489+/**
1490+ * get 3 byte number from raw data
1491+ *
1492+ * @param[in] pos Start reading from pos.
1493+ * @param[in] data Raw data from binglog.
1494+ *
1495+ *@retval 3 byte number
1496+ */
1497+ DRIZZLE_API
1498+uint32_t getByte3(int pos,const unsigned char* data);
1499+/**
1500+ * get 6 byte number from raw data
1501+ *
1502+ * @param[in] pos Start reading from pos.
1503+ * @param[in] data Raw data from binglog.
1504+ *
1505+ *@retval 6 byte number
1506+ */
1507+ DRIZZLE_API
1508+uint64_t getByte6(int pos,const unsigned char* data);
1509+/**
1510+ * get 8 byte number from raw data
1511+ *
1512+ * @param[in] pos Start reading from pos.
1513+ * @param[in] data Raw data from binglog.
1514+ *
1515+ *@retval 8 byte number
1516+ */
1517+ DRIZZLE_API
1518+uint64_t getByte8(int pos,const unsigned char* data);
1519+/** gets the string of specified length
1520+ *
1521+ * @param[in] pos Start reading from pos.
1522+ * @param[in] len Length of string
1523+ * @param[in] data Raw data from binglog.
1524+ */
1525+ DRIZZLE_API
1526+char * getString(int pos,int len,const unsigned char * data);
1527+
1528+ DRIZZLE_API
1529+uint64_t getEncodedLen(int& pos,const unsigned char * data);
1530+
1531+ DRIZZLE_API
1532+int lookup_metadata_field_size(enum_field_types field_type);
1533+
1534+ DRIZZLE_API
1535+std::string getIntToStr(uint64_t num);
1536+
1537+ DRIZZLE_API
1538+int getBoolArray(bool arr[],const unsigned char data[],int start_pos,int _byte,int _bit);
1539+
1540+ DRIZZLE_API
1541+enum_field_bytes lookup_field_bytes(enum_field_types field_type);
1542+
1543+#endif
1544
1545=== modified file 'libdrizzle-5.1/include.am'
1546--- libdrizzle-5.1/include.am 2013-01-27 09:48:19 +0000
1547+++ libdrizzle-5.1/include.am 2013-09-23 11:52:14 +0000
1548@@ -24,3 +24,18 @@
1549 nobase_include_HEADERS+= libdrizzle-5.1/verbose.h
1550 nobase_include_HEADERS+= libdrizzle-5.1/visibility.h
1551 nobase_include_HEADERS+= libdrizzle-5.1/version.h
1552+
1553+nobase_include_HEADERS+= libdrizzle-5.1/binlogapi.h
1554+nobase_include_HEADERS+= libdrizzle-5.1/binlog_client.h
1555+
1556+nobase_include_HEADERS+= libdrizzle-5.1/event_data.h
1557+nobase_include_HEADERS+= libdrizzle-5.1/event_header.h
1558+nobase_include_HEADERS+= libdrizzle-5.1/helper.h
1559+nobase_include_HEADERS+= libdrizzle-5.1/row_event.h
1560+nobase_include_HEADERS+= libdrizzle-5.1/table_map_event.h
1561+nobase_include_HEADERS+= libdrizzle-5.1/event_interface.h
1562+nobase_include_HEADERS+= libdrizzle-5.1/query_event.h
1563+nobase_include_HEADERS+= libdrizzle-5.1/xid_event.h
1564+nobase_include_HEADERS+= libdrizzle-5.1/row_iterator.h
1565+nobase_include_HEADERS+= libdrizzle-5.1/column_value.h
1566+
1567
1568=== added file 'libdrizzle-5.1/query_event.h'
1569--- libdrizzle-5.1/query_event.h 1970-01-01 00:00:00 +0000
1570+++ libdrizzle-5.1/query_event.h 2013-09-23 11:52:14 +0000
1571@@ -0,0 +1,155 @@
1572+/*
1573+ * Copyright (C) 2013 Drizzle Developer Group
1574+ * Copyright (C) 2013 Kuldeep Porwal
1575+ * All rights reserved.
1576+ *
1577+ * Use and distribution licensed under the BSD license. See
1578+ * the COPYING file in the parent directory for full text.
1579+ *
1580+ * summary: parse query event
1581+ *
1582+ */
1583+#include<cstring>
1584+#include<inttypes.h>
1585+
1586+#ifndef event_interface
1587+#define event_interface
1588+#include"event_interface.h"
1589+#endif
1590+
1591+
1592+using namespace std;
1593+
1594+#ifndef QUERY_EVENT
1595+#define QUERY_EVENT
1596+//using namespace binlogevent;
1597+namespace binlogevent
1598+{
1599+ class QueryEvent : public Events
1600+ {
1601+ public:
1602+
1603+// QueryEvent(TableMapEvent& tableMap) : table_id(0),
1604+ QueryEvent() : proxy_id(-1),
1605+ execution_time(-1),
1606+ schema_length(-1),
1607+ error_code(-1)
1608+ {
1609+ }
1610+
1611+ ~QueryEvent()
1612+ {
1613+ }
1614+
1615+
1616+ /** Get the raw data and call all the setters with
1617+ * appropriate value
1618+ *
1619+ * @param[in] data Raw data from binglog.
1620+ */
1621+ DRIZZLE_API
1622+ void initWithData(const unsigned char * data);
1623+
1624+ //getters
1625+
1626+ /**
1627+ * @retval timestamp of event.
1628+ */
1629+
1630+ DRIZZLE_API
1631+ uint32_t getTimestamp();
1632+ /**
1633+ * @retval type of event.
1634+ */
1635+
1636+ DRIZZLE_API
1637+ uint8_t getType();
1638+
1639+ /**
1640+ * @retval server-id of the originating mysql-server. Used to filter out events in circular replication.
1641+ */
1642+ DRIZZLE_API
1643+ uint32_t getServerId();
1644+
1645+ /**
1646+ * @retval of size of event.
1647+ */
1648+ DRIZZLE_API
1649+ uint32_t getEventSize();
1650+ /**
1651+ * @retval of position of the next event .
1652+ */
1653+ DRIZZLE_API
1654+ uint32_t getLogPos();
1655+
1656+ /**
1657+ * @retval Binlog Event Flag from header
1658+ */
1659+ DRIZZLE_API
1660+ uint16_t getFlagH();
1661+
1662+ /**
1663+ * @retval proxy id.
1664+ */
1665+
1666+ DRIZZLE_API
1667+ uint32_t getProxyId();
1668+
1669+ /**
1670+ * @retval execution time.
1671+ */
1672+ DRIZZLE_API
1673+ uint32_t getExecutionTime();
1674+
1675+ /**
1676+ *@retval schema length.
1677+ */
1678+ DRIZZLE_API
1679+ uint8_t getSchemaLength();
1680+
1681+ /**
1682+ *@retval error code.
1683+ */
1684+ DRIZZLE_API
1685+ uint16_t getErrorCode();
1686+
1687+
1688+
1689+ //setters
1690+ /** set master proxy Id
1691+ *
1692+ *@param[in] value Proxy Id of master
1693+ */
1694+
1695+ void setProxyId(uint32_t value);
1696+
1697+ /** set execution time.
1698+ *
1699+ * @param[in] value Execution time of query.
1700+ */
1701+ void setExecutionTime(uint32_t value);
1702+
1703+ /** set schema length
1704+ *
1705+ * @param[in] value Schema length of query.
1706+ */
1707+ void setSchemaLength(uint8_t value);
1708+
1709+ /** set error code.
1710+ *
1711+ * @param[in] value Error code if any error occurred.
1712+ */
1713+ void setErrorCode(uint16_t value);
1714+
1715+
1716+
1717+
1718+ private:
1719+ uint32_t proxy_id;
1720+ uint32_t execution_time;
1721+ uint8_t schema_length;
1722+ uint16_t error_code;
1723+
1724+ }; // query event
1725+} /*namespace binlogevent*/
1726+#endif
1727
1728=== added file 'libdrizzle-5.1/row_event.h'
1729--- libdrizzle-5.1/row_event.h 1970-01-01 00:00:00 +0000
1730+++ libdrizzle-5.1/row_event.h 2013-09-23 11:52:14 +0000
1731@@ -0,0 +1,181 @@
1732+/*
1733+ * Copyright (C) 2013 Drizzle Developer Group
1734+ * Copyright (C) 2013 Kuldeep Porwal
1735+ * All rights reserved.
1736+ *
1737+ * Use and distribution licensed under the BSD license. See
1738+ * the COPYING file in the parent directory for full text.
1739+ *
1740+ * summary: parsing of row events like write event, update event, delete event
1741+ *
1742+ */
1743+#include<cstring>
1744+#include<inttypes.h>
1745+
1746+#ifndef event_interface
1747+#define event_interface
1748+#include"event_interface.h"
1749+#endif
1750+
1751+#include"row_iterator.h"
1752+
1753+using namespace std;
1754+
1755+
1756+//using namespace binlogevent;
1757+
1758+#ifndef ROW_EVENT
1759+#define ROW_EVENT
1760+
1761+namespace binlogevent
1762+{
1763+ class RowEvent : public Events
1764+ {
1765+ public:
1766+
1767+ RowEvent(uint8_t *col_type) :
1768+ table_id(-1),
1769+ flag(-1),
1770+ column_count(-1),
1771+ column_null_bitmap(NULL),
1772+ column_bitmap(NULL)
1773+ {
1774+ column_type=col_type;
1775+ }
1776+
1777+ ~RowEvent()
1778+ {
1779+ }
1780+
1781+
1782+ /** Get the raw data and call all the setters with
1783+ * appropriate value
1784+ *
1785+ * @param[in] data Raw data from binglog.
1786+ */
1787+ DRIZZLE_API
1788+ void initWithData(const unsigned char * data);
1789+
1790+ //getters
1791+
1792+ /**
1793+ * @retval timestamp of event.
1794+ */
1795+
1796+ DRIZZLE_API
1797+ uint32_t getTimestamp();
1798+ /**
1799+ * @retval type of event.
1800+ */
1801+
1802+ DRIZZLE_API
1803+ enum_event_type getType();
1804+
1805+ /**
1806+ * @retval server-id of the originating mysql-server. Used to filter out events in circular replication.
1807+ */
1808+ DRIZZLE_API
1809+ uint32_t getServerId();
1810+
1811+ /**
1812+ * @retval of size of event.
1813+ */
1814+ DRIZZLE_API
1815+ uint32_t getEventSize();
1816+ /**
1817+ * @retval of position of the next event .
1818+ */
1819+ DRIZZLE_API
1820+ uint32_t getLogPos();
1821+
1822+ /**
1823+ * @retval Binlog Event Flag from header
1824+ */
1825+ DRIZZLE_API
1826+ uint16_t getFlagH();
1827+
1828+ /**
1829+ * @retval numeric table id
1830+ */
1831+
1832+ DRIZZLE_API
1833+ uint64_t getTableId();
1834+
1835+ /**
1836+ * @retval flag of post header
1837+ */
1838+ DRIZZLE_API
1839+ uint16_t getFlagPh();
1840+
1841+ /**
1842+ * In funtion : conversion of length-encoded integer into its numeric value
1843+ * @retval number of columns in the table map
1844+ */
1845+ DRIZZLE_API
1846+ uint64_t getColumnCount();
1847+
1848+ /**
1849+ * @retval bitmap of column present
1850+ */
1851+
1852+ DRIZZLE_API
1853+ bool * getColumnPresentBitmap();
1854+
1855+ DRIZZLE_API
1856+ RowVector getRows();
1857+
1858+ DRIZZLE_API
1859+ int getRowEventType();
1860+
1861+ //RowVector getAllRows();
1862+ //Row getRow();
1863+
1864+
1865+
1866+ //setters
1867+
1868+ void setTableId(uint64_t value);
1869+
1870+ /** set flag_ph.
1871+ *
1872+ * @param[in] value Post header flag.
1873+ */
1874+ void setFlagPh(uint16_t value);
1875+
1876+ /** set column_count.
1877+ *
1878+ * @param[in] value Column count in table map.
1879+ */
1880+ void setColumnCount(uint64_t value);
1881+
1882+ /** set column_bitmap.
1883+ *
1884+ * @param[in] bitmap Array
1885+ */
1886+ void setColumnPresentBitmap(bool * value);
1887+
1888+ /** set null_bitmap.
1889+ *
1890+ * @param[in] null bitmap Array
1891+ */
1892+ void setNullBitmap(bool * value);
1893+
1894+ void setRowEventType(int value);
1895+
1896+
1897+
1898+
1899+ private:
1900+ uint8_t * column_type;
1901+ uint64_t table_id;
1902+ uint16_t flag; //post header
1903+ uint64_t column_count;
1904+ bool * column_null_bitmap;
1905+ bool * column_bitmap;
1906+ bool * null_bitmap;
1907+ RowIterator rows;
1908+ int row_event_type; // write-> 1, delete-> 2, update->3
1909+
1910+ }; // RowEvent
1911+} /*namespace binlogevent*/
1912+#endif
1913
1914=== added file 'libdrizzle-5.1/row_iterator.h'
1915--- libdrizzle-5.1/row_iterator.h 1970-01-01 00:00:00 +0000
1916+++ libdrizzle-5.1/row_iterator.h 2013-09-23 11:52:14 +0000
1917@@ -0,0 +1,35 @@
1918+/*
1919+ * Copyright (C) 2013 Drizzle Developer Group
1920+ * Copyright (C) 2013 Kuldeep Porwal
1921+ * All rights reserved.
1922+ *
1923+ * Use and distribution licensed under the BSD license. See
1924+ * the COPYING file in the parent directory for full text.
1925+ *
1926+ *
1927+ */
1928+#include<iostream>
1929+#include"column_value.h"
1930+#include<vector>
1931+
1932+using namespace std;
1933+
1934+#ifndef ROW_ITERATOR
1935+#define ROW_ITERATOR
1936+namespace binlogevent
1937+{
1938+ typedef vector<vector<ColumnValue> > RowVector;
1939+ typedef vector<ColumnValue> Row;
1940+
1941+ class RowIterator
1942+ {
1943+ public:
1944+ RowIterator()
1945+ {
1946+ }
1947+ vector<vector<ColumnValue> > vec_rows;
1948+ vector<ColumnValue> vec_col_val;
1949+// RowVector
1950+ };
1951+}
1952+#endif
1953
1954=== added file 'libdrizzle-5.1/table_map_event.h'
1955--- libdrizzle-5.1/table_map_event.h 1970-01-01 00:00:00 +0000
1956+++ libdrizzle-5.1/table_map_event.h 2013-09-23 11:52:14 +0000
1957@@ -0,0 +1,203 @@
1958+/*
1959+ * Copyright (C) 2013 Drizzle Developer Group
1960+ * Copyright (C) 2013 Kuldeep Porwal
1961+ * All rights reserved.
1962+ *
1963+ * Use and distribution licensed under the BSD license. See
1964+ * the COPYING file in the parent directory for full text.
1965+ *
1966+ * summary: parse table map event
1967+ *
1968+ */
1969+#include<cstring>
1970+#include<inttypes.h>
1971+
1972+#ifndef event_interface
1973+#define event_interface
1974+#include"event_interface.h"
1975+#endif
1976+using namespace std;
1977+#ifndef HELPER
1978+#define HELPER
1979+
1980+#include"helper.h"
1981+
1982+#endif
1983+
1984+#ifndef TABLE_MAP
1985+#define TABLE_MAP
1986+//using namespace binlogevent;
1987+namespace binlogevent
1988+{
1989+ class TableMapEvent : public Events
1990+ {
1991+ public:
1992+
1993+ TableMapEvent() : table_id(-1),
1994+ flag(-1),
1995+ schema_name_len(-1),
1996+ schema_name(NULL),
1997+ table_name_len(-1),
1998+ table_name(NULL),
1999+ column_count(-1),
2000+ column_type_def(NULL),
2001+ column_meta_data(NULL)
2002+ {
2003+ }
2004+
2005+ ~TableMapEvent()
2006+ {
2007+ }
2008+
2009+
2010+ /**
2011+ * Get the raw data and call all the setters with
2012+ * appropriate value
2013+ *
2014+ * @param[in] data Raw data from binglog.
2015+ */
2016+ DRIZZLE_API
2017+ void initWithData(const unsigned char * data);
2018+
2019+
2020+ //getters
2021+
2022+ /**
2023+ * @retval timestamp of event.
2024+ */
2025+ DRIZZLE_API
2026+ uint32_t getTimestamp();
2027+ /**
2028+ * @retval type of event.
2029+ */
2030+ DRIZZLE_API
2031+ enum_event_type getType();
2032+ /**
2033+ * @retval server-id of the originating mysql-server. Used to filter out events in circular replication.
2034+ */
2035+ DRIZZLE_API
2036+ uint32_t getServerId();
2037+ /**
2038+ * @retval of position of the next event .
2039+ */
2040+ DRIZZLE_API
2041+ uint32_t getLogPos();
2042+ /**
2043+ * @retval Binlog Event Flag from header
2044+ */
2045+ DRIZZLE_API
2046+ uint16_t getFlagH();
2047+
2048+ /**
2049+ * @retval numeric table id
2050+ */
2051+ DRIZZLE_API
2052+ uint64_t getTableId();
2053+ /**
2054+ * @retval flag of post header
2055+ */
2056+ DRIZZLE_API
2057+ uint16_t getFlagPh();
2058+ /**
2059+ * @retval length of the schema name
2060+ */
2061+ DRIZZLE_API
2062+ int getSchemaNameLen();
2063+ /**
2064+ * @retval schema name
2065+ */
2066+ DRIZZLE_API
2067+ char * getSchemaName();
2068+ /**
2069+ * @retval length of table name
2070+ */
2071+ DRIZZLE_API
2072+ int getTableNameLen();
2073+ /**
2074+ * @retval table name
2075+ */
2076+ DRIZZLE_API
2077+ char * getTableName();
2078+ /**
2079+ * In funtion : conversion of length-encoded integer into its numeric value
2080+ * @retval number of columns in the table map
2081+ */
2082+ DRIZZLE_API
2083+ uint64_t getColumnCount();
2084+ /**
2085+ * @retval array of column definitions, one byte per field type
2086+ */
2087+ DRIZZLE_API
2088+ uint8_t * getColumnTypeDef();
2089+
2090+ /**
2091+ * @retval enum {INT,STRING} as a type of column
2092+ */
2093+
2094+ DRIZZLE_API
2095+ enum_col_type getColType(int colNo);
2096+
2097+ //setters
2098+
2099+ DRIZZLE_API
2100+ void setTableId(uint64_t value);
2101+ /**
2102+ * set flag_ph.
2103+ *
2104+ * @param[in] value Post header flag.
2105+ */
2106+ DRIZZLE_API
2107+ void setFlagPh(uint16_t value);
2108+ /**
2109+ * set schema_name_len.
2110+ *
2111+ * @param[in] value Length of the schema name.
2112+ */
2113+ void setSchemaNameLen(uint8_t value);
2114+ /**
2115+ * set schema_name.
2116+ *
2117+ * @param[in] value Schema Name or Database name.
2118+ */
2119+ void setSchemaName(char *value);
2120+ /**
2121+ * set table_name_len.
2122+ *
2123+ * @param[in] value Table name length.
2124+ */
2125+ void setTableNameLen(uint8_t value);
2126+ /**
2127+ * set table_name.
2128+ *
2129+ * @param[in] value Table name.
2130+ */
2131+ void setTableName(char *value);
2132+ /**
2133+ * set column_count.
2134+ *
2135+ * @param[in] value Column count in table map.
2136+ */
2137+ void setColumnCount(uint64_t value);
2138+ /**
2139+ * set column_type_def.
2140+ *
2141+ * @param[in] value Array of column definitions, one byte per field type
2142+ */
2143+ void setColumnTypeDef(uint8_t * value);
2144+
2145+
2146+
2147+ private:
2148+ uint64_t table_id;
2149+ uint16_t flag; //post header
2150+ uint8_t schema_name_len;
2151+ char * schema_name;
2152+ uint8_t table_name_len;
2153+ char * table_name;
2154+ uint64_t column_count;
2155+ uint8_t * column_type_def;
2156+ uint64_t * column_meta_data;
2157+
2158+ }; // tablemapevent
2159+} /*namespace binlogevent*/
2160+#endif
2161
2162=== added file 'libdrizzle-5.1/xid_event.h'
2163--- libdrizzle-5.1/xid_event.h 1970-01-01 00:00:00 +0000
2164+++ libdrizzle-5.1/xid_event.h 2013-09-23 11:52:14 +0000
2165@@ -0,0 +1,95 @@
2166+/*
2167+ * Copyright (C) 2013 Drizzle Developer Group
2168+ * Copyright (C) 2013 Kuldeep Porwal
2169+ * All rights reserved.
2170+ *
2171+ * Use and distribution licensed under the BSD license. See
2172+ * the COPYING file in the parent directory for full text.
2173+ *
2174+ * summary: parse xid event
2175+ *
2176+ */
2177+#include<cstring>
2178+#include<inttypes.h>
2179+
2180+#ifndef event_interface
2181+#define event_interface
2182+#include"event_interface.h"
2183+#endif
2184+using namespace std;
2185+
2186+#ifndef XID_EVENT
2187+#define XID_EVENT
2188+//using namespace binlogevent;
2189+namespace binlogevent
2190+{
2191+ class XidEvent : public Events
2192+ {
2193+ public:
2194+
2195+ XidEvent() : Xid(-1)
2196+ {
2197+ }
2198+
2199+ ~XidEvent()
2200+ {
2201+ }
2202+
2203+
2204+ /**
2205+ * Get the raw data and call all the setters with
2206+ * appropriate value
2207+ *
2208+ * @param[in] data Raw data from binglog.
2209+ */
2210+ DRIZZLE_API
2211+ void initWithData(const unsigned char * data);
2212+
2213+
2214+ //getters
2215+
2216+ /**
2217+ * @retval timestamp of event.
2218+ */
2219+ DRIZZLE_API
2220+ uint32_t getTimestamp();
2221+ /**
2222+ * @retval type of event.
2223+ */
2224+ DRIZZLE_API
2225+ enum_event_type getType();
2226+ /**
2227+ * @retval server-id of the originating mysql-server. Used to filter out events in circular replication.
2228+ */
2229+ DRIZZLE_API
2230+ uint32_t getServerId();
2231+ /**
2232+ * @retval of position of the next event .
2233+ */
2234+ DRIZZLE_API
2235+ uint32_t getLogPos();
2236+ /**
2237+ * @retval Binlog Event Flag from header
2238+ */
2239+ DRIZZLE_API
2240+ uint16_t getFlagH();
2241+
2242+ /**
2243+ * @retval transaction id
2244+ */
2245+ DRIZZLE_API
2246+ uint64_t getXid();
2247+
2248+ /**
2249+ * set transaction id
2250+ */
2251+ //DRIZZLE_API
2252+ void setXid(uint64_t value);
2253+
2254+
2255+ private:
2256+ uint64_t Xid;
2257+
2258+ }; // Xidevent
2259+} /*namespace binlogevent*/
2260+#endif
2261
2262=== added file 'libdrizzle/commonapi.h'
2263--- libdrizzle/commonapi.h 1970-01-01 00:00:00 +0000
2264+++ libdrizzle/commonapi.h 2013-09-23 11:52:14 +0000
2265@@ -0,0 +1,1 @@
2266+#include<libdrizzle-5.1/binlog_client.h>
2267
2268=== added file 'libdrizzle/event_data.cc'
2269--- libdrizzle/event_data.cc 1970-01-01 00:00:00 +0000
2270+++ libdrizzle/event_data.cc 2013-09-23 11:52:14 +0000
2271@@ -0,0 +1,61 @@
2272+/*
2273+ * Copyright (C) 2013 Drizzle Developer Group
2274+ * Copyright (C) 2013 Kuldeep Porwal
2275+ * All rights reserved.
2276+ *
2277+ * Use and distribution licensed under the BSD license. See
2278+ * the COPYING file in the parent directory for full text.
2279+ *
2280+ * summary: Returns objects of every event
2281+ *
2282+ */
2283+#include "config.h"
2284+#include<iostream>
2285+#include "libdrizzle/common.h"
2286+#include "libdrizzle/commonapi.h"
2287+#include <stdio.h>
2288+#include <stdlib.h>
2289+#include <errno.h>
2290+#include <inttypes.h>
2291+#include<string.h>
2292+//#include<libdrizzle-5.1/event_data.h>
2293+#define EVENT_DATA
2294+using namespace std;
2295+using namespace binlogevent;
2296+
2297+void EventData::setData(const unsigned char* data)
2298+{
2299+ _data=data;
2300+}
2301+
2302+void EventData::getTableMap(TableMapEvent& tableMap)
2303+{
2304+ tableMap.initWithData(_data);
2305+}
2306+
2307+void EventData::getUpdateEvent(RowEvent& updateEvent)
2308+{
2309+ updateEvent.setRowEventType(3); // type 3
2310+ updateEvent.initWithData(_data);
2311+}
2312+
2313+void EventData::getDeleteEvent(RowEvent& deleteEvent)
2314+{
2315+ deleteEvent.setRowEventType(2); // type 2
2316+ deleteEvent.initWithData(_data);
2317+}
2318+
2319+void EventData::getWriteEvent(RowEvent& writeEvent)
2320+{
2321+ writeEvent.setRowEventType(1); // type 1
2322+ writeEvent.initWithData(_data);
2323+}
2324+
2325+void EventData::getQueryEvent(QueryEvent& queryEvent)
2326+{
2327+ queryEvent.initWithData(_data);
2328+}
2329+void EventData::getXidEvent(XidEvent& xidEvent)
2330+{
2331+ xidEvent.initWithData(_data);
2332+}
2333
2334=== added file 'libdrizzle/event_header.cc'
2335--- libdrizzle/event_header.cc 1970-01-01 00:00:00 +0000
2336+++ libdrizzle/event_header.cc 2013-09-23 11:52:14 +0000
2337@@ -0,0 +1,67 @@
2338+/*
2339+ * Copyright (C) 2013 Drizzle Developer Group
2340+ * Copyright (C) 2013 Kuldeep Porwal
2341+ * All rights reserved.
2342+ *
2343+ * Use and distribution licensed under the BSD license. See
2344+ * the COPYING file in the parent directory for full text.
2345+ *
2346+ * summary: parsing of header (common for each event)
2347+ *
2348+ */
2349+
2350+#include "config.h"
2351+#include<iostream>
2352+#include "libdrizzle/common.h"
2353+#include <stdio.h>
2354+#include <stdlib.h>
2355+#include <errno.h>
2356+#include <inttypes.h>
2357+#include<string.h>
2358+
2359+#ifndef event_header
2360+#define event_header
2361+#include<libdrizzle-5.1/event_header.h>
2362+#endif
2363+
2364+using namespace std;
2365+using namespace binlogevent;
2366+
2367+
2368+int EventHeader::setHeader(const unsigned char* data)
2369+{
2370+ // Total bytes to read: 19
2371+ int start_pos = 0;
2372+ timestamp= getByte4(start_pos,data);
2373+ if(timestamp==UINT_MAX)
2374+ return -1;
2375+ start_pos+=4; // 4 byte for timestamp.
2376+
2377+ if((int)(sizeof(data) - start_pos) < 0)
2378+ return -1;
2379+ int tmp=(uint8_t)data[start_pos];
2380+ type= (enum_event_type)tmp;
2381+ start_pos+=1; // 1 byte for type of evnet.
2382+
2383+ server_id= getByte4(start_pos,data);
2384+ if(server_id==UINT_MAX)
2385+ return -1;
2386+ start_pos+=4; // 4 byte of server ID.
2387+
2388+ event_size= getByte4(start_pos,data);
2389+ if(event_size==UINT_MAX)
2390+ return -1;
2391+ start_pos+=4; // 4 byte for event size.
2392+
2393+ log_pos= getByte4(start_pos,data);
2394+ if(log_pos==UINT_MAX)
2395+ return -1;
2396+ start_pos+=4;// 4 byte for getting possion of next event.
2397+
2398+ flag= getByte2(start_pos,data);
2399+ if(flag==USHRT_MAX)
2400+ return -1;
2401+ start_pos+=2; // 2 bytes for getting flag
2402+
2403+ return start_pos;
2404+}
2405
2406=== added file 'libdrizzle/helper.cc'
2407--- libdrizzle/helper.cc 1970-01-01 00:00:00 +0000
2408+++ libdrizzle/helper.cc 2013-09-23 11:52:14 +0000
2409@@ -0,0 +1,286 @@
2410+/*
2411+ * Copyright (C) 2013 Drizzle Developer Group
2412+ * Copyright (C) 2013 Kuldeep Porwal
2413+ * All rights reserved.
2414+ *
2415+ * Use and distribution licensed under the BSD license. See
2416+ * the COPYING file in the parent directory for full text.
2417+ *
2418+ * summary: Utility functions to parse event data
2419+ *
2420+ */
2421+#include "config.h"
2422+#include<iostream>
2423+#include "libdrizzle/common.h"
2424+#include <stdio.h>
2425+#include <stdlib.h>
2426+#include <errno.h>
2427+#include <inttypes.h>
2428+#include<string.h>
2429+#include<sstream>
2430+#include<libdrizzle-5.1/helper.h>
2431+
2432+using namespace std;
2433+
2434+uint32_t getByte4(int pos,const unsigned char* data)
2435+{
2436+ if((int)(sizeof(data)-pos)<4)
2437+ {
2438+ return UINT_MAX;
2439+ }
2440+ uint32_t tmpMask = mask(32); // all 32 bits set to 1
2441+
2442+ tmpMask=((uint32_t)data[pos]&tmpMask);
2443+ tmpMask=((uint32_t)data[pos+1]<<8|tmpMask);
2444+ tmpMask=((uint32_t)data[pos+2]<<16|tmpMask);
2445+ tmpMask=((uint32_t)data[pos+3]<<24|tmpMask);
2446+
2447+ return tmpMask;
2448+}
2449+
2450+uint32_t getByte3(int pos,const unsigned char* data)
2451+{
2452+ if((int)(sizeof(data)-pos)<3)
2453+ {
2454+ return UINT_MAX;
2455+ }
2456+ uint32_t tmpMask = mask(32); // all 32 bits set to 1
2457+
2458+ tmpMask=((uint32_t)data[pos]&tmpMask);
2459+ tmpMask=((uint32_t)data[pos+1]<<8|tmpMask);
2460+ tmpMask=((uint32_t)data[pos+2]<<16|tmpMask);
2461+
2462+ return tmpMask;
2463+}
2464+
2465+uint16_t getByte2(int pos,const unsigned char* data)
2466+{
2467+ if((int)sizeof(data)-pos<2)
2468+ {
2469+ return USHRT_MAX;
2470+ }
2471+ uint16_t tmpMask = mask(16); // all 16 bits set to 1
2472+
2473+ tmpMask=((uint16_t)data[pos]&tmpMask);
2474+ tmpMask=((uint16_t)data[pos+1]<<8|tmpMask);
2475+
2476+ return tmpMask;
2477+}
2478+
2479+
2480+uint64_t getByte6(int pos,const unsigned char* data)
2481+{
2482+ if((int)sizeof(data)-pos<6)
2483+ {
2484+ return UINT_MAX;
2485+ }
2486+ uint64_t tmpMask = mask(64); // all 64 bits set to 1
2487+
2488+ tmpMask=((uint64_t)data[pos]&tmpMask);
2489+ tmpMask=((uint64_t)data[pos+1]<<8|tmpMask);
2490+ tmpMask=((uint64_t)data[pos+2]<<16|tmpMask);
2491+ tmpMask=((uint64_t)data[pos+3]<<24|tmpMask);
2492+ tmpMask=((uint64_t)data[pos+4]<<32|tmpMask);
2493+ tmpMask=((uint64_t)data[pos+5]<<40|tmpMask);
2494+
2495+ return tmpMask;
2496+}
2497+
2498+uint64_t getByte8(int pos,const unsigned char* data)
2499+{
2500+ if((int)sizeof(data)-pos<8)
2501+ {
2502+ return UINT_MAX;
2503+ }
2504+ uint64_t tmpMask = mask(64); // all 64 bits set to 1
2505+
2506+ tmpMask=((uint64_t)data[pos]&tmpMask);
2507+ tmpMask=((uint64_t)data[pos+1]<<8|tmpMask);
2508+ tmpMask=((uint64_t)data[pos+2]<<16|tmpMask);
2509+ tmpMask=((uint64_t)data[pos+3]<<24|tmpMask);
2510+ tmpMask=((uint64_t)data[pos+4]<<32|tmpMask);
2511+ tmpMask=((uint64_t)data[pos+5]<<40|tmpMask);
2512+ tmpMask=((uint64_t)data[pos+5]<<48|tmpMask);
2513+ tmpMask=((uint64_t)data[pos+5]<<56|tmpMask);
2514+
2515+ return tmpMask;
2516+}
2517+
2518+char * getString(int pos,int len,const unsigned char * data)
2519+{
2520+ if((int)sizeof(data)-pos<len)
2521+ {
2522+ return NULL;
2523+ }
2524+ char *tmp = (char *)malloc(sizeof(char)*(len));
2525+ int i;
2526+ for(i=pos;i<pos+len;i++)
2527+ {
2528+ tmp[i-pos]=data[i];
2529+ }
2530+ tmp[i-pos]='\0';
2531+ return tmp;
2532+}
2533+
2534+std::string getIntToStr(uint64_t num)
2535+{
2536+ std::stringstream ss;
2537+ ss << num;
2538+ std::string str=ss.str();
2539+ return str;
2540+}
2541+
2542+uint64_t getEncodedLen(int& pos, const unsigned char *data)
2543+{
2544+ uint64_t len=0;
2545+ if((int)sizeof(data)-pos<1)
2546+ {
2547+ return 0;
2548+ }
2549+
2550+ int colBytes = bytes_col_count((uint32_t)data[pos]);
2551+ if((int)sizeof(data)-pos-1<colBytes)
2552+ {
2553+ pos++;
2554+ return 0;
2555+ }
2556+ switch(colBytes)
2557+ {
2558+ case 1:
2559+ len= (uint64_t)data[pos];
2560+ break;
2561+
2562+ case 2:
2563+ len= (uint64_t)getByte2(pos+1,data);
2564+ break;
2565+ case 3:
2566+ len= (uint64_t)getByte3(pos+1,data);
2567+ break;
2568+ case 8:
2569+ len= (uint64_t)getByte8(pos+1,data);
2570+ break;
2571+ default:
2572+ break;
2573+ }
2574+ pos+=colBytes+(colBytes>1)?1:0; // include first byte if colCount>1
2575+
2576+ return len;
2577+}
2578+
2579+bool getNextBit(uint8_t& val)
2580+{
2581+ val = val >> 1;
2582+ return (val & 1);
2583+}
2584+int getBoolArray(bool arr[],const unsigned char data[],int start_pos,int _byte,int _bit)
2585+{
2586+ if((int)sizeof(data)-start_pos<_byte)
2587+ {
2588+ return -1;
2589+ }
2590+ int count=0;
2591+ for(int i=0;i<_byte;i++)
2592+ {
2593+ if(8*i>=_bit)
2594+ break;
2595+ uint8_t number= (uint8_t)data[start_pos+i];
2596+ arr[8*i] = (int)number&(int)1;
2597+ if(arr[8*i]==0)
2598+ count++;
2599+ for(int val=1;val<8;val++)
2600+ {
2601+ if((8*i+val) >= _bit)
2602+ break;
2603+ arr[8*i+val] = getNextBit(number);
2604+ if(arr[8*i+val]==0)
2605+ count++;
2606+ }
2607+ }
2608+ return count; // count where bit in not set. (0)
2609+
2610+}
2611+int lookup_metadata_field_size(enum_field_types field_type)
2612+{
2613+ switch (field_type)
2614+ {
2615+ case MYSQL_TYPE_DOUBLE:
2616+ case MYSQL_TYPE_FLOAT:
2617+ case MYSQL_TYPE_BLOB:
2618+ case MYSQL_TYPE_GEOMETRY:
2619+ return 1;
2620+ case MYSQL_TYPE_BIT:
2621+ case MYSQL_TYPE_VARCHAR:
2622+ case MYSQL_TYPE_NEWDECIMAL:
2623+ case MYSQL_TYPE_STRING:
2624+ case MYSQL_TYPE_VAR_STRING:
2625+ return 2;
2626+ case MYSQL_TYPE_DECIMAL:
2627+ case MYSQL_TYPE_SET:
2628+ case MYSQL_TYPE_ENUM:
2629+ case MYSQL_TYPE_YEAR:
2630+ case MYSQL_TYPE_TINY:
2631+ case MYSQL_TYPE_SHORT:
2632+ case MYSQL_TYPE_INT24:
2633+ case MYSQL_TYPE_LONG:
2634+ case MYSQL_TYPE_LONGLONG:
2635+ case MYSQL_TYPE_NEWDATE:
2636+ case MYSQL_TYPE_DATE:
2637+ case MYSQL_TYPE_TIME:
2638+ case MYSQL_TYPE_TIMESTAMP:
2639+ case MYSQL_TYPE_DATETIME:
2640+ case MYSQL_TYPE_TINY_BLOB:
2641+ case MYSQL_TYPE_MEDIUM_BLOB:
2642+ case MYSQL_TYPE_LONG_BLOB:
2643+ case MYSQL_TYPE_NULL:
2644+ default:
2645+ return 0;
2646+ }
2647+
2648+}
2649+
2650+enum_field_bytes lookup_field_bytes(enum_field_types field_type)
2651+{
2652+ switch (field_type)
2653+ {
2654+ case MYSQL_TYPE_DECIMAL:
2655+ case MYSQL_TYPE_TIMESTAMP:
2656+ case MYSQL_TYPE_DATE:
2657+ case MYSQL_TYPE_TIME:
2658+ case MYSQL_TYPE_DATETIME:
2659+ case MYSQL_TYPE_NEWDATE:
2660+ case MYSQL_TYPE_VARCHAR:
2661+ case MYSQL_TYPE_BIT:
2662+ case MYSQL_TYPE_NEWDECIMAL:
2663+ case MYSQL_TYPE_TINY_BLOB:
2664+ case MYSQL_TYPE_MEDIUM_BLOB:
2665+ case MYSQL_TYPE_LONG_BLOB:
2666+ case MYSQL_TYPE_BLOB:
2667+ case MYSQL_TYPE_VAR_STRING:
2668+ case MYSQL_TYPE_STRING:
2669+ return LEN_ENC_STR;
2670+
2671+ case MYSQL_TYPE_TINY:
2672+ return READ_1_BYTE;
2673+
2674+ case MYSQL_TYPE_SHORT:
2675+ case MYSQL_TYPE_YEAR:
2676+ return READ_2_BYTE;
2677+
2678+ case MYSQL_TYPE_LONG:
2679+ case MYSQL_TYPE_FLOAT:
2680+ case MYSQL_TYPE_INT24:
2681+ return READ_4_BYTE;
2682+
2683+ case MYSQL_TYPE_DOUBLE:
2684+ case MYSQL_TYPE_LONGLONG:
2685+ return READ_8_BYTE;
2686+
2687+ case MYSQL_TYPE_NULL:
2688+ case MYSQL_TYPE_ENUM:
2689+ case MYSQL_TYPE_SET:
2690+ case MYSQL_TYPE_GEOMETRY:
2691+ default:
2692+ return NOT_FOUND;
2693+
2694+ }
2695+}
2696
2697=== modified file 'libdrizzle/include.am'
2698--- libdrizzle/include.am 2013-01-27 11:22:49 +0000
2699+++ libdrizzle/include.am 2013-09-23 11:52:14 +0000
2700@@ -19,6 +19,10 @@
2701 noinst_HEADERS+= libdrizzle/structs.h
2702 noinst_HEADERS+= libdrizzle/windows.hpp
2703
2704+noinst_HEADERS+= libdrizzle/commonapi.h
2705+
2706+# Paths for new binlog api
2707+
2708 lib_LTLIBRARIES+= libdrizzle/libdrizzle.la
2709 libdrizzle_libdrizzle_la_SOURCES=
2710 libdrizzle_libdrizzle_la_LIBADD=
2711@@ -65,4 +69,15 @@
2712 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/statement.cc
2713 libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/statement_param.cc
2714
2715+# paths for new binlog api
2716+
2717+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/event_data.cc
2718+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/event_header.cc
2719+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/helper.cc
2720+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/query_event.cc
2721+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/row_event.cc
2722+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/xid_event.cc
2723+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/row_iterator.cc
2724+libdrizzle_libdrizzle_la_SOURCES+= libdrizzle/table_map_event.cc
2725+
2726 libdrizzle_libdrizzle_la_LDFLAGS+= -version-info ${LIBDRIZZLE_LIBRARY_VERSION}
2727
2728=== added file 'libdrizzle/query_event.cc'
2729--- libdrizzle/query_event.cc 1970-01-01 00:00:00 +0000
2730+++ libdrizzle/query_event.cc 2013-09-23 11:52:14 +0000
2731@@ -0,0 +1,126 @@
2732+/*
2733+ * Copyright (C) 2013 Drizzle Developer Group
2734+ * Copyright (C) 2013 Kuldeep Porwal
2735+ * All rights reserved.
2736+ *
2737+ * Use and distribution licensed under the BSD license. See
2738+ * the COPYING file in the parent directory for full text.
2739+ *
2740+ * summary: parse query event
2741+ *
2742+ */
2743+#include "config.h"
2744+#include<iostream>
2745+#include "libdrizzle/common.h"
2746+#include <stdio.h>
2747+#include <stdlib.h>
2748+#include <errno.h>
2749+#include <inttypes.h>
2750+#include<string.h>
2751+
2752+#ifndef write_map
2753+#define write_map
2754+
2755+#include<libdrizzle-5.1/query_event.h>
2756+
2757+#endif
2758+//#include"helper.h"
2759+
2760+using namespace std;
2761+using namespace binlogevent;
2762+
2763+
2764+
2765+void QueryEvent::initWithData(const unsigned char* data)
2766+{
2767+ uint64_t tmp;
2768+ int start_pos = header.setHeader(data);
2769+ if(start_pos==-1)
2770+ return;
2771+
2772+ tmp = getByte4(start_pos,data);
2773+ if(tmp==UINT_MAX)
2774+ return;
2775+ setProxyId((uint32_t)tmp);
2776+ start_pos+=4;// 4 byte for proxy id.
2777+
2778+ tmp = getByte4(start_pos,data);
2779+ if(tmp==UINT_MAX)
2780+ return;
2781+ setExecutionTime((uint32_t)tmp);
2782+ start_pos+=4;// 4 byte for execution time.
2783+
2784+ if(sizeof(data)-start_pos<1)
2785+ return;
2786+ setSchemaLength((uint8_t)data[start_pos]);
2787+ start_pos+=1;// 1 byte for schema length.
2788+
2789+ tmp = getByte2(start_pos,data);
2790+ if(tmp==USHRT_MAX)
2791+ return;
2792+ setErrorCode((uint16_t)tmp);
2793+ start_pos+=2;// 2 byte for error code.
2794+
2795+}
2796+
2797+// getters
2798+
2799+uint32_t QueryEvent::getTimestamp()
2800+{
2801+ return header.timestamp;
2802+}
2803+uint8_t QueryEvent::getType()
2804+{
2805+ return header.type;
2806+}
2807+uint32_t QueryEvent::getServerId()
2808+{
2809+ return header.server_id;
2810+}
2811+uint32_t QueryEvent::getEventSize()
2812+{
2813+ return header.event_size;
2814+}
2815+uint32_t QueryEvent::getLogPos()
2816+{
2817+ return header.log_pos;
2818+}
2819+uint16_t QueryEvent::getFlagH()
2820+{
2821+ return header.flag;
2822+}
2823+uint32_t QueryEvent::getProxyId()
2824+{
2825+ return proxy_id;
2826+}
2827+uint32_t QueryEvent::getExecutionTime()
2828+{
2829+ return execution_time;
2830+}
2831+uint8_t QueryEvent::getSchemaLength()
2832+{
2833+ return schema_length;
2834+}
2835+uint16_t QueryEvent::getErrorCode()
2836+{
2837+ return error_code;
2838+}
2839+
2840+//setters
2841+
2842+void QueryEvent::setProxyId(uint32_t value)
2843+{
2844+ proxy_id = value;
2845+}
2846+void QueryEvent::setExecutionTime(uint32_t value)
2847+{
2848+ execution_time = value;
2849+}
2850+void QueryEvent::setSchemaLength(uint8_t value)
2851+{
2852+ schema_length = value;
2853+}
2854+void QueryEvent::setErrorCode(uint16_t value)
2855+{
2856+ error_code = value;
2857+}
2858
2859=== added file 'libdrizzle/row_event.cc'
2860--- libdrizzle/row_event.cc 1970-01-01 00:00:00 +0000
2861+++ libdrizzle/row_event.cc 2013-09-23 11:52:14 +0000
2862@@ -0,0 +1,297 @@
2863+/*
2864+ * Copyright (C) 2013 Drizzle Developer Group
2865+ * Copyright (C) 2013 Kuldeep Porwal
2866+ * All rights reserved.
2867+ *
2868+ * Use and distribution licensed under the BSD license. See
2869+ * the COPYING file in the parent directory for full text.
2870+ *
2871+ * summary: parsing of row events like write event, update event, delete event
2872+ *
2873+ */
2874+
2875+#include "config.h"
2876+#include<iostream>
2877+#include "libdrizzle/common.h"
2878+#include <stdio.h>
2879+#include <stdlib.h>
2880+#include <errno.h>
2881+#include <inttypes.h>
2882+#include<string.h>
2883+#include<limits.h>
2884+#ifndef row_event
2885+#define row_event
2886+
2887+#include<libdrizzle-5.1/row_event.h>
2888+
2889+#endif
2890+
2891+#ifndef HELPER
2892+#define HELPER
2893+
2894+#include<libdrizzle-5.1/helper.h>
2895+
2896+#endif
2897+
2898+using namespace std;
2899+using namespace binlogevent;
2900+
2901+
2902+
2903+void RowEvent::initWithData(const unsigned char* data)
2904+{
2905+ if(row_event_type<0) // Event type not exist
2906+ return;
2907+ uint64_t tmp;
2908+ int tmp_int;
2909+ int start_pos = header.setHeader(data);
2910+ if(start_pos==-1)
2911+ return;
2912+
2913+ tmp = getByte6(start_pos,data);
2914+ if(tmp==UINT_MAX)
2915+ return;
2916+ setTableId((uint64_t)tmp);
2917+ start_pos+=6;// 6 byte for table id.
2918+
2919+ tmp = getByte2(start_pos,data);
2920+ if(tmp==USHRT_MAX)
2921+ return;
2922+ setFlagPh((uint16_t)tmp);
2923+ start_pos+=2;// 2 byte for post-header flag.
2924+
2925+ tmp_int = getEncodedLen(start_pos,data);
2926+ if(tmp_int==0)
2927+ return;
2928+ setColumnCount(tmp_int); // start_pos will also get updated
2929+
2930+ int size= (column_count+7)/8; // length of present column bitmap1
2931+
2932+ int count_cnp=0; // count of column not present
2933+
2934+ bool *tmp_present = new bool(column_count); // bit array of column bitmap1
2935+ count_cnp = getBoolArray(tmp_present,data,start_pos,size,column_count); // return -1 when data problem
2936+
2937+ if(count_cnp==-1)
2938+ return;
2939+
2940+ setColumnPresentBitmap(tmp_present);
2941+
2942+ start_pos+=size; //null-bitmap
2943+ size= (column_count-count_cnp+7)/8; // length of null bitmap in bytes
2944+
2945+ bool *tmp_bool = new bool(column_count-count_cnp);
2946+ count_cnp = getBoolArray(tmp_bool,data,start_pos,size,(column_count-count_cnp)); // return -1 when data problem
2947+
2948+ if(count_cnp==-1)
2949+ return;
2950+
2951+ setNullBitmap(tmp_bool);
2952+
2953+ start_pos+=size;
2954+
2955+ //LOOP for ROWs
2956+ while(1)
2957+ {
2958+ rows.vec_col_val.clear();
2959+ string str_col_val; // column value as string
2960+ unsigned int int_col_val = UINT_MAX; // column value as int
2961+ for(uint64_t val=0;val<column_count;val++)
2962+ {
2963+ if(column_bitmap[val]==0)
2964+ continue;
2965+
2966+ if(null_bitmap[val]==1)
2967+ {
2968+ str_col_val.clear();
2969+ ColumnValue value(str_col_val,1,val); // 1 -> null, val is column number
2970+ rows.vec_col_val.push_back(value);
2971+ continue;
2972+
2973+ }
2974+
2975+ enum_field_bytes num;
2976+ num = lookup_field_bytes((enum_field_types)column_type[val]);
2977+ switch(num)
2978+ {
2979+ case LEN_ENC_STR:
2980+ {
2981+ int len;
2982+ len=getEncodedLen(start_pos,data);
2983+ if(len==0)
2984+ {
2985+ return;
2986+ }
2987+ str_col_val.clear();
2988+ len=start_pos+len-1;
2989+
2990+ if((int)sizeof(data)-start_pos<len)
2991+ return;
2992+ for(int it=start_pos;it<=len;it++) // Formation of string
2993+ {
2994+ str_col_val.push_back(data[it]);
2995+ }
2996+ ColumnValue value(str_col_val,0,val); // 0 -> not null
2997+ rows.vec_col_val.push_back(value);
2998+ start_pos+=len; //length of string
2999+ break;
3000+ }
3001+ case READ_1_BYTE:
3002+ {
3003+ if((int)sizeof(data)-start_pos<1)
3004+ return;
3005+ str_col_val.clear();
3006+ int_col_val = (uint8_t)data[start_pos];
3007+ str_col_val = getIntToStr(int_col_val);
3008+ ColumnValue value(str_col_val,0,val);
3009+ rows.vec_col_val.push_back(value);
3010+ start_pos+=(int)READ_1_BYTE;
3011+ break;
3012+ }
3013+ case READ_2_BYTE:
3014+ {
3015+ str_col_val.clear();
3016+ int_col_val = getByte2(start_pos,data);
3017+ if(int_col_val==USHRT_MAX)
3018+ return;
3019+ str_col_val = getIntToStr(int_col_val);
3020+ ColumnValue value(str_col_val,0,val);
3021+ rows.vec_col_val.push_back(value);
3022+ start_pos+=(int)READ_2_BYTE;
3023+ break;
3024+ }
3025+ case READ_4_BYTE:
3026+ {
3027+ str_col_val.clear();
3028+ int_col_val = getByte4(start_pos,data);
3029+ if(int_col_val==UINT_MAX)
3030+ return;
3031+ str_col_val = getIntToStr(int_col_val);
3032+ ColumnValue value(str_col_val,0,val);
3033+ rows.vec_col_val.push_back(value);
3034+ start_pos+=(int)READ_4_BYTE;
3035+ break;
3036+ }
3037+ case READ_8_BYTE:
3038+ {
3039+ str_col_val.clear();
3040+ int_col_val = getByte8(start_pos,data);
3041+ if(int_col_val==UINT_MAX)
3042+ return;
3043+ str_col_val = getIntToStr(int_col_val);
3044+ ColumnValue value(str_col_val,0,val);
3045+ rows.vec_col_val.push_back(value);
3046+ start_pos+=(int)READ_8_BYTE;
3047+ break;
3048+ }
3049+ case NOT_FOUND:
3050+ {
3051+ break;
3052+ }
3053+
3054+
3055+
3056+ }
3057+ }
3058+
3059+ rows.vec_rows.push_back(rows.vec_col_val);
3060+ if((int)header.event_size==start_pos)
3061+ {
3062+ break;
3063+ }
3064+ }
3065+
3066+
3067+
3068+}
3069+
3070+// getters
3071+int RowEvent::getRowEventType()
3072+{
3073+ return row_event_type;
3074+}
3075+uint32_t RowEvent::getTimestamp()
3076+{
3077+ return header.timestamp;
3078+}
3079+enum_event_type RowEvent::getType()
3080+{
3081+ return (enum_event_type)header.type;
3082+}
3083+uint32_t RowEvent::getServerId()
3084+{
3085+ return header.server_id;
3086+}
3087+uint32_t RowEvent::getEventSize()
3088+{
3089+ return header.event_size;
3090+}
3091+uint32_t RowEvent::getLogPos()
3092+{
3093+ return header.log_pos;
3094+}
3095+uint16_t RowEvent::getFlagH()
3096+{
3097+ return header.flag;
3098+}
3099+uint64_t RowEvent::getTableId()
3100+{
3101+ return table_id;
3102+}
3103+uint16_t RowEvent::getFlagPh()
3104+{
3105+ return flag;
3106+}
3107+uint64_t RowEvent::getColumnCount()
3108+{
3109+ return column_count;
3110+}
3111+bool * RowEvent::getColumnPresentBitmap()
3112+{
3113+ return column_bitmap;
3114+}
3115+RowVector RowEvent::getRows()
3116+{
3117+ return rows.vec_rows;
3118+}
3119+
3120+/*Row RowEvent::getRow()
3121+{
3122+ rows.setCurrentPos(0);
3123+ return rows.vec_rows;
3124+}
3125+
3126+RowVector RowEvent::getAllRows()
3127+{
3128+ rows.setCurrentPos(0);
3129+ return rows.vec_rows;
3130+}*/
3131+
3132+
3133+
3134+//setters
3135+//setters
3136+void RowEvent::setRowEventType(int value)
3137+{
3138+ row_event_type=value;
3139+}
3140+void RowEvent::setTableId(uint64_t value)
3141+{
3142+ table_id = value;
3143+}
3144+void RowEvent::setFlagPh(uint16_t value)
3145+{
3146+ flag = value;
3147+}
3148+void RowEvent::setColumnCount(uint64_t value)
3149+{
3150+ column_count = value;
3151+}
3152+void RowEvent::setColumnPresentBitmap(bool * value)
3153+{
3154+ column_bitmap = value;
3155+}
3156+void RowEvent::setNullBitmap(bool * value)
3157+{
3158+ null_bitmap = value;
3159+}
3160
3161=== added file 'libdrizzle/row_iterator.cc'
3162--- libdrizzle/row_iterator.cc 1970-01-01 00:00:00 +0000
3163+++ libdrizzle/row_iterator.cc 2013-09-23 11:52:14 +0000
3164@@ -0,0 +1,16 @@
3165+/*
3166+ * Copyright (C) 2013 Drizzle Developer Group
3167+ * Copyright (C) 2013 Kuldeep Porwal
3168+ * All rights reserved.
3169+ *
3170+ * Use and distribution licensed under the BSD license. See
3171+ * the COPYING file in the parent directory for full text.
3172+ *
3173+ * summary: utility functions to get each row of Row event
3174+ *
3175+ */
3176+#include "config.h"
3177+#include<libdrizzle-5.1/row_iterator.h>
3178+
3179+using namespace binlogevent;
3180+
3181
3182=== added file 'libdrizzle/table_map_event.cc'
3183--- libdrizzle/table_map_event.cc 1970-01-01 00:00:00 +0000
3184+++ libdrizzle/table_map_event.cc 2013-09-23 11:52:14 +0000
3185@@ -0,0 +1,235 @@
3186+/*
3187+ * Copyright (C) 2013 Drizzle Developer Group
3188+ * Copyright (C) 2013 Kuldeep Porwal
3189+ * All rights reserved.
3190+ *
3191+ * Use and distribution licensed under the BSD license. See
3192+ * the COPYING file in the parent directory for full text.
3193+ *
3194+ * summary: parse table map event
3195+ *
3196+ */
3197+#include "config.h"
3198+#include<iostream>
3199+#include "libdrizzle/common.h"
3200+#include "libdrizzle/commonapi.h"
3201+#include <stdio.h>
3202+#include <stdlib.h>
3203+#include <errno.h>
3204+#include <inttypes.h>
3205+#include<string.h>
3206+
3207+/*#ifndef table_map
3208+
3209+#define table_map
3210+
3211+#include<libdrizzle-5.1/table_map_event.h>
3212+
3213+#endif*/
3214+
3215+
3216+using namespace std;
3217+using namespace binlogevent;
3218+
3219+
3220+
3221+void TableMapEvent::initWithData(const unsigned char* data)
3222+{
3223+ uint64_t tmp;
3224+ char *tmp_char;
3225+ int tmp_int;
3226+ int start_pos = header.setHeader(data);
3227+ if(start_pos==-1)
3228+ return;
3229+
3230+ tmp = getByte6(start_pos,data);
3231+ if(tmp==UINT_MAX)
3232+ return;
3233+ setTableId((uint64_t)tmp);
3234+ start_pos+=6;// 6 byte for table id.
3235+
3236+ tmp = getByte2(start_pos,data);
3237+ if(tmp==USHRT_MAX)
3238+ return;
3239+ setFlagPh((uint16_t)tmp);
3240+ start_pos+=2;// 2 byte for post-header flag.
3241+
3242+ if(sizeof(data)-start_pos<1)
3243+ return;
3244+ setSchemaNameLen((uint8_t)data[start_pos]);
3245+ start_pos+=1;// 1 byte for schema name length.
3246+
3247+ tmp_char = getString(start_pos,schema_name_len,data);
3248+ if(tmp_char==NULL)
3249+ return;
3250+ setSchemaName(tmp_char);
3251+ start_pos+= schema_name_len; //schema_name_len byte for schema name.
3252+
3253+ // data[start_pos+getSchemaNameLen()] is Null
3254+ start_pos+=1; // +1 for Null.
3255+
3256+ if(sizeof(data)-start_pos<1)
3257+ return;
3258+ setTableNameLen((uint8_t)data[start_pos]);
3259+ start_pos+=1;// 1 byte for table name length.
3260+
3261+ tmp_char = getString(start_pos,schema_name_len,data);
3262+ if(tmp_char==NULL)
3263+ return;
3264+ setTableName(tmp_char);
3265+ start_pos+=table_name_len+1; // +1 for null
3266+
3267+ tmp_int = getEncodedLen(start_pos,data);
3268+ if(tmp_int==0)
3269+ return;
3270+ setColumnCount(getEncodedLen(start_pos,data)); // start_pos will also get updated
3271+
3272+
3273+ if(sizeof(data)-start_pos<getColumnCount())
3274+ return;
3275+ uint8_t *tmp_array = (uint8_t *)(malloc(sizeof(uint8_t)*getColumnCount()));
3276+ for(uint64_t i=0;i<getColumnCount();i++)
3277+ {
3278+ tmp_array[i]=(uint8_t)data[start_pos+i];
3279+ }
3280+ setColumnTypeDef(tmp_array);
3281+ start_pos+=column_count;
3282+
3283+
3284+ int metaSize= getEncodedLen(start_pos,data);
3285+ if(metaSize==0)
3286+ return;
3287+ column_meta_data = (uint64_t *)(malloc(sizeof(uint64_t)*column_count));
3288+
3289+ if(sizeof(data)-start_pos<column_count)
3290+ return;
3291+ for(uint64_t col=0;col<column_count;col++)
3292+ {
3293+ int type= column_type_def[col];
3294+ int nextBytes= lookup_metadata_field_size((enum_field_types)type);
3295+ int metaData=0;
3296+ switch(nextBytes)
3297+ {
3298+ case 1:
3299+ metaData= (int)data[start_pos];
3300+ break;
3301+ case 2:
3302+ metaData= (int)getByte2(start_pos,data);
3303+ break;
3304+ default:
3305+ break;
3306+ }
3307+ column_meta_data[col]= metaData;
3308+ start_pos+=nextBytes;
3309+ }
3310+
3311+}
3312+
3313+// getters
3314+
3315+uint32_t TableMapEvent::getTimestamp()
3316+{
3317+ return header.timestamp;
3318+}
3319+enum_event_type TableMapEvent::getType()
3320+{
3321+ return (enum_event_type)header.type;
3322+}
3323+uint32_t TableMapEvent::getServerId()
3324+{
3325+ return header.server_id;
3326+}
3327+uint32_t TableMapEvent::getLogPos()
3328+{
3329+ return header.log_pos;
3330+}
3331+uint16_t TableMapEvent::getFlagH()
3332+{
3333+ return header.flag;
3334+}
3335+uint64_t TableMapEvent::getTableId()
3336+{
3337+ return table_id;
3338+}
3339+uint16_t TableMapEvent::getFlagPh()
3340+{
3341+ return flag;
3342+}
3343+int TableMapEvent::getSchemaNameLen()
3344+{
3345+ return (int)schema_name_len;
3346+}
3347+char * TableMapEvent::getSchemaName()
3348+{
3349+ return schema_name;
3350+}
3351+int TableMapEvent::getTableNameLen()
3352+{
3353+ return (int)table_name_len;
3354+}
3355+char * TableMapEvent::getTableName()
3356+{
3357+ return table_name;
3358+}
3359+uint64_t TableMapEvent::getColumnCount()
3360+{
3361+ return column_count;
3362+}
3363+uint8_t * TableMapEvent::getColumnTypeDef()
3364+{
3365+ return column_type_def;
3366+}
3367+
3368+enum_col_type TableMapEvent::getColType(int colNo)
3369+{
3370+ enum_field_bytes num;
3371+ num = lookup_field_bytes((enum_field_types)column_type_def[colNo]);
3372+ switch(num)
3373+ {
3374+ case LEN_ENC_STR:
3375+ return (enum_col_type)1;
3376+ case READ_1_BYTE:
3377+ case READ_2_BYTE:
3378+ case READ_4_BYTE:
3379+ case READ_8_BYTE:
3380+ case NOT_FOUND:
3381+ default:
3382+ return (enum_col_type)2;
3383+ }
3384+}
3385+
3386+
3387+//setters
3388+
3389+void TableMapEvent::setTableId(uint64_t value)
3390+{
3391+ table_id = value;
3392+}
3393+void TableMapEvent::setFlagPh(uint16_t value)
3394+{
3395+ flag = value;
3396+}
3397+void TableMapEvent::setSchemaNameLen(uint8_t value)
3398+{
3399+ schema_name_len = value;
3400+}
3401+void TableMapEvent::setSchemaName(char *value)
3402+{
3403+ schema_name = value;
3404+}
3405+void TableMapEvent::setTableNameLen(uint8_t value)
3406+{
3407+ table_name_len = value;
3408+}
3409+void TableMapEvent::setTableName(char *value)
3410+{
3411+ table_name = value;
3412+}
3413+void TableMapEvent::setColumnCount(uint64_t value)
3414+{
3415+ column_count = value;
3416+}
3417+void TableMapEvent::setColumnTypeDef(uint8_t * value)
3418+{
3419+ column_type_def = value;
3420+}
3421
3422=== added file 'libdrizzle/xid_event.cc'
3423--- libdrizzle/xid_event.cc 1970-01-01 00:00:00 +0000
3424+++ libdrizzle/xid_event.cc 2013-09-23 11:52:14 +0000
3425@@ -0,0 +1,82 @@
3426+/*
3427+ * Copyright (C) 2013 Drizzle Developer Group
3428+ * Copyright (C) 2013 Kuldeep Porwal
3429+ * All rights reserved.
3430+ *
3431+ * Use and distribution licensed under the BSD license. See
3432+ * the COPYING file in the parent directory for full text.
3433+ *
3434+ * summary: parse xid event
3435+ *
3436+ */
3437+#include "config.h"
3438+#include<iostream>
3439+#include "libdrizzle/common.h"
3440+#include <stdio.h>
3441+#include <stdlib.h>
3442+#include <errno.h>
3443+#include <inttypes.h>
3444+#include<string.h>
3445+
3446+#include<libdrizzle-5.1/xid_event.h>
3447+
3448+
3449+#ifndef HELPER
3450+#define HELPER
3451+
3452+#include<libdrizzle-5.1/helper.h>
3453+
3454+#endif
3455+
3456+using namespace std;
3457+using namespace binlogevent;
3458+
3459+
3460+
3461+void XidEvent::initWithData(const unsigned char* data)
3462+{
3463+
3464+ int start_pos = header.setHeader(data);
3465+ if(start_pos==-1)
3466+ return;
3467+ uint64_t tmp;
3468+
3469+ tmp=getByte8(start_pos,data);
3470+ if(tmp==UINT_MAX)
3471+ return;
3472+ setXid((uint64_t)tmp);
3473+}
3474+
3475+// getters
3476+
3477+uint32_t XidEvent::getTimestamp()
3478+{
3479+ return header.timestamp;
3480+}
3481+enum_event_type XidEvent::getType()
3482+{
3483+ return (enum_event_type)header.type;
3484+}
3485+uint32_t XidEvent::getServerId()
3486+{
3487+ return header.server_id;
3488+}
3489+uint32_t XidEvent::getLogPos()
3490+{
3491+ return header.log_pos;
3492+}
3493+uint16_t XidEvent::getFlagH()
3494+{
3495+ return header.flag;
3496+}
3497+uint64_t XidEvent::getXid()
3498+{
3499+ return Xid;
3500+}
3501+
3502+//setters
3503+
3504+void XidEvent::setXid(uint64_t value)
3505+{
3506+ Xid = value;
3507+}

Subscribers

People subscribed via source and target branches

to status/vote changes: