summaryrefslogtreecommitdiffstats
path: root/config-db/testConfDB.pl
blob: 69216e9ca6ea7a4f97a819507d7f1ace369f8dd5 (plain) (blame)
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
#! /usr/bin/perl

# add the folder this script lives in to perl's search path for modules:
use FindBin;
use lib $FindBin::Bin;

use ODLX::Basics;
use ODLX::ConfigDB qw(:access :manipulation);

odlxInit();

my $odlxDB = connectConfigDB();

my @systems;
foreach my $id (1..10) {
	push @systems, {
		'name' => "name of $id",
		'descr' => "descr of $id",
	};
}
addSystem($odlxDB, \@systems);

removeSystem($odlxDB, [1,3,5,7,9,11,13,15,17,19] );

changeSystem($odlxDB, [ 2 ], [ { 'name' => 'new name of 2'} ] );

changeSystem($odlxDB, 4, { 'id' => 114, 'name' => 'id should still be 4'} );

my $metaDB = $odlxDB->{'meta-db'};
my $colDescrs = [
	'id:pk',
	'name:s.30',
	'descr:s.1024',
	'counter:i',
	'hidden:b',
	'dropped1:b',
	'dropped2:b',
];
my $initialVals = [
	{
		'name' => '123456789012345678901234567890xxx',
		'descr' => 'descr-value-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
		'counter' => 34567,
		'hidden' => 1,
		'dropped1' => 0,
		'dropped2' => 1,
	},
	{
		'name' => 'name',
		'descr' => q[from_äöüß#'"$...\to_here],
		'counter' => -1,
		'hidden' => 0,
		'dropped1' => 1,
		'dropped2' => 0,
	},
];


$metaDB->schemaAddTable('test', $colDescrs, $initialVals);

$metaDB->schemaRenameTable('test', 'test2', $colDescrs);

push @$colDescrs, 'added:s.20';
push @$colDescrs, 'added2:s.20';
$metaDB->schemaAddColumns('test2',
						  ['added:s.20', 'added2:b'],
						  [{'added' => 'added'}, {'added2' => '1'}],
						  $colDescrs);

my @rows = $metaDB->_doSelect("SELECT * FROM test2");
foreach my $row (@rows) {
	foreach my $r (keys %$row) {
		print "$r = $row->{$r}\n";
	}
}

$colDescrs = [grep {$_ !~ m[dropped]} @$colDescrs];
$metaDB->schemaDropColumns('test2', ['dropped1', 'dropped2'], $colDescrs);


$colDescrs = [
	map {
		if ($_ =~ m[counter]) {
			"count:i";
		} elsif ($_ =~ m[descr]) {
			"description:s.30";
		} else {
			$_
		}
	} @$colDescrs
];
$metaDB->schemaChangeColumns('test2',
							 { 'counter' => 'count:i',
							   'descr' => 'description:s.30' },
							 $colDescrs);

my @rows = $metaDB->_doSelect("SELECT * FROM test2");
foreach my $row (@rows) {
	foreach my $r (keys %$row) {
		print "$r = $row->{$r}\n";
	}
}

# $metaDB->schemaDropTable('test2');

disconnectConfigDB($odlxDB);