Skip to content

Commit 617d37b

Browse files
committed
add timestap,binInt parse 增加对mysql5.1的支持
1 parent ba0fdc9 commit 617d37b

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

Connect.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
require_once ROOT . "config/Config.php";
43
require_once ROOT . 'db/TimeDate.php';
54
require_once ROOT . 'db/DBMysql.php';
@@ -285,6 +284,8 @@ public static function analysisBinLog($flag = false) {
285284
// 校验数据包格式
286285
PackAuth::success($pack);
287286

287+
//todo eof pack 0xfe
288+
288289
$binlog = BinLogPack::getInstance();
289290
$result = $binlog->init($pack, self::$_CHECKSUM);
290291

bin/BinLogPack.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function init($pack, $checkSum = true) {
5050
self::$EVENT_INFO['time'] = $timestamp = unpack('L', $this->read(4))[1];
5151
self::$EVENT_INFO['type'] = self::$EVENT_TYPE = unpack('C', $this->read(1))[1];
5252
self::$EVENT_INFO['id'] = $server_id = unpack('L', $this->read(4))[1];
53-
self::$EVENT_INFO['size'] = $event_size = unpack('L', $this->read(4))[1];
53+
self::$EVENT_INFO['sivize'] = $event_size = unpack('L', $this->read(4))[1];
5454
//position of the next event
5555
self::$EVENT_INFO['pos'] = $log_pos = unpack('L', $this->read(4))[1];//
5656
self::$EVENT_INFO['flag'] = $flags = unpack('S', $this->read(2))[1];
@@ -87,6 +87,10 @@ public function init($pack, $checkSum = true) {
8787
//gtid event
8888

8989
}elseif(self::$EVENT_TYPE == 15) {
90+
$pack = self::getInstance();
91+
92+
$pack->read(4);
93+
9094

9195
} elseif(self::$EVENT_TYPE == ConstEventType::QUERY_EVENT) {
9296

@@ -95,8 +99,8 @@ public function init($pack, $checkSum = true) {
9599
if(DEBUG) {
96100
$msg = self::$_FILE_NAME;
97101
$msg .= '-- next pos -> '.$log_pos;
98-
$msg .= ' -- typeEvent -> '.self::$EVENT_TYPE;
99-
Log::out($msg);
102+
$msg .= ' -- typeEvent -> '.self::$EVENT_TYPE;
103+
Log::out($msg);
100104
}
101105

102106
return $data;
@@ -250,15 +254,18 @@ public function readUint56()
250254
/*
251255
* 不支持unsigned long long,溢出
252256
*/
253-
public function readUint64()
254-
{
257+
public function readUint64() {
255258
$d = $this->read(8);
256-
$unpackArr = unpack('I2', $d);
259+
$data = unpack('V*', $d);
260+
$bigInt = bcadd($data[1], bcmul($data[2], bcpow(2, 32)));
261+
return $bigInt;
262+
263+
// $unpackArr = unpack('I2', $d);
257264
//$data = unpack("C*", $d);
258265
//$r = $data[1] + ($data[2] << 8) + ($data[3] << 16) + ($data[4] << 24);//+
259266
//$r2= ($data[5]) + ($data[6] << 8) + ($data[7] << 16) + ($data[8] << 24);
260267

261-
return $unpackArr[1] + ($unpackArr[2] << 32);
268+
// return $unpackArr[1] + ($unpackArr[2] << 32);
262269
}
263270

264271
public function readInt64()

pack/RowEvent.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,13 @@ private static function _read_column_data($cols_bitmap, $len)
282282
$values[$name] = self.__read_time()
283283
elseif ($column['type'] == ConstFieldType::DATE:
284284
$values[$name] = self.__read_date()
285-
elseif ($column['type'] == ConstFieldType::TIMESTAMP:
286-
$values[$name] = datetime.datetime.fromtimestamp(
287-
self::$PACK->read_uint32())
285+
*/
286+
elseif ($column['type'] == ConstFieldType::TIMESTAMP) {
287+
$values[$name] = self::$PACK->readUint32();
288+
}
288289

289290
# For new date format:
290-
291+
/*
291292
elseif ($column['type'] == ConstFieldType::TIME2:
292293
$values[$name] = self.__read_time2(column)
293294
elseif ($column['type'] == ConstFieldType::TIMESTAMP2:

0 commit comments

Comments
 (0)