use constant VERSION => '2.0';
-our %tables = (); our %tables_id_type = ();
+our (%tables, %tables_id_type, %tables_data_map);
our %views = ();
our %mig = ();
our @sql = ();
# This subrotine is also a good example why using generic driver is not recomended.
# Various SQL db server flavours meta info is def. handled differently and not updated in them.
#
-# $map - In general is binding of an CNF table to its DATA property, header of the DATA instructed property is self column resolving.
-# If assinged to an array the first element must contain the name,
+# $map - The synch binding of an CNF TABLE to its CNF DATA property,
+# a header of the DATA instructed property with a meta _SQL_TABLE_ tag is self column resolving
+# based on ID not requiring this mapping now. To better explain, CNF data can have several data properties,
+# with the map we programatically instruct which on is the right one, per various possible tables?
# @TODO 20231018 - Specifications page to be provided with examples for this.
#
sub initDatabase { my($self, $db, $do_not_auto_synch, $map, $st) = @_;
}
}
}}
+ ###
# By default we automatically data insert synchronize script with database state on every init.
# If set $do_not_auto_synch = 1 we skip that if table is present, empty or not,
# and if has been updated dynamically that is good, what we want. It is of external config. implementation choice.
if($data){
my $data_prp = %$data{$t};
if(!$data_prp && $self->{data}){
- $data_prp = %{$self->{data}}{$t};
+ if(%tables_data_map){
+ $data_prp = %$data{$tables_data_map{$t}};
+ if(!$data_prp){
+ $self->{parser} ->error("Invalid data mapping for table $t -> $tables_data_map{$t}")
+ }
+ }
+ $data_prp = %{$self->{data}}{$t} if !$data_prp;
}
if($data_prp){
my @hdr;
}
$db->commit()
}else{
- $self->{parser}->log("CNFParser-> No data collection is available for $tbl\n");
+ $self->{parser}->log("CNFParser-> No data collection is available or mapped to $tbl\n");
}
}else{
$self->{parser}->log("CNFParser-> No data collection scanned for $tbl\n");
}
return $self->{parser}-> const('$RELEASE_VER');
}
-
+###
sub _connectDB {
my ($user, $pass, $source, $store, $path) = @_;
if($path && ! -e $path){
}
sub createTable { my ($self, $name, $body, $idType) = @_;
+ if($body =~ s/${CNFMeta::_meta('MAP_TO')}/""/sexi){
+ $body =~ m/\s*(\w*)(.*)/gs;
+ $tables_data_map{$name} = $1;
+ $body = $2;
+ }
$tables{$name} = "CREATE TABLE $name(\n$body);";
$tables_id_type{$name} = $idType;
}
$test->case("Test CNFSQL script to data synch and map.");
$cnf = CNFParser->new(undef,{DO_ENABLED=>1,DEBUG=>1,'%LOG'=>{console=>1}});
$cnf->parse(undef,q(
- <<TBL_A<TABLE>
+ <<TBL_A<TABLE> _MAP_TO_ TBL_A_DATA
"name" varchar(28) NOT NULL,
"ID" INTEGER NOT NULL,
PRIMARY KEY ("ID" AUTOINCREMENT)
my $db = CNFSQL::_connectDB('test','test',$central->{DBI_SQL_SOURCE},$central->{DB}.'.db');
$sql = $cnf->SQL();
$sql -> {data } = $sql2->{parser}->data();
- $sql -> initDatabase($db,0,{'TBL_A' => ['TBL_A_DATA','name','ID']});
+ #$sql -> initDatabase($db,0,{'TBL_A' => ['TBL_A_DATA','name','ID']});
+ $sql -> initDatabase($db,0);
#
#
$test->done();