<commit_before>#include <cerrno>
#include <cstring>
#include <iostream>

#include <pqxx/pqxx>

using namespace PGSTD;
using namespace pqxx;

namespace
{

const string Contents = "Large object test contents";

class WriteLargeObject : public transactor<>
{
public:
  explicit WriteLargeObject() : 
    transactor<>("WriteLargeObject")
  {
  }

  void operator()(argument_type &T)
  {
    largeobjectaccess A(T);
    cout << "Writing to large object #" << largeobject(A).id() << endl;

    A.write(Contents);

    char Buf[200];
    const size_t Size = sizeof(Buf) - 1;
    largeobjectaccess::size_type Bytes = A.read(Buf, Size);
    if (Bytes)
      throw logic_error("Could read " + to_string(Bytes) + " bytes "
	                "from large object after writing");

    // Overwrite terminating zero
    largeobjectaccess::size_type Here = A.seek(-1, ios::cur);
    if (Here != largeobjectaccess::size_type(Contents.size()-1))
      throw logic_error("Expected to move back 1 byte to " + 
	                to_string(Contents.size()-1) + ", "
			"ended up at " + to_string(Here));
    A.write("!", 1);
    
    // Now check that we really did
    A.seek(-1, ios::cur);
    if (Here != largeobjectaccess::size_type(Contents.size()-1))
      throw logic_error("Inconsistent seek: ended up at " + to_string(Here));

    char Check;
    Here = A.read(&Check, 1);
    if (Here != 1)
      throw logic_error("Wanted to read back 1 byte, got " + to_string(Here));

    if (Check != '!')
      throw logic_error("Read back '" + to_string(Check) + "', "
	                "expected '!'");

    Here = A.seek(0, ios::beg);
    if (Here != 0)
      throw logic_error("Tried to seek back to beginning of large object, "
	                "ended up at " + to_string(Here));

    Here = A.read(&Check, 1);
    if (Here != 1)
      throw logic_error("Tried to read back 1st byte, got " + 
	                to_string(Here) + " bytes");

    if (Check != Contents[0])
      throw logic_error("Expected large object to begin with '" +
	                to_string(Contents[0]) + "', "
			"found '" + to_string(Check) + "'");

    // Clean up after ourselves
    A.remove(T);
  }

private:<commit_msg>Work around bizarre Visual C++.NET problem<commit_after>#include <cerrno>
#include <cstring>
#include <iostream>

#include <pqxx/pqxx>

using namespace PGSTD;
using namespace pqxx;

namespace
{

const string Contents = "Large object test contents";

class WriteLargeObject : public transactor<>
{
public:
  explicit WriteLargeObject() : 
    transactor<>("WriteLargeObject")
  {
  }

  void operator()(argument_type &T)
  {
    largeobjectaccess A(T);
    cout << "Writing to large object #" << largeobject(A).id() << endl;

    A.write(Contents);

    char Buf[200];
    const size_t Size = sizeof(Buf) - 1;
    largeobjectaccess::size_type Bytes = A.read(Buf, Size);
    if (Bytes)
      throw logic_error("Could read " + to_string(Bytes) + " bytes "
	                "from large object after writing");

    // Overwrite terminating zero
    largeobjectaccess::size_type Here = A.seek(-1, ios::cur);

    // Redundant typedef to work around bug in Visual C++.NET
    typedef largeobjectaccess::size_type loa_size;
    if (Here != loa_size(Contents.size()-1))
      throw logic_error("Expected to move back 1 byte to " + 
	                to_string(Contents.size()-1) + ", "
			"ended up at " + to_string(Here));
    A.write("!", 1);
    
    // Now check that we really did
    A.seek(-1, ios::cur);
    if (Here != loa_size(Contents.size()-1))
      throw logic_error("Inconsistent seek: ended up at " + to_string(Here));

    char Check;
    Here = A.read(&Check, 1);
    if (Here != 1)
      throw logic_error("Wanted to read back 1 byte, got " + to_string(Here));

    if (Check != '!')
      throw logic_error("Read back '" + to_string(Check) + "', "
	                "expected '!'");

    Here = A.seek(0, ios::beg);
    if (Here != 0)
      throw logic_error("Tried to seek back to beginning of large object, "
	                "ended up at " + to_string(Here));

    Here = A.read(&Check, 1);
    if (Here != 1)
      throw logic_error("Tried to read back 1st byte, got " + 
	                to_string(Here) + " bytes");

    if (Check != Contents[0])
      throw logic_error("Expected large object to begin with '" +
	                to_string(Contents[0]) + "', "
			"found '" + to_string(Check) + "'");

    // Clean up after ourselves
    A.remove(T);
  }

private:
{'fraction_non_alphanumeric': 0.1433699798070451, 'fraction_numerical': 0.009423378954453668, 'mean_word_length': 2.7525252525252526, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4299076', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1402, 'n_words': 392}