<commit_before>package SQL::Struct::Connector;
use strict;
use warnings;
use base 'DBIx::Connector';

sub _connect {
	my ($self, @args) = @_;
	for (1 .. 30) {
		my $dbh = eval { $self->SUPER::_connect(@args) };
		return $dbh if $dbh;
		sleep 1;
	}
	die $@ if $@;
	die "no connect";
}

package SQL::Struct;
use strict;
use warnings;
use Carp;
use SQL::Abstract;
use Digest::MD5;
use Data::Dumper;
use base 'Exporter';

our $VERSION = '0.01';

our @EXPORT = qw{
  one_row
  all_rows
  new_row
};
our $conn;
our $update_on_destroy     = 1;
our $connector_module      = 'SQL::Struct::Connector';
our $connector_constructor = 'new';
our $connector_args        = [];
our $connector_driver;
our %driver_pk_insert;

BEGIN {
	%driver_pk_insert = (
		Pg => sub {
			my ($table, $pk_bind, $pk_return) = @_;
			(   $pk_bind
				? qq|
						($pk_bind) =
							\$_->selectrow_array('insert into $table (' . join (", ", keys \%insert) . ") values ("
								. join(",", ('?') x scalar(keys \%insert) ) . ") $pk_return", undef, values \%insert)
|
				: qq|
						\$_->do('insert into $table (' . join (", ", keys \%insert) . ") values ("
								. join(",", ('?') x scalar(keys \%insert) ) . ")", undef, values \%insert)
|
			  ) . qq|
						or croak {
							result  => 'SQLERR',
							message => 'error '.\$_->errstr.' inserting into table $table'
						};
|;
		},
		mysql => sub {
			my ($table, $pk_bind, $pk_return) = @_;
			qq|
						\$_->do('insert into $table (' . join (", ", keys \%insert) . ") values ("
								. join(",", ('?') x scalar(keys \%insert) ) . ")", undef, values \%insert)
						or croak {
							result  => 'SQLERR',
							message => 'error '.\$_->errstr.' inserting into table $table'
						};
|
			  . (
				$pk_bind
				? qq|\t\t\t\t\t\t$pk_bind = $_->last_insert_id(undef, undef, undef, undef);\n|
				: ''
			  );
		}
	);
}

sub check_package_scalar {
	my ($package, $scalar) = @_;
	no strict 'refs';
	my $pr = \%{$package . '::'};
	my $er = $$pr{$scalar};
	return unless $er;
	defined *{$er}{'SCALAR'};
}

sub import {
	my ($class, @args) = @_;
	my $defconn = 0;
	for (my $i = 0 ; $i < @args ; ++$i) {
		if ($args[$i] eq 'connector') {
			(undef, $connector_module) = splice @args, $i, 2;
			--$i;
			if (not $defconn and check_package_scalar($connector_module, 'conn')) {
				*conn = \${$connector_module . '::conn'};
			}
		} elsif ($args[$i] eq 'constructor') {
			(undef, $connector_constructor) = splice @args, $i, 2;
			--$i;
		} elsif ($args[$i] eq 'args') {
			(undef, $connector_args) = splice @args, $i, 2;
			--$i;
		} elsif ($args[$i] eq 'connector_object') {
			$defconn = 1;
			my (undef, $connector_object) = splice @args, $i, 2;
			--$i;
			*conn = \${$connector_object};
		}
	}
	$class->export_to_level(1, @args);
}

sub _connected {
	$conn;
}

sub _not_yet_connected {
	if (not $conn) {
		my ($dsn, $user, $password) = @_;
		if ($dsn && $dsn !~ /^dbi:/) {
			$dsn = "dbi:Pg:dbname=$dsn";
		}
		my $connect_attrs = {
			AutoCommit          => 1,
			PrintError          => 0,
			AutoInactiveDestroy => 1,
			RaiseError          => 1,<commit_msg>fixed @EXPORT_OK<commit_after>package SQL::Struct::Connector;
use strict;
use warnings;
use base 'DBIx::Connector';

sub _connect {
	my ($self, @args) = @_;
	for (1 .. 30) {
		my $dbh = eval { $self->SUPER::_connect(@args) };
		return $dbh if $dbh;
		sleep 1;
	}
	die $@ if $@;
	die "no connect";
}

package SQL::Struct;
use strict;
use warnings;
use Carp;
use SQL::Abstract;
use Digest::MD5;
use Data::Dumper;
use base 'Exporter';

our $VERSION = '0.01';

our @EXPORT = qw{
  one_row
  all_rows
  new_row
};

our @EXPORT_OK = qw{
  $conn
};

our $conn;
our $update_on_destroy     = 1;
our $connector_module      = 'SQL::Struct::Connector';
our $connector_constructor = 'new';
our $connector_args        = [];
our $connector_driver;
our %driver_pk_insert;

%driver_pk_insert = (
	Pg => sub {
		my ($table, $pk_bind, $pk_return) = @_;
		(   $pk_bind
			? qq|
						($pk_bind) =
							\$_->selectrow_array('insert into $table (' . join (", ", keys \%insert) . ") values ("
								. join(",", ('?') x scalar(keys \%insert) ) . ") $pk_return", undef, values \%insert)
|
			: qq|
						\$_->do('insert into $table (' . join (", ", keys \%insert) . ") values ("
								. join(",", ('?') x scalar(keys \%insert) ) . ")", undef, values \%insert)
|
		  ) . qq|
						or croak {
							result  => 'SQLERR',
							message => 'error '.\$_->errstr.' inserting into table $table'
						};
|;
	},
	mysql => sub {
		my ($table, $pk_bind, $pk_return) = @_;
		qq|
						\$_->do('insert into $table (' . join (", ", keys \%insert) . ") values ("
								. join(",", ('?') x scalar(keys \%insert) ) . ")", undef, values \%insert)
						or croak {
							result  => 'SQLERR',
							message => 'error '.\$_->errstr.' inserting into table $table'
						};
|
		  . (
			$pk_bind
			? qq|\t\t\t\t\t\t$pk_bind = $_->last_insert_id(undef, undef, undef, undef);\n|
			: ''
		  );
	}
);

sub check_package_scalar {
	my ($package, $scalar) = @_;
	no strict 'refs';
	my $pr = \%{$package . '::'};
	my $er = $$pr{$scalar};
	return unless $er;
	defined *{$er}{'SCALAR'};
}

sub import {
	my $defconn = 0;
	for (my $i = 1 ; $i < @_ ; ++$i) {
		if ($_[$i] eq 'connector') {
			(undef, $connector_module) = splice @_, $i, 2;
			--$i;
			if (not $defconn and check_package_scalar($connector_module, 'conn')) {
				*conn = \${$connector_module . '::conn'};
			}
		} elsif ($_[$i] eq 'constructor') {
			(undef, $connector_constructor) = splice @_, $i, 2;
			--$i;
		} elsif ($_[$i] eq 'args') {
			(undef, $connector_args) = splice @_, $i, 2;
			--$i;
		} elsif ($_[$i] eq 'connector_object') {
			$defconn = 1;
			my (undef, $connector_object) = splice @_, $i, 2;
			--$i;
			*conn = \${$connector_object};
		}
	}
	$_[0]->export_to_level(1, @_);
}

sub _connected {
	$conn;
}

sub _not_yet_connected {
	if (not $conn) {
		my ($dsn, $user, $password) = @_;
		if ($dsn && $dsn !~ /^dbi:/) {
			$dsn = "dbi:Pg:dbname=$dsn";
		}
		my $connect_attrs = {
			AutoCommit          => 1,
			PrintError          => 0,
			AutoInactiveDestroy => 1,
			RaiseError          => 1,
{'fraction_non_alphanumeric': 0.21318717277486912, 'fraction_numerical': 0.007035340314136125, 'mean_word_length': 2.7664818237831175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '7011945', 'n_tokens_mistral': 2793, 'n_tokens_neox': 2395, 'n_words': 570}