summaryrefslogtreecommitdiff
path: root/mysql-test/include/get_frm_info.inc
blob: db9c319542b00f92765b000469fc2671eb389c16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
perl;
  use strict;
  my $path = "$ENV{'PATH_TO_TABLE'}";
  if ($path eq "") { die "No path given!"; }
  my @found_files = glob($path . "*.MYD");
  if ($#found_files >= 0) {
    print "found " . (1 + $#found_files) . " *.MYD file(s)\n";
  }
  @found_files = glob($path . "*.ibd");
  if ($#found_files >= 0) {
    print "found " . (1 + $#found_files) . " *.ibd file(s)\n";
  }
  if (-e $path . ".par") {
    print ".par file exists\n";
  }
  my $frm_file = $path . ".frm";
  if (not -e $frm_file) {
    die $frm_file . " does not file exists!";
  }
  open(FH, "<", $frm_file) or die "Failed to open '$frm_file'";
  binmode FH;
  my $bin_val;
  seek(FH, 0x33, 0) or die "Failed to seek";
  my $res= read FH, $bin_val, 4;
  die "Failed to read bin_val! res: $res" unless ($res == 4);
  my $frm_ver = unpack("V", $bin_val);
  if ($frm_ver >= 50708) {
    print ".frm created by version >= 5.7.8\n";
  } else {
    print ".frm created by version: $frm_ver\n";
  }
  seek(FH, 3, 0) or die "Failed to seek";
  my $res= read FH, $bin_val, 1;
  die "Failed to read bin_val! res: $res" unless ($res == 1);
  print "DB_TYPE (byte 3): " . unpack("C", $bin_val) . "\n";
  seek(FH, 61, 0) or die "Failed to seek";
  $res= read FH, $bin_val, 1;
  die "Failed to read bin_val! res: $res" unless ($res == 1);
  print "DEFAULT_PART_DB_TYPE (byte 61): " . unpack("C", $bin_val) . "\n";
  # Also check the engine name
  seek(FH, 55, 0) or die "Failed to seek";
  $res= read FH, $bin_val, 4;
  my $length = unpack("V", $bin_val);
  if ($length != 0)
  {
    # see from table.cc (reading .frm file)
    seek(FH, 6, 0) or die "Failed to seek";
    $res= read FH, $bin_val, 2;
    my $record_offset= unpack("v", $bin_val);
    seek(FH, 14, 0) or die "Failed to seek";
    $res= read FH, $bin_val, 2;
    my $tmp = unpack("v", $bin_val);
    if ($tmp == 0xffff)
    {
      seek(FH, 47, 0) or die "Failed to seek";
      $res= read FH, $bin_val, 4;
      $tmp= unpack("V", $bin_val);
    }
    $record_offset+= $tmp;
    seek(FH, 16, 0) or die "Failed to seek";
    $res= read FH, $bin_val, 2;
    $tmp = unpack("v", $bin_val);
    $record_offset+= $tmp;
    # connect string length + string
    seek(FH, $record_offset, 0) or die "Failed to seek";
    $res= read FH, $bin_val, 2;
    die "Failed to read bin_val! res: $res" unless ($res == 2);
    $length= unpack("v", $bin_val);
    seek(FH, $record_offset + 2 + $length, 0) or die "Failed to seek";
    $res= read FH, $bin_val, 2;
    die "Failed to read bin_val! res: $res" unless ($res == 2);
    $length= unpack("v", $bin_val);
    $res= read FH, $bin_val, $length;
    die "Failed to read bin_val! res: $res" unless ($res == $length);
    print "DB_TYPE string: '" . $bin_val . "'\n";
  }
  close(FH);
EOF