Ignore:
Timestamp:
2018-10-24T20:41:01+13:00 (5 years ago)
Author:
ak19
Message:

Previous commit message meant to be: string names of strings shared by GS SQL Plugin and Plugout have been changed in strings.properties to indicate both modules used them. Current commit: Some tidying up the new GreenstoneSQLPlugin and moving the select statements from there into gssql.pm.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm

    r32537 r32538  
    124124}
    125125
    126 # need to store current section
    127 #sub xml_start_tag {
    128 #    my $self = shift(@_);
    129 #    $self->SUPER::xml_start_tag(@_);
    130 #    $self->{'stored_section'} = $self->{'section'};
    131 #    $self->{'stored_section_level'} = $self->{'section_level'}
    132 #}
    133126
    134127# TODO Q: Why are there 3 passes when we're only indexing at doc and section level (2 passes)?
     
    145138
    146139    my $oid = $self->{'doc_oid'}; # we stored current doc's OID during sub read()
    147     print $outhandle "@@@@@@ OID of document (meta|text) to be read in from DB: $oid\n"
     140    print $outhandle "==== OID of document (meta|text) to be read in from DB: $oid\n"
    148141    if $self->{'verbosity'} > 1;
    149142
    150 #    print STDERR "@@@@ section: |" . $self->{'stored_section'} . "|\n";
    151 #    print STDERR "@@@@ section_level: " . $self->{'stored_section_level'} . "\n";
    152    
    153     # for now, we have access to doc_obj (until just before super::close_document() terminates)
    154     #$self->{'doc_obj'}->set_OID($oid);
     143   
     144    # For now, we have access to doc_obj (until just before super::close_document() terminates)
     145   
     146    $self->{'doc_obj'}->set_OID($oid); # complex method. Is this necessary, since we just want to write meta and txt for the docobj to index?
     147   
     148    # checking that complicated looking method set_OID() hasn't modified oid
     149    if($oid ne $self->{'doc_obj'}->get_OID()) {
     150    print STDERR "@@@@ WARNING: OID after setting on doc_obj = " . $self->{'doc_obj'}->get_OID() . " and is not the same as original OID $oid from docsqloid.xml filename\n";
     151    }
     152
    155153   
    156154    # TODO: This function is called on a per doc.xml file basis
     
    164162    # read in meta for the collection (i.e. select * from <col>_metadata table
    165163
    166     my $meta_table = $gs_sql->get_metadata_table_name();
    167    
     164    my $sth = $gs_sql->select_from_metatable_matching_docid($oid); 
     165    print $outhandle "### stmt: ".$sth->{'Statement'}."\n" if $self->{'verbosity'} > 1;
     166
     167    print $outhandle "----------SQL DB contains meta-----------\n" if $self->{'verbosity'} > 1;
    168168    # https://www.effectiveperlprogramming.com/2010/07/set-custom-dbi-error-handlers/
    169     my $sth = $gs_sql->get_db_handle()->prepare(qq{SELECT * FROM $meta_table WHERE did = ?});
    170     print $outhandle "### stmt: ".$sth->{'Statement'}."\n"
    171         if $self->{'verbosity'} > 1;
    172     $sth->execute( $oid ); # will print msg on fail
    173 
    174     print $outhandle "----------SQL DB contains meta-----------\n" if $self->{'verbosity'} > 1;
    175169    while( my @row = $sth->fetchrow_array() ) {     
    176170        #print $outhandle "row: @row\n";
     
    196190   
    197191   
    198     my $sth = $gs_sql->get_db_handle()->prepare(qq{SELECT * FROM $fulltxt_table WHERE did = ?});
    199     print $outhandle "### stmt: ".$sth->{'Statement'}."\n"
    200         if $self->{'verbosity'} > 1;
    201     $sth->execute( $oid ); # will print msg on fail
     192    my $sth = $gs_sql->select_from_texttable_matching_docid($oid);
     193    print $outhandle "### stmt: ".$sth->{'Statement'}."\n" if $self->{'verbosity'} > 1;
    202194
    203195    print $outhandle "----------\nSQL DB contains txt entries for-----------\n"
     
    226218
    227219
    228 # TODO: only want to work with sql db if buildcol.pl
     220# TODO: only want to work with sql db if buildcol.pl. Unfortunately, also runs on import.pl
    229221# call init() not begin() because there can be multiple plugin passes
    230222# and init() should be called before all passes:
    231223# one for doc level and another for section level indexing
     224# This way, we can connect to the SQL database once per buildcol run.
    232225sub init {
    233226    my ($self) = shift (@_);
     
    290283}
    291284
    292 
     285# This method also runs on import.pl if gs_sql has a value. But we just want to run it on buildcol
    293286# Call deinit() not end() because there can be multiple plugin passes:
    294287# one for doc level and another for section level indexing
    295288# and deinit() should be called before all passes
     289# This way, we can close the SQL database once per buildcol run.
    296290sub deinit {
    297291    my ($self) = shift (@_);
Note: See TracChangeset for help on using the changeset viewer.