Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 90bb521a

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 90bb521a25eeb37c5bbae1ff68c38e6c142b6e6b
  • Vorgänger b49ec094
  • Nachfolger 66c08b64

Alle Vorkommen von dbdriver, sid, Oracle entfernt

...und gegen das hardcodierte Werte für PostgreSQL ersetzt.

Unterschiede anzeigen:

SL/CA.pm
182 182

  
183 183
  my $sortorder = join ', ',
184 184
    $form->sort_columns(qw(transdate reference description));
185
  my $false = ($myconfig->{dbdriver} eq 'Pg') ? "FALSE" : q|'0'|;
186

  
187
  # Oracle workaround, use ordinal positions
188
  my %ordinal = (transdate   => 4,
189
                 reference   => 2,
190
                 description => 3);
191
  map { $sortorder =~ s/$_/$ordinal{$_}/ } keys %ordinal;
192 185

  
193 186
  my ($null, $department_id) = split(/--/, $form->{department});
194 187
  my ($dpt_where, $dpt_join, @department_values);
......
272 265
    # get all transactions
273 266
    $query =
274 267
      qq|SELECT a.id, a.reference, a.description, ac.transdate, ac.chart_id, | .
275
      qq|  $false AS invoice, ac.amount, 'gl' as module, | .
268
      qq|  FALSE AS invoice, ac.amount, 'gl' as module, | .
276 269
      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = (SELECT tax_id FROM taxkeys WHERE taxkey_id = ac.taxkey AND taxkeys.startdate <= ac.transdate ORDER BY taxkeys.startdate DESC LIMIT 1)) AS taxinfo, ac.source || ' ' || ac.memo AS memo § .
277 270
      qq|FROM acc_trans ac, gl a | .
278 271
      $dpt_join .
SL/Controller/Admin.pm
504 504
}
505 505

  
506 506
sub apply_dbupgrade_scripts {
507
  return SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(1);
507
  return SL::DBUpgrade2->new(form => $::form, auth => 1)->apply_admin_dbupgrade_scripts(1);
508 508
}
509 509

  
510 510
sub authenticate_root {
SL/DBUpgrade2.pm
27 27

  
28 28
  $params{path_suffix} ||= '';
29 29
  $params{schema}      ||= '';
30
  $params{path}          = "sql/" . $params{dbdriver} . "-upgrade2" . $params{path_suffix};
30
  $params{path}          = "sql/Pg-upgrade2" . $params{path_suffix};
31 31

  
32 32
  map { $self->{$_} = $params{$_} } keys %params;
33 33

  
......
243 243

  
244 244
  my ($self, $dbh, $filename, $version_or_control, $db_charset) = @_;
245 245

  
246
  my %form_values = map { $_ => $::form->{$_} } qw(dbconnect dbdefault dbdriver dbhost dbmbkiviunstable dbname dboptions dbpasswd dbport dbupdate dbuser login template_object version);
246
  my %form_values = map { $_ => $::form->{$_} } qw(dbconnect dbdefault dbhost dbmbkiviunstable dbname dboptions dbpasswd dbport dbupdate dbuser login template_object version);
247 247

  
248 248
  $dbh->begin_work;
249 249

  
......
302 302

  
303 303
  local *SQLDIR;
304 304

  
305
  my $dbdriver = $self->{dbdriver};
306
  opendir SQLDIR, "sql/${dbdriver}-upgrade" || error("", "sql/${dbdriver}-upgrade: $!");
307
  my @upgradescripts = grep /${dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR;
305
  opendir SQLDIR, "sql/Pg-upgrade" || error("", "sql/Pg-upgrade: $!");
306
  my @upgradescripts = grep /Pg-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR;
308 307
  closedir SQLDIR;
309 308

  
310 309
  return ($#upgradescripts > -1);
......
374 373
    $::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}");
375 374
    print $self->{form}->parse_html_template("dbupgrade/upgrade_message2", $control);
376 375

  
377
    $self->process_file($dbh, "sql/$self->{dbdriver}-upgrade2-auth/$control->{file}", $control, $db_charset);
376
    $self->process_file($dbh, "sql/Pg-upgrade2-auth/$control->{file}", $control, $db_charset);
378 377
  }
379 378

  
380 379
  print $self->{form}->parse_html_template("dbupgrade/footer", { is_admin => 1 }) if $called_from_admin;
......
461 460
  # Apply outstanding updates to the authentication database
462 461
  my $scripts = SL::DBUpgrade2->new(
463 462
    form     => $::form,
464
    dbdriver => 'Pg',
465 463
    auth     => 1
466 464
  );
467 465
  $scripts->apply_admin_dbupgrade_scripts(1);
......
469 467
  # Apply updates to a user database
470 468
  my $scripts = SL::DBUpgrade2->new(
471 469
    form     => $::form,
472
    dbdriver => $::form->{dbdriver},
473 470
    auth     => 1
474 471
  );
475 472
  User->dbupdate2($form, $scripts->parse_dbupdate_controls);
......
603 600

  
604 601
C<SL::Form> object to use. Required.
605 602

  
606
=item dbdriver
607

  
608
Name of the database driver. Currently only C<Pg> for PostgreSQL is
609
supported.
610

  
611 603
=item auth
612 604

  
613 605
Optional parameter defaulting to 0. If trueish then the scripts read
SL/DO.pm
672 672
    delete $form->{id};
673 673
  }
674 674

  
675
  my %oid = ('Pg'     => 'oid',
676
             'Oracle' => 'rowid');
677

  
678 675
  # retrieve individual items
679 676
  # this query looks up all information about the items
680 677
  # stuff different from the whole will not be overwritten, but saved with a suffix.
......
693 690
       LEFT JOIN project pr ON (doi.project_id = pr.id)
694 691
       LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
695 692
       WHERE doi.delivery_order_id IN ($do_ids_placeholders)
696
       ORDER BY doi.$oid{$myconfig->{dbdriver}}|;
693
       ORDER BY doi.oid|;
697 694

  
698 695
  $form->{form_details} = selectall_hashref_query($form, $dbh, $query, @do_ids);
699 696

  
......
752 749
  my $partsgroup;
753 750
  my $position = 0;
754 751

  
755
  my %oid = ('Pg'     => 'oid',
756
             'Oracle' => 'rowid');
757

  
758 752
  my (@project_ids, %projectnumbers, %projectdescriptions);
759 753

  
760 754
  push(@project_ids, $form->{"globalproject_id"}) if ($form->{"globalproject_id"});
......
869 863
      my $sortorder = "";
870 864
      if ($form->{groupitems}) {
871 865
        $sortorder =
872
          qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|;
866
          qq|ORDER BY pg.partsgroup, a.oid|;
873 867
      } else {
874
        $sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|;
868
        $sortorder = qq|ORDER BY a.oid|;
875 869
      }
876 870

  
877 871
      do_statement($form, $h_pg, $q_pg, conv_i($form->{"id_$i"}));
SL/GL.pm
354 354
    }
355 355
  }
356 356

  
357
  my $false = ($myconfig->{dbdriver} eq 'Pg') ? "FALSE" : q|'0'|;
358

  
359 357
  my %sort_columns =  (
360 358
    'id'           => [ qw(id)                   ],
361 359
    'transdate'    => [ qw(transdate id)         ],
......
385 383

  
386 384
  $query =
387 385
    qq|SELECT
388
        ac.acc_trans_id, g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
386
        ac.acc_trans_id, g.id, 'gl' AS type, FALSE AS invoice, g.reference, ac.taxkey, c.link,
389 387
        g.description, ac.transdate, ac.gldate, ac.source, ac.trans_id,
390 388
        ac.amount, c.accno, g.notes, t.chart_id,
391 389
        CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
SL/IS.pm
114 114
  my $i;
115 115
  my @partsgroup = ();
116 116
  my $partsgroup;
117
  my %oid = ('Pg'     => 'oid',
118
             'Oracle' => 'rowid');
119 117

  
120 118
  # sort items by partsgroup
121 119
  for $i (1 .. $form->{rowcount}) {
......
336 334
        my $sortorder = "";
337 335
        if ($form->{groupitems}) {
338 336
          $sortorder =
339
            qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|;
337
            qq|ORDER BY pg.partsgroup, a.oid|;
340 338
        } else {
341
          $sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|;
339
          $sortorder = qq|ORDER BY a.oid|;
342 340
        }
343 341

  
344 342
        $query =
SL/OE.pm
853 853
      map { $form->{$_} =~ s/ +$//g } qw(printed emailed queued);
854 854
    }    # if !@ids
855 855

  
856
    my %oid = ('Pg'     => 'oid',
857
               'Oracle' => 'rowid');
858

  
859 856
    my $transdate = $form->{transdate} ? $dbh->quote($form->{transdate}) : "current_date";
860 857

  
861 858
    $form->{taxzone_id} = 0 unless ($form->{taxzone_id});
......
887 884
      ($form->{id}
888 885
       ? qq|WHERE o.trans_id = ?|
889 886
       : qq|WHERE o.trans_id IN (| . join(", ", map("?", @ids)) . qq|)|) .
890
      qq|ORDER BY o.$oid{$myconfig->{dbdriver}}|;
887
      qq|ORDER BY o.oid|;
891 888

  
892 889
    @ids = $form->{id} ? ($form->{id}) : @ids;
893 890
    $sth = prepare_execute_query($form, $dbh, $query, @values);
......
1055 1052
  my $tax_rate;
1056 1053
  my $taxamount;
1057 1054

  
1058

  
1059
  my %oid = ('Pg'     => 'oid',
1060
             'Oracle' => 'rowid');
1061

  
1062 1055
  my (@project_ids, %projectnumbers, %projectdescriptions);
1063 1056

  
1064 1057
  push(@project_ids, $form->{"globalproject_id"}) if ($form->{"globalproject_id"});
......
1277 1270
        # get parts and push them onto the stack
1278 1271
        my $sortorder = "";
1279 1272
        if ($form->{groupitems}) {
1280
          $sortorder = qq|ORDER BY pg.partsgroup, a.$oid{$myconfig->{dbdriver}}|;
1273
          $sortorder = qq|ORDER BY pg.partsgroup, a.oid|;
1281 1274
        } else {
1282
          $sortorder = qq|ORDER BY a.$oid{$myconfig->{dbdriver}}|;
1275
          $sortorder = qq|ORDER BY a.oid|;
1283 1276
        }
1284 1277

  
1285 1278
        $query = qq|SELECT p.partnumber, p.description, p.unit, a.qty, | .
SL/RC.pm
93 93
  ($form->{beginningbalance}, $form->{category}) =
94 94
    selectrow_query($form, $dbh, $query, @values);
95 95

  
96
  my %oid = ('Pg'     => 'ac.acc_trans_id',
97
             'Oracle' => 'ac.rowid');
98 96
  @values = ();
99 97
  $query =
100 98
    qq|SELECT c.name, ac.source, ac.transdate, ac.cleared, | .
101 99
    qq|  ac.fx_transaction, ac.amount, a.id, | .
102
    qq|  $oid{$myconfig->{dbdriver}} AS oid | .
100
    qq|  ac.acc_trans_id AS oid | .
103 101
    qq|FROM customer c, acc_trans ac, ar a, chart ch | .
104 102
    qq|WHERE c.id = a.customer_id | .
105 103
    qq|  AND ac.cleared = '0' | .
......
123 121

  
124 122
    qq|SELECT v.name, ac.source, ac.transdate, ac.cleared, | .
125 123
    qq|  ac.fx_transaction, ac.amount, a.id, | .
126
    qq|  $oid{$myconfig->{dbdriver}} AS oid | .
124
    qq|  ac.acc_trans_id AS oid | .
127 125
    qq|FROM vendor v, acc_trans ac, ap a, chart ch | .
128 126
    qq|WHERE v.id = a.vendor_id | .
129 127
    qq|  AND ac.cleared = '0' | .
......
148 146

  
149 147
    qq|SELECT g.description, ac.source, ac.transdate, ac.cleared, | .
150 148
    qq|  ac.fx_transaction, ac.amount, g.id, | .
151
    qq|  $oid{$myconfig->{dbdriver}} AS oid | .
149
    qq|  ac.acc_trans_id AS oid | .
152 150
    qq|FROM gl g, acc_trans ac, chart ch | .
153 151
    qq|WHERE g.id = ac.trans_id | .
154 152
    qq|  AND ac.cleared = '0' | .
......
186 184
  my $dbh = $form->dbconnect($myconfig);
187 185

  
188 186
  my ($query, $i);
189
  my %oid = ('Pg'     => 'acc_trans_id',
190
             'Oracle' => 'rowid');
191 187

  
192 188
  # clear flags
193 189
  for $i (1 .. $form->{rowcount}) {
194 190
    if ($form->{"cleared_$i"}) {
195 191
      $query =
196 192
        qq|UPDATE acc_trans SET cleared = '1' | .
197
        qq|WHERE $oid{$myconfig->{dbdriver}} = ?|;
193
        qq|WHERE acc_trans_id = ?|;
198 194
      do_query($form, $dbh, $query, $form->{"oid_$i"});
199 195

  
200 196
      # clear fx_transaction
201 197
      if ($form->{"fxoid_$i"}) {
202 198
        $query =
203 199
          qq|UPDATE acc_trans SET cleared = '1' | .
204
          qq|WHERE $oid{$myconfig->{dbdriver}} = ?|;
200
          qq|WHERE acc_trans_id = ?|;
205 201
        do_query($form, $dbh, $query, $form->{"fxoid_$i"});
206 202
      }
207 203
    }
SL/User.pm
93 93

  
94 94
sub login {
95 95
  my ($self, $form) = @_;
96
  our $sid;
97 96

  
98 97
  return -3 if !$self->{login} || !$::auth->client;
99 98

  
......
103 102
  my $dbh = $form->dbconnect_noauto;
104 103

  
105 104
  # we got a connection, check the version
106
  my $query = qq|SELECT version FROM defaults|;
107
  my $sth   = $dbh->prepare($query);
108
  $sth->execute || $form->dberror($query);
109

  
110
  my ($dbversion) = $sth->fetchrow_array;
111
  $sth->finish;
105
  my ($dbversion) = $dbh->selectrow_array(qq|SELECT version FROM defaults|);
112 106

  
113 107
  $self->create_employee_entry($form, $dbh, \%myconfig);
114 108

  
115 109
  $self->create_schema_info_table($form, $dbh);
116 110

  
117 111
  # Auth DB upgrades available?
118
  my $dbupdater_auth = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg', auth => 1)->parse_dbupdate_controls;
112
  my $dbupdater_auth = SL::DBUpgrade2->new(form => $form, auth => 1)->parse_dbupdate_controls;
119 113
  return -3 if $dbupdater_auth->unapplied_upgrade_scripts($::auth->dbconnect);
120 114

  
121
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $myconfig{dbdriver})->parse_dbupdate_controls;
115
  my $dbupdater = SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls;
122 116

  
123 117
  $form->{$_} = $::auth->client->{$_} for qw(dbname dbhost dbport dbuser dbpasswd);
124 118
  $form->{$_} = $myconfig{$_}         for qw(dateformat);
......
155 149

  
156 150
  $self->dbupdate($form);
157 151
  $self->dbupdate2($form, $dbupdater);
158
  SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(0);
152
  SL::DBUpgrade2->new(form => $::form, auth => 1)->apply_admin_dbupgrade_scripts(0);
159 153

  
160 154
  close($fh);
161 155

  
......
173 167
  my ($form, $db) = @_;
174 168

  
175 169
  my %dboptions = (
176
        'Pg' => { 'yy-mm-dd'   => 'set DateStyle to \'ISO\'',
177
                  'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
178
                  'mm/dd/yy'   => 'set DateStyle to \'SQL, US\'',
179
                  'dd/mm/yy'   => 'set DateStyle to \'SQL, EUROPEAN\'',
180
                  'dd.mm.yy'   => 'set DateStyle to \'GERMAN\''
181
        },
182
        'Oracle' => {
183
          'yy-mm-dd'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YY-MM-DD\'',
184
          'yyyy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'',
185
          'mm/dd/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM/DD/YY\'',
186
          'dd/mm/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD/MM/YY\'',
187
          'dd.mm.yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD.MM.YY\'',
188
        });
189

  
190
  $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
191

  
192
  if ($form->{dbdriver} eq 'Pg') {
193
    $form->{dbconnect} = "dbi:Pg:dbname=$db";
194
  }
195

  
196
  if ($form->{dbdriver} eq 'Oracle') {
197
    $form->{dbconnect} = "dbi:Oracle:sid=$form->{sid}";
198
  }
199

  
200
  if ($form->{dbhost}) {
201
    $form->{dbconnect} .= ";host=$form->{dbhost}";
202
  }
203
  if ($form->{dbport}) {
204
    $form->{dbconnect} .= ";port=$form->{dbport}";
205
  }
206

  
207
  $main::lxdebug->leave_sub();
208
}
209

  
210
sub dbdrivers {
211
  $main::lxdebug->enter_sub();
170
    'yy-mm-dd'   => 'set DateStyle to \'ISO\'',
171
    'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
172
    'mm/dd/yy'   => 'set DateStyle to \'SQL, US\'',
173
    'dd/mm/yy'   => 'set DateStyle to \'SQL, EUROPEAN\'',
174
    'dd.mm.yy'   => 'set DateStyle to \'GERMAN\''
175
  );
212 176

  
213
  my @drivers = DBI->available_drivers();
177
  $form->{dboptions} = $dboptions{ $form->{dateformat} };
178
  $form->{dbconnect} = "dbi:Pg:dbname=${db};host=" . ($form->{dbhost} || 'localhost') . ";port=" . ($form->{dbport} || 5432);
214 179

  
215 180
  $main::lxdebug->leave_sub();
216

  
217
  return (grep { /(Pg|Oracle)/ } @drivers);
218 181
}
219 182

  
220 183
sub dbsources {
......
226 189
  my ($sth, $query);
227 190

  
228 191
  $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
229
  $form->{sid} = $form->{dbdefault};
230 192
  &dbconnect_vars($form, $form->{dbdefault});
231 193

  
232 194
  my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
233 195
    or $form->dberror;
234 196

  
235
  if ($form->{dbdriver} eq 'Pg') {
236
    $query =
237
      qq|SELECT datname FROM pg_database | .
238
      qq|WHERE NOT datname IN ('template0', 'template1')|;
239
    $sth = $dbh->prepare($query);
240
    $sth->execute() || $form->dberror($query);
241

  
242
    while (my ($db) = $sth->fetchrow_array) {
243

  
244
      if ($form->{only_acc_db}) {
245

  
246
        next if ($db =~ /^template/);
247

  
248
        &dbconnect_vars($form, $db);
249
        my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
250
          or $form->dberror;
251

  
252
        $query =
253
          qq|SELECT tablename FROM pg_tables | .
254
          qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
255
        my $sth = $dbh->prepare($query);
256
        $sth->execute($form->{dbuser}) ||
257
          $form->dberror($query . " ($form->{dbuser})");
258

  
259
        if ($sth->fetchrow_array) {
260
          push(@dbsources, $db);
261
        }
262
        $sth->finish;
263
        $dbh->disconnect;
264
        next;
265
      }
266
      push(@dbsources, $db);
267
    }
268
  }
197
  $query =
198
    qq|SELECT datname FROM pg_database | .
199
    qq|WHERE NOT datname IN ('template0', 'template1')|;
200
  $sth = $dbh->prepare($query);
201
  $sth->execute() || $form->dberror($query);
202

  
203
  while (my ($db) = $sth->fetchrow_array) {
269 204

  
270
  if ($form->{dbdriver} eq 'Oracle') {
271 205
    if ($form->{only_acc_db}) {
272
      $query =
273
        qq|SELECT owner FROM dba_objects | .
274
        qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
275
    } else {
276
      $query = qq|SELECT username FROM dba_users|;
277
    }
278 206

  
279
    $sth = $dbh->prepare($query);
280
    $sth->execute || $form->dberror($query);
207
      next if ($db =~ /^template/);
208

  
209
      &dbconnect_vars($form, $db);
210
      my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
211
        or $form->dberror;
281 212

  
282
    while (my ($db) = $sth->fetchrow_array) {
283
      push(@dbsources, $db);
213
      $query =
214
        qq|SELECT tablename FROM pg_tables | .
215
        qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
216
      my $sth = $dbh->prepare($query);
217
      $sth->execute($form->{dbuser}) ||
218
        $form->dberror($query . " ($form->{dbuser})");
219

  
220
      if ($sth->fetchrow_array) {
221
        push(@dbsources, $db);
222
      }
223
      $sth->finish;
224
      $dbh->disconnect;
225
      next;
284 226
    }
227
    push(@dbsources, $db);
285 228
  }
286 229

  
287 230
  $sth->finish;
......
316 259

  
317 260
  my ($self, $form) = @_;
318 261

  
319
  $form->{sid} = $form->{dbdefault};
320 262
  &dbconnect_vars($form, $form->{dbdefault});
321 263
  my $dbh =
322 264
    SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
323 265
    or $form->dberror;
324 266
  $form->{db} =~ s/\"//g;
325
  my %dbcreate = (
326
    'Pg'     => qq|CREATE DATABASE "$form->{db}"|,
327
    'Oracle' =>
328
    qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS | .
329
    qq|TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
330
  );
331 267

  
332
  my %dboptions = (
333
    'Pg' => [],
334
  );
268
  my @dboptions;
335 269

  
336
  push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"}))
337
    if ($form->{"encoding"});
270
  push @dboptions, "ENCODING = " . $dbh->quote($form->{"encoding"}) if $form->{"encoding"};
338 271
  if ($form->{"dbdefault"}) {
339 272
    my $dbdefault = $form->{"dbdefault"};
340 273
    $dbdefault =~ s/[^a-zA-Z0-9_\-]//g;
341
    push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault");
274
    push @dboptions, "TEMPLATE = $dbdefault";
342 275
  }
343 276

  
344
  my $query = $dbcreate{$form->{dbdriver}};
345
  $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}});
277
  my $query = qq|CREATE DATABASE "$form->{db}"|;
278
  $query   .= " WITH " . join(" ", @dboptions) if @dboptions;
346 279

  
347 280
  # Ignore errors if the database exists.
348 281
  $dbh->do($query);
349 282

  
350
  if ($form->{dbdriver} eq 'Oracle') {
351
    $query = qq|GRANT CONNECT, RESOURCE TO "$form->{db}"|;
352
    do_query($form, $dbh, $query);
353
  }
354 283
  $dbh->disconnect;
355 284

  
356
  # setup variables for the new database
357
  if ($form->{dbdriver} eq 'Oracle') {
358
    $form->{dbuser}   = $form->{db};
359
    $form->{dbpasswd} = $form->{db};
360
  }
361

  
362 285
  &dbconnect_vars($form, $form->{db});
363 286

  
364 287
  $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
......
367 290
  my $db_charset = $Common::db_encoding_to_charset{$form->{encoding}};
368 291
  $db_charset ||= Common::DEFAULT_CHARSET;
369 292

  
370
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver});
293
  my $dbupdater = SL::DBUpgrade2->new(form => $form);
371 294
  # create the tables
372 295
  $dbupdater->process_query($dbh, "sql/lx-office.sql", undef, $db_charset);
373 296

  
......
395 318

  
396 319
  my ($self, $form) = @_;
397 320
  $form->{db} =~ s/\"//g;
398
  my %dbdelete = ('Pg'     => qq|DROP DATABASE "$form->{db}"|,
399
                  'Oracle' => qq|DROP USER "$form->{db}" CASCADE|);
400 321

  
401
  $form->{sid} = $form->{dbdefault};
402 322
  &dbconnect_vars($form, $form->{dbdefault});
403 323
  my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
404 324
    or $form->dberror;
405
  my $query = $dbdelete{$form->{dbdriver}};
325
  my $query = qq|DROP DATABASE "$form->{db}"|;
406 326
  do_query($form, $dbh, $query);
407 327

  
408 328
  $dbh->disconnect;
......
436 356
  my ($self, $form) = @_;
437 357

  
438 358
  my %members   = $main::auth->read_all_users();
439
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls;
359
  my $dbupdater = SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls;
440 360

  
441 361
  my ($query, $sth, %dbs_needing_updates);
442 362

  
......
545 465

  
546 466
  local *SQLDIR;
547 467

  
548
  $form->{sid} = $form->{dbdefault};
549

  
550 468
  my @upgradescripts = ();
551 469
  my $query;
552 470
  my $rc = -2;
......
554 472
  if ($form->{dbupdate}) {
555 473

  
556 474
    # read update scripts into memory
557
    opendir(SQLDIR, "sql/" . $form->{dbdriver} . "-upgrade")
558
      or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
475
    opendir(SQLDIR, "sql/Pg-upgrade")
476
      or &error("", "sql/Pg-upgrade : $!");
559 477
    @upgradescripts =
560 478
      sort(cmp_script_version
561
           grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/,
479
           grep(/Pg-upgrade-.*?\.(sql|pl)$/,
562 480
                readdir(SQLDIR)));
563 481
    closedir(SQLDIR);
564 482
  }
......
566 484
  my $db_charset = $::lx_office_conf{system}->{dbcharset};
567 485
  $db_charset ||= Common::DEFAULT_CHARSET;
568 486

  
569
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver});
487
  my $dbupdater = SL::DBUpgrade2->new(form => $form);
570 488

  
571 489
  foreach my $db (split(/ /, $form->{dbupdate})) {
572 490

  
......
591 509

  
592 510
    foreach my $upgradescript (@upgradescripts) {
593 511
      my $a = $upgradescript;
594
      $a =~ s/^\Q$form->{dbdriver}\E-upgrade-|\.(sql|pl)$//g;
512
      $a =~ s/^Pg-upgrade-|\.(sql|pl)$//g;
595 513

  
596 514
      my ($mindb, $maxdb) = split /-/, $a;
597 515
      my $str_maxdb = $maxdb;
......
605 523

  
606 524
      # apply upgrade
607 525
      $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $upgradescript");
608
      $dbupdater->process_file($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb, $db_charset);
526
      $dbupdater->process_file($dbh, "sql/Pg-upgrade/$upgradescript", $str_maxdb, $db_charset);
609 527

  
610 528
      $version = $maxdb;
611 529

  
......
626 544

  
627 545
  my ($self, $form, $dbupdater) = @_;
628 546

  
629
  $form->{sid} = $form->{dbdefault};
630

  
631 547
  my $rc         = -2;
632 548
  my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET;
633 549

  
......
655 571
      $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}");
656 572
      print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
657 573

  
658
      $dbupdater->process_file($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade2/$control->{file}", $control, $db_charset);
574
      $dbupdater->process_file($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset);
659 575
    }
660 576

  
661 577
    $rc = 0;
bin/mozilla/admin.pl
101 101
      call_sub($locale->findsub($form->{action}));
102 102
    }
103 103
  } else {
104
    # if there are no drivers bail out
105
    $form->error($locale->text('No Database Drivers available!'))
106
      unless (User->dbdrivers);
107

  
108 104
    adminlogin();
109 105
  }
110 106
  $::lxdebug->leave_sub;
......
143 139

  
144 140
sub pg_database_administration {
145 141
  my $form = $main::form;
146

  
147
  $form->{dbdriver} = 'Pg';
148 142
  dbselect_source();
149

  
150 143
}
151 144

  
152 145
sub dbselect_source {
......
171 164
  my $form   = $main::form;
172 165
  my $locale = $main::locale;
173 166

  
174
  $form->{dbdriver} = 'Pg';
175 167
  User::dbconnect_vars($form, $form->{dbname});
176 168

  
177 169
  my $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd});
......
225 217
    restore_form($saved_form);
226 218

  
227 219
    %::myconfig = ();
228
    map { $form->{$_} = $::myconfig{$_} = $form->{"${_}_${i}"} } qw(dbname dbdriver dbhost dbport dbuser dbpasswd);
220
    map { $form->{$_} = $::myconfig{$_} = $form->{"${_}_${i}"} } qw(dbname dbhost dbport dbuser dbpasswd);
229 221

  
230 222
    print $form->parse_html_template("admin/dbupgrade_header");
231 223

  
......
233 225
    $form->{$form->{dbname}} = 1;
234 226

  
235 227
    User->dbupdate($form);
236
    User->dbupdate2($form, SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls);
228
    User->dbupdate2($form, SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls);
237 229

  
238 230
    print $form->parse_html_template("admin/dbupgrade_footer");
239 231
  }
scripts/dbupgrade2_tool.pl
360 360
    print "Applying upgrade $control->{file}\n";
361 361

  
362 362
    if ($file_type eq "sql") {
363
      $dbupgrader->process_query($dbh, "sql/$form->{dbdriver}-upgrade2/$control->{file}", $control, $db_charset);
363
      $dbupgrader->process_query($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset);
364 364
    } else {
365
      $dbupgrader->process_perl_script($dbh, "sql/$form->{dbdriver}-upgrade2/$control->{file}", $control, $db_charset);
365
      $dbupgrader->process_perl_script($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset);
366 366
    }
367 367
  }
368 368

  
......
499 499

  
500 500
show_help() if ($opt_help);
501 501

  
502
$dbupgrader = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg', auth => $opt_auth_db);
502
$dbupgrader = SL::DBUpgrade2->new(form => $form, auth => $opt_auth_db);
503 503
$controls   = $dbupgrader->parse_dbupdate_controls->{all_controls};
504 504

  
505 505
dump_list()                                 if ($opt_list);
templates/webpages/admin/backup_dataset.html
27 27

  
28 28
  <form name="Form" method="post" action="admin.pl">
29 29

  
30
   <input type="hidden" name="dbdriver" value="Pg">
31 30
   <input type="hidden" name="dbhost" value="[% HTML.escape(dbhost) %]">
32 31
   <input type="hidden" name="dbport" value="[% HTML.escape(dbport) %]">
33 32
   <input type="hidden" name="dbuser" value="[% HTML.escape(dbuser) %]">
templates/webpages/admin/create_dataset.html
83 83
    </tr>
84 84
   </table>
85 85

  
86
   <input type="hidden" name="dbdriver"  value="[% HTML.escape(dbdriver) %]">
87 86
   <input type="hidden" name="dbuser"    value="[% HTML.escape(dbuser) %]">
88 87
   <input type="hidden" name="dbhost"    value="[% HTML.escape(dbhost) %]">
89 88
   <input type="hidden" name="dbport"    value="[% HTML.escape(dbport) %]">
templates/webpages/admin/dbadmin.html
11 11

  
12 12
      <table>
13 13

  
14
       <input type="hidden" name="dbdriver" value="[% HTML.escape(dbdriver) %]">
15

  
16 14
       <tr>
17 15
        <td>
18 16
         <table>
templates/webpages/admin/delete_dataset.html
11 11
   <select name="db">[% FOREACH row = DBSOURCES %]<option>[% HTML.escape(row.name) %]</option>[% END %]</select>
12 12
  </p>
13 13

  
14
  <input type="hidden" name="dbdriver"  value="[% HTML.escape(dbdriver) %]">
15 14
  <input type="hidden" name="dbuser"    value="[% HTML.escape(dbuser) %]">
16 15
  <input type="hidden" name="dbhost"    value="[% HTML.escape(dbhost) %]">
17 16
  <input type="hidden" name="dbport"    value="[% HTML.escape(dbport) %]">
templates/webpages/admin/restore_dataset.html
8 8

  
9 9
 <form name="Form" method="post" action="admin.pl" enctype="multipart/form-data">
10 10

  
11
  <input type="hidden" name="dbdriver" value="Pg">
12 11
  <input type="hidden" name="dbhost" value="[% HTML.escape(dbhost) %]">
13 12
  <input type="hidden" name="dbport" value="[% HTML.escape(dbport) %]">
14 13
  <input type="hidden" name="dbuser" value="[% HTML.escape(dbuser) %]">
templates/webpages/admin/update_dataset.html
14 14
   <table>
15 15
    <tr>
16 16
     <th class="listtop">[% 'Update?' | $T8 %]</th>
17
     <th class="listtop">[% 'Dataset' | $T8 %]</th>
18 17
     <th class="listtop">[% 'Driver' | $T8 %]</th>
19 18
     <th class="listtop">[% 'Host' | $T8 %]</th>
20 19
     <th class="listtop">[% 'Port' | $T8 %]</th>
......
28 27
       <input type="hidden" name="dbname_[% loop.count %]" value="[% HTML.escape(row.dbname) %]">
29 28
       <label for="update_[% loop.count %]">[% HTML.escape(row.dbname) %]</label>
30 29
      </td>
31
      <td><input type="hidden" name="dbdriver_[% loop.count %]" value="Pg">PostgreSQL</td>
32 30
      <td><input type="hidden" name="dbhost_[% loop.count %]" value="[% HTML.escape(row.dbhost) %]">[% HTML.escape(row.dbhost) %]</td>
33 31
      <td><input type="hidden" name="dbport_[% loop.count %]" value="[% HTML.escape(row.dbport) %]">[% HTML.escape(row.dbport) %]</td>
34 32
      <td><input type="hidden" name="dbuser_[% loop.count %]" value="[% HTML.escape(row.dbuser) %]">[% HTML.escape(row.dbuser) %]</td>

Auch abrufbar als: Unified diff