File: copy_to_psql

package info (click to toggle)
openser 1.1.0-9etch1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 9,828 kB
  • ctags: 11,809
  • sloc: ansic: 120,528; sh: 5,249; yacc: 1,716; makefile: 1,261; php: 656; perl: 205; sql: 190
file content (133 lines) | stat: -rw-r--r-- 2,862 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
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
129
130
131
132
133
#!/usr/local/bin/perl
#
# $Id: copy_to_psql,v 1.1.1.1 2005/06/13 16:47:43 bogdan_iancu Exp $
#
# sc: ser control; tool for maintaining ser's databases
#
# History:
# --------
# 2003-04-07 initial attempt at file copy script
#
# To-DO:
# -----
# - generalization for other than mysql databases
# - front-end to updating administrative mysql password would
#   be a convenient thing to have
#
# quick and dirty script to copy 0.8.10 mysql location and subscription table
# out and create insert statements for postgres new CVS version table
# this script only copies 2 tables, location and subscriber.
# you may need to modify the open(FD,"sdfdsf") line to suite your needs.
#

$q = <<EOT;
select
	user_id, domain, contact, expires, q, callid, cseq,
	last_modified
  from
	location
EOT
if(!open(FD,"/usr/local/mysql/bin/mysql --batch ser -e \"$q\"|"))
{
	die("can't open mysql process");
}

print "/* insert location tuples */\n";
print "delete from location;\n";
while(<FD>)
{
	chop;
	($user_id,$domain,$contact,$expires,$q,$callid,$cseq, $lastmodified)=
		split("\t");

	$i = <<EOT;
	insert
	  into
	  	location
	     (
	     	username,
		domain,
		contact,
		expires,
		q,
		callid,
		cseq,
		last_modified,
		replicate,
		state
	     )
	values
	     (
	     	'$user_id',
		'$domain',
		'$contact',
		'$expires',
		$q,
		'$callid',
		$cseq,
		'$expires',
		null,
		null
	      );
EOT

	$i =~ s/\n/ /g;
	$i =~ s/\t+/ /g;
	$i =~ s/^\s+//;
	$i =~ s/\s+$//;
	print "$i\n";
}
$q = <<EOT;
select
	phplib_id, user_id, password, first_name, last_name, phone,
	email_address, datetime_created, datetime_modified, confirmation,
	flag, sendnotification, greeting, ha1, domain, ha1b, perms,
	allow_find, timezone
  from
	subscriber
EOT
if(!open(FD,"/usr/local/mysql/bin/mysql --batch ser -e \"$q\"|"))
{
	die("can't open mysql process");
}

print "/* insert subscriber tuples */\n";
print "delete from subscriber;\n";
while(<FD>)
{
	chop;
	( $phplib_id, $user_id, $password, $first_name, $last_name,
	  $phone, $email_address, $datetime_created, $datetime_modified,
	  $confirmation, $flag, $sendnotification, $greeting, $ha1,
	  $domain, $ha1b, $perms, $allow_find, $timezone) =
		split("\t");

	$i = <<EOT;
	insert
	  into
	  	subscriber
	     (
		phplib_id, username, password, first_name,
		last_name, phone, email_address, datetime_created,
		datetime_modified, confirmation, flag,
		sendnotification, greeting, ha1, domain,
		ha1b, perms, allow_find, timezone
	     )
	values
	     (
		'$phplib_id', '$user_id', '$password', '$first_name',
		'$last_name', '$phone', '$email_address', '$datetime_created',
		'$datetime_created', '$confirmation', '$flag',
		'$sendnotification', '$greeting', '$ha1', '$domain',
		'$ha1b', '$perms', '$allow_find', '$timezone'
	      );
EOT

	$i =~ s/\n/ /g;
	$i =~ s/\t+/ /g;
	$i =~ s/^\s+//;
	$i =~ s/\s+$//;
	print "$i\n";
}

exit 0;