File: dbswitch.pl

package info (click to toggle)
pronto 2.4.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,112 kB
  • ctags: 487
  • sloc: perl: 22,159; makefile: 127; sh: 34; sql: 7
file content (128 lines) | stat: -rwxr-xr-x 3,552 bytes parent folder | download | duplicates (3)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl -w

##############################################################################
#
#	dbswitch.pl	-	This program will copy the contents of one db 
#				backend to another.
#				Call it with dbswitch.pl olddriver newdriver
#
#	Author		-	Steve Kordik <countzero@cyberdeck.org>
#
#
##############################################################################

$olddriver = $ARGV[0];
$newdriver = $ARGV[1];

if (!$olddriver || !$newdriver) {
 print ("Usage: dbswitch.pl olddriver newdriver\n");
 exit;
}


use DBI;
use Gtk;
Gtk->init();
require 'prontolib.pl';
use Pronto::FirstRun;


$prefs{'DatabaseDriver'} = $olddriver;

$olddbh=&open_db_conn;

$prefs{'DatabaseDriver'} = $newdriver;

$conn=&open_db_conn;

&Pronto::FirstRun::create_database();

$sql =   "select id, msgid, boxid, accountid,
          date, sentto, sentfrom, subject, contenttype,
          contentxferencode, mimeversion, precedence,
          approvedby, inreplyto, replyto, listsub,
          listunsub, status, xorigip, cc, bcc, sender,
          returnpath, priority, xmailer, xuidl, xsender,
          localdate, newmsg, replyf, friendly, rreceiptto, score, ref, serverstat
	  from messages";
	  
$query=$olddbh->prepare($sql);
$query->execute();

$sql = "insert into messages (id, msgid, boxid, accountid,
          date, sentto, sentfrom, subject, contenttype,
          contentxferencode, mimeversion, precedence,
          approvedby, inreplyto, replyto, listsub,
          listunsub, status, xorigip, cc, bcc, sender,
          returnpath, priority, xmailer, xuidl, xsender,
          localdate, newmsg, replyf, friendly, rreceiptto, score, ref, serverstat)
	values
	(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$query2=$conn->prepare($sql);
while (@row=$query->fetchrow_array()) {
 $query2->execute(@row);
}

$sql = "select id,uname,friendly,smtp,pop,pport,pass,reply,
	include,dm,def,type,dupecheck  from accounts";

$query=$olddbh->prepare($sql);
$query->execute();

$sql = "insert into accounts (id, uname, friendly, smtp,
          pop, pport, pass, reply, include,
          dm, def,type, dupecheck)
	values
	(?,?,?,?,?,?,?,?,?,?,?,?,?)";
$query2=$conn->prepare($sql);

while (@row=$query->fetchrow_array()) {
 $query2->execute(@row);
}

$sql = "select id,alias,address,public_key,groups from addresses";
$query=$olddbh->prepare($sql);
$query->execute();
$sql = "insert into addresses (id, alias, address, public_key, groups)
      values
	(?,?,?,?,?)";
$query2=$conn->prepare($sql);
while (@row=$query->fetchrow_array()) {
 if (!$row[4]) { $row[4] = " "; }
 $query2->execute(@row);
}

$sql = "select id, name from groups";
$query=$olddbh->prepare($sql);
$query->execute();
$sql = "insert into groups (id, name)
      values
	(?,?)";
$query2=$conn->prepare($sql);
while (@row=$query->fetchrow_array()) {
 $query2->execute(@row);
}


$sql = "select id,name,sibling,parent,query,body from boxlist";
$query=$olddbh->prepare($sql);
$query->execute();
$sql = "insert into boxlist (id, name, sibling, parent, query, body)
	values
	(?,?,?,?,?,?)";
$query2=$conn->prepare($sql);
while (@row=$query->fetchrow_array()) {
	if ($row[0] > 4) {
      	$query2->execute(@row);
	}
}
$sql = "select id,sorder,type,boxid,regex,addr,name,trueregex,count  from filters";
$query=$olddbh->prepare($sql);
$query->execute();
$sql = "insert into filters (id, sorder, type, boxid, regex, addr, name, trueregex, count)
	values
	(?,?,?,?,?,?,?,?,?)";
$query2=$conn->prepare($sql);
while (@row=$query->fetchrow_array()) {
	$query2->execute(@row);
}