package AXRecord; # Our libraries use lib 'C:\Users\Jay\Desktop\SBS DEV\CODE\perl\Utilities'; use AXControl; use AXSQL; use Moose; use DBI; # Attributes has 'Name' => (is => 'rw', isa => 'Str', required => 1); has 'Fields' => (is => 'ro', isa => 'Hash'); has 'FieldCount' => (is => 'ro', isa => 'Num'); has 'Changed' => (is=>'rw', isa => 'Boolean'); has 'Where' => (is => 'rw', isa => 'Str'); has 'ControlObject' => (is => 'rw', isa => 'Object', required => 1); has 'Keys' => (is => 'rw', isa=>'Array'); # Contains a single record sub BUILD # Constructor { my $self; $self = shift; if (defined $self->Where) { $self->Select(); } } # Insert the record sub Insert { } #Delete using the keys in the record sub Delete { } #Update using the keys and values in the record sub Update { } #Save the record sub Save { } sub Select { my ($SQLStr, $Cnt, $sql, @Values, $self, $Col, @Flds, $i); $self = shift; $SQLStr = "SELECT * FROM " . $self->Name . ' ' . $self->Where; $sql = AXSQL->new(ControlObject => $self->ControlObject, SQLString => $SQLStr); #construct a hash using the metadata and the data from the actual table $self->Fields = {}; @Values = $sql->Fetch(); #Get field Names $sql = AXSQL->new(ControlObject => $self->ControlObject, SQLString => "show fields from '" . $self->Name . "'"); @Flds = $sql->fetch(); # Construct the hash for ($i..$#Flds) { $self->Fields{$Flds[$i]} = $Values[$i]; } $self->Keys = (); $sql = AXSQL->new(ControlObject => $self->ControlObject, SQLString => "SELECT column_name FROM information_schema.`key_column_usage` WHERE table_name = '" . $self->name . "' order by ordinal_position"); while (($Col) = $sql.fetch()) { push $self->Keys, $Col; } $Cnt = $self->Fields; $self->FieldCount = $Cnt; $self->Changed = -1; }