var common = require('../../common');
var connection = common.createConnection({debug: true});
var assert = require('assert');
var Buffer = require('safe-buffer').Buffer;

var table = 'insert_large_test';
var content = Buffer.allocUnsafe(19777216); // > 16 megabytes
content.fill('x', 0, 100000);
content.fill('o', 100000);

connection.query([
  'CREATE TEMPORARY TABLE `' + table + '` (',
  '`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
  '`content` longblob NOT NULL,',
  'PRIMARY KEY (`id`)',
  ') ENGINE=InnoDB DEFAULT CHARSET=utf8'
].join('\n'));

var result, result2;
connection.query('SET GLOBAL max_allowed_packet=56777216', function (err, res) {
  assert.ifError(err);
  console.log('SET GLOBAL max_allowed_packet=56777216 OK');
  connection.query('INSERT INTO ' + table + ' (content) VALUES(?)', [content], function (err, _result) {
    console.log('INSERT OK');
    assert.ifError(err);
    result = _result;
    connection.query('SELECT * FROM ' + table + ' WHERE id = ' + result.insertId, function (err, _result2) {
      result2 = _result2;
      connection.end();
    });
  });
});

process.on('exit', function () {
  assert.equal(result2[0].id, String(result.insertId));
  assert.equal(result2[0].content.toString(), content.toString());
});


@@ -76,24 +76,11 @@
 ion(
-%7Bdebug: true%7D
 );%0A
+
 var 
@@ -598,32 +598,33 @@
 _allowed_packet=
+1
 56777216', funct
@@ -723,16 +723,127 @@
 6 OK');%0A
+  connection.query('show variables like max_allowed_packet', function (err, res) %7B%0A    console.log(err, res);%0A%0A
   connec
@@ -1151,16 +1151,16 @@
 esult2;%0A
-
       co
@@ -1182,16 +1182,25 @@
 %0A    %7D);
+%0A%0A    %7D);
 %0A  %7D);%0A%7D

check max_allowed_packet value