File: cod_fetch

package info (click to toggle)
cod-tools 3.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 154,792 kB
  • sloc: perl: 57,588; sh: 36,842; ansic: 6,402; xml: 1,982; yacc: 1,117; makefile: 727; python: 166
file content (85 lines) | stat: -rwxr-xr-x 2,569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2021-04-28 19:35:53 +0300 (Wed, 28 Apr 2021) $
#$Revision: 8738 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.7.0/scripts/cod_fetch $
#------------------------------------------------------------------------------
#*
#* Query COD server using the Perl DBD::mysql interface.
#*
#* USAGE:
#*   $0 --options "search text"
#*   $0 --options -- "--search text"
#**

use strict;
use warnings;
use DBD::mysql;
use COD::SOptions qw( getOptions );
use COD::SUsage qw( usage options );
use COD::ErrorHandler qw( report_message );
use COD::ToolsVersion qw( get_version_string );

my $opt_enabled = 1;
#* OPTIONS:
#*   --
#*                     Notify the end of command line options. Only positional
#*                     parameters are accepted after this option. This option
#*                     is mandatory if the positional parameters are prefixed
#*                     with a minus sign ('-').
#*   --help, --usage
#*                     Output a short usage message (this message) and exit.
#*   --version
#*                     Output version information and exit.
#**
@ARGV = getOptions(
    '--'             => sub { if ($opt_enabled) { $opt_enabled = 0 } },
    '--options'      => sub { if ($opt_enabled) { options; exit } },
    '--help,--usage' => sub { if ($opt_enabled) { usage; exit } },
    '--version'      => sub {
                                if ($opt_enabled) {
                                    print get_version_string(), "\n"; exit
                                }
                            }
);

if ( @ARGV > 1 ) {
    report_message( {
        'program'   => $0,
        'err_level' => 'WARNING',
        'message'   => 'more than one positional parameters was provided -- '
                     . "only the first one ('$ARGV[0]') will be used"
    }, 0 );
}

my $database = "cod";
my $hostname = "cod.ibt.lt";

my $query_text = $ARGV[0];

my $dsn = "DBI:mysql:database=$database;host=$hostname";

my $dbh = DBI->connect( $dsn, "cod_reader" );

my $query = sprintf("SELECT file FROM data WHERE text like %s",
                    $dbh->quote( "%" . $query_text . "%" ));

print "query = >>>$query<<<\n";

my $sth = $dbh->prepare( $query );

$sth->execute();

use COD::Serialise qw( serialiseRef );

while (my $row = $sth->fetchrow_hashref()) {
    serialiseRef( $row );
}

$sth->finish();

$dbh->disconnect();