-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjson-Sqlrun-connect.pl
More file actions
executable file
·91 lines (74 loc) · 1.69 KB
/
json-Sqlrun-connect.pl
File metadata and controls
executable file
·91 lines (74 loc) · 1.69 KB
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
86
87
88
89
90
#!/usr/bin/env perl
use strict;
use warnings;
# part of Perl core as of 5.14.0
# 2.273 required as 2.271 does not work here
# do not know about 2.272
use JSON::PP 2.273 ;
use Data::Dumper;
use DBI;
use lib 'lib';
use Sqlrun::Connect;
use lib 'lib';
use Sqlrun;
use Sqlrun::Connect;
use Sqlrun::Timer;
use Sqlrun::File;
use 5.14.0;
# simulate setup in sqlrun.pl
my $driver='Oracle';
my $host='';
my $port='';
my $options='';
my $db='js01';
my $username='scott';
my $password='tiger';
my $oraSessionMode = '';
my $raiseError=1;
my $printError=0;
my $autoCommit=0;
my $driverConfigFile = 'SQL/driver-config.json';
# for postgres
#$driver='Pg';
#$host='ubuntu-20-pg02';
#$port=5432;
#$db='postgres';
#$username='benchmark';
#$password='grok';
# this should match exactly to all possible keys in driver-config.json
my %connectSetup = (
'connectParms' => {
'db' => $db,
'username' => $username,
'password' => $password,
'port' => $port,
'host' => $host,
'options' => $options
},
'dbhAttributes' => {
'RaiseError' => $raiseError,
'PrintError' => $printError,
'AutoCommit' => $autoCommit,
'ora_session_mode' => $oraSessionMode,
},
# these will be populated from the config file
'connectCode' => '',
);
my $connection = new Sqlrun::Connect (
DRIVER => $driver,
SETUP => \%connectSetup,
DRIVERCONFIGFILE => $driverConfigFile,
);
#print 'main::Connect: ' . Dumper($connection);
my $dbh = $connection->connect;
# oracle
my $sql = "select 'this is oracle' from dual";
# postgres
#$sql = "select 'this is PostgreSQL'";
my $sth = $dbh->prepare($sql);
$sth->execute;
my @ary = $sth->fetchrow_array;
print "test: $ary[0]\n";
$sth->finish;
$dbh->disconnect;
print Dumper(\%connectSetup) . "\n";