line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FileMaker::XML::Database; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Net::FileMaker::XML::Database::VERSION = '0.064'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7475
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
7
|
1
|
|
|
1
|
|
42
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
592
|
use Net::FileMaker::XML::ResultSet; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Carp; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use base qw(Net::FileMaker::XML); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Particular methods have specific parameters that are optional, but need to be |
14
|
|
|
|
|
|
|
# validated to mitigate sending bad parameters to the server. |
15
|
|
|
|
|
|
|
my $acceptable_params = { |
16
|
|
|
|
|
|
|
'find' => '-recid|-lop|-op|-max|-skip|-sortorder|-sortfield|-script|-script\.prefind|-script\.presort', |
17
|
|
|
|
|
|
|
'findall' => '-recid|-lop|-op|-max|-skip|-sortorder|-sortfield|-script|-script\.prefind|-script\.presort', |
18
|
|
|
|
|
|
|
'findany' => '-recid|-lop|-op|-max|-skip|-sortorder|-sortfield|-script|-script\.prefind|-script\.presort', |
19
|
|
|
|
|
|
|
'delete' => '-db|-lay|-recid|-script', |
20
|
|
|
|
|
|
|
'dup' => '-db|-lay|-recid|-script', |
21
|
|
|
|
|
|
|
'edit' => '-db|-lay|-recid|-modid|-script', |
22
|
|
|
|
|
|
|
'new' => '-db|-lay|-script' |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Net::FileMaker::XML::Database |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 SYNOPSIS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
This module handles all the tasks with XML data. Don't call this module |
32
|
|
|
|
|
|
|
directly, instead use L. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use Net::FileMaker::XML; |
35
|
|
|
|
|
|
|
my $fm = Net::FileMaker::XML->new(host => $host); |
36
|
|
|
|
|
|
|
my $db = $fm->database(db => $db, user => $user, pass => $pass); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $layouts = $db->layoutnames; |
39
|
|
|
|
|
|
|
my $scripts = $db->scriptnames; |
40
|
|
|
|
|
|
|
my $records = $db->findall( layout => $layout, params => { '-max' => '10'}); |
41
|
|
|
|
|
|
|
my $records = $db->findany( layout => $layout, params => { '-skip' => '10'}); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new |
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
my($class, %args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $self = { |
52
|
|
|
|
|
|
|
host => $args{host}, |
53
|
|
|
|
|
|
|
db => $args{db}, |
54
|
|
|
|
|
|
|
user => $args{user}, |
55
|
|
|
|
|
|
|
pass => $args{pass}, |
56
|
|
|
|
|
|
|
resultset => '/fmi/xml/fmresultset.xml', |
57
|
|
|
|
|
|
|
ua => LWP::UserAgent->new, |
58
|
|
|
|
|
|
|
xml => XML::Twig->new, |
59
|
|
|
|
|
|
|
uri => URI->new($args{host}), |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
bless $self , $class; |
63
|
|
|
|
|
|
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 layoutnames |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns an arrayref containing layouts accessible for the respective database. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub layoutnames |
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
my $self = shift; |
75
|
|
|
|
|
|
|
my $xml = $self->_request( |
76
|
|
|
|
|
|
|
user => $self->{user}, |
77
|
|
|
|
|
|
|
pass => $self->{pass}, |
78
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
79
|
|
|
|
|
|
|
query => '-layoutnames', |
80
|
|
|
|
|
|
|
params => { '-db' => $self->{db} } |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return $self->_compose_arrayref('LAYOUT_NAME', $xml); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 scriptnames |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns an arrayref containing scripts accessible for the respective database. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub scriptnames |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
my $xml = $self->_request( |
97
|
|
|
|
|
|
|
user => $self->{user}, |
98
|
|
|
|
|
|
|
pass => $self->{pass}, |
99
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
100
|
|
|
|
|
|
|
query => '-scriptnames', |
101
|
|
|
|
|
|
|
params => { '-db' => $self->{db} } |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return $self->_compose_arrayref('SCRIPT_NAME', $xml); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 find(layout => $layout, params => { parameters }) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns a L for a specific database and layout. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub find |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
my ($self, %args) = @_; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $params = { |
119
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
120
|
|
|
|
|
|
|
'-db' => $self->{db} |
121
|
|
|
|
|
|
|
}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$params = $self->_assert_params( |
124
|
|
|
|
|
|
|
type => 'find', |
125
|
|
|
|
|
|
|
def_params => $params, |
126
|
|
|
|
|
|
|
params => $args{params}, |
127
|
|
|
|
|
|
|
acceptable_params => $acceptable_params, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $xml = $self->_request( |
131
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
132
|
|
|
|
|
|
|
user => $self->{user}, |
133
|
|
|
|
|
|
|
pass => $self->{pass}, |
134
|
|
|
|
|
|
|
query => '-find', |
135
|
|
|
|
|
|
|
params => $params |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
return Net::FileMaker::XML::ResultSet->new(rs => $xml , db => $self); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 findall(layout => $layout, params => { parameters }, nocheck => 1) |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Returns a L of all rows on a specific database |
145
|
|
|
|
|
|
|
and layout. C is an optional argument that will skip checking of |
146
|
|
|
|
|
|
|
parameters if set to 1. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub findall |
151
|
|
|
|
|
|
|
{ |
152
|
|
|
|
|
|
|
my ($self, %args) = @_; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $params = { |
155
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
156
|
|
|
|
|
|
|
'-db' => $self->{db} |
157
|
|
|
|
|
|
|
}; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
$params = $self->_assert_params( |
160
|
|
|
|
|
|
|
type => 'findall', |
161
|
|
|
|
|
|
|
def_params => $params, |
162
|
|
|
|
|
|
|
params => $args{params}, |
163
|
|
|
|
|
|
|
acceptable_params => $acceptable_params |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my $xml = $self->_request( |
167
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
168
|
|
|
|
|
|
|
user => $self->{user}, |
169
|
|
|
|
|
|
|
pass => $self->{pass}, |
170
|
|
|
|
|
|
|
query => '-findall', |
171
|
|
|
|
|
|
|
params => $params |
172
|
|
|
|
|
|
|
); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
return Net::FileMaker::XML::ResultSet->new(rs => $xml , db => $self); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 findany(layout => $layout, params => { parameters }, nocheck => 1) |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Returns a L of random rows on a specific |
180
|
|
|
|
|
|
|
database and layout. C is an optional argument that will skip checking |
181
|
|
|
|
|
|
|
of parameters if set to 1. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub findany |
186
|
|
|
|
|
|
|
{ |
187
|
|
|
|
|
|
|
my ($self, %args) = @_; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
my $params = { |
190
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
191
|
|
|
|
|
|
|
'-db' => $self->{db} |
192
|
|
|
|
|
|
|
}; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$params = $self->_assert_params( |
195
|
|
|
|
|
|
|
type => 'findany', |
196
|
|
|
|
|
|
|
def_params => $params, |
197
|
|
|
|
|
|
|
params => $args{params}, |
198
|
|
|
|
|
|
|
acceptable_params => $acceptable_params, |
199
|
|
|
|
|
|
|
); |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $xml = $self->_request( |
202
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
203
|
|
|
|
|
|
|
user => $self->{user}, |
204
|
|
|
|
|
|
|
pass => $self->{pass}, |
205
|
|
|
|
|
|
|
query => '-findany', |
206
|
|
|
|
|
|
|
params => $params |
207
|
|
|
|
|
|
|
); |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
return Net::FileMaker::XML::ResultSet->new(rs => $xml , db => $self); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 edit(layout => $layout , recid => $recid , params => { params }) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Updates the row with the fieldname/value pairs passed to params. |
217
|
|
|
|
|
|
|
Returns a L object. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
#TODO: add tests to /t/01_xml |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub edit |
224
|
|
|
|
|
|
|
{ |
225
|
|
|
|
|
|
|
my ($self, %args) = @_; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my $params = { |
228
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
229
|
|
|
|
|
|
|
'-db' => $self->{db} |
230
|
|
|
|
|
|
|
}; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# just to make the recid param more visible than putting it into the params |
233
|
|
|
|
|
|
|
croak 'recid must be defined' if(! defined $args{recid}); |
234
|
|
|
|
|
|
|
$params->{'-recid'} = $args{recid}; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
$params = $self->_assert_params( |
237
|
|
|
|
|
|
|
type => 'edit', |
238
|
|
|
|
|
|
|
def_params => $params, |
239
|
|
|
|
|
|
|
params => $args{params}, |
240
|
|
|
|
|
|
|
acceptable_params => $acceptable_params |
241
|
|
|
|
|
|
|
); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
my $xml = $self->_request( |
244
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
245
|
|
|
|
|
|
|
user => $self->{user}, |
246
|
|
|
|
|
|
|
pass => $self->{pass}, |
247
|
|
|
|
|
|
|
query => '-edit', |
248
|
|
|
|
|
|
|
params => $params |
249
|
|
|
|
|
|
|
); |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
return Net::FileMaker::XML::ResultSet->new(rs => $xml , db => $self); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 remove(layout => $layout , recid => $recid , params => { params }) |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Deletes the record with that specific record id and returns a |
257
|
|
|
|
|
|
|
L object. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub remove |
262
|
|
|
|
|
|
|
{ |
263
|
|
|
|
|
|
|
my ($self, %args) = @_; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
my $params = { |
266
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
267
|
|
|
|
|
|
|
'-db' => $self->{db} |
268
|
|
|
|
|
|
|
}; |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
# just to make the recid param more visible than putting it into the params |
271
|
|
|
|
|
|
|
croak 'recid must be defined' if(! defined $args{recid}); |
272
|
|
|
|
|
|
|
$params->{'-recid'} = $args{recid}; |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
$params = $self->_assert_params( |
275
|
|
|
|
|
|
|
type => 'delete', |
276
|
|
|
|
|
|
|
def_params => $params, |
277
|
|
|
|
|
|
|
params => $args{params}, |
278
|
|
|
|
|
|
|
acceptable_params => $acceptable_params |
279
|
|
|
|
|
|
|
); |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
my $xml = $self->_request( |
282
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
283
|
|
|
|
|
|
|
user => $self->{user}, |
284
|
|
|
|
|
|
|
pass => $self->{pass}, |
285
|
|
|
|
|
|
|
query => '-delete', |
286
|
|
|
|
|
|
|
params => $params |
287
|
|
|
|
|
|
|
); |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
return Net::FileMaker::XML::ResultSet->new(rs => $xml , db => $self); |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head2 insert(layout => $layout , recid => $recid , params => { params }) |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
Creates a new record and populates that record with the fieldname/value pairs passed to params. |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
Returns an L object. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
sub insert |
303
|
|
|
|
|
|
|
{ |
304
|
|
|
|
|
|
|
my ($self, %args) = @_; |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
my $params = { |
307
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
308
|
|
|
|
|
|
|
'-db' => $self->{db} |
309
|
|
|
|
|
|
|
}; |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
$params = $self->_assert_params( |
312
|
|
|
|
|
|
|
type => 'new', |
313
|
|
|
|
|
|
|
def_params => $params, |
314
|
|
|
|
|
|
|
params => $args{params}, |
315
|
|
|
|
|
|
|
acceptable_params => $acceptable_params |
316
|
|
|
|
|
|
|
); |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
my $xml = $self->_request( |
319
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
320
|
|
|
|
|
|
|
user => $self->{user}, |
321
|
|
|
|
|
|
|
pass => $self->{pass}, |
322
|
|
|
|
|
|
|
query => '-new', |
323
|
|
|
|
|
|
|
params => $params |
324
|
|
|
|
|
|
|
); |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
return Net::FileMaker::XML::ResultSet->new(rs => $xml , db => $self); |
327
|
|
|
|
|
|
|
} |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=head2 total_rows(layout => $layout) |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
Returns a scalar with the total rows for a given layout. |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=cut |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
sub total_rows |
338
|
|
|
|
|
|
|
{ |
339
|
|
|
|
|
|
|
my($self, %args) = @_; |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
# Just do a findall with 1 record and parse the result. This might break on an empty database. |
342
|
|
|
|
|
|
|
my $xml = $self->_request( |
343
|
|
|
|
|
|
|
user => $self->{user}, |
344
|
|
|
|
|
|
|
pass => $self->{pass}, |
345
|
|
|
|
|
|
|
resultset => $self->{resultset}, |
346
|
|
|
|
|
|
|
params => { |
347
|
|
|
|
|
|
|
'-db' => $self->{db}, |
348
|
|
|
|
|
|
|
'-lay' => $args{layout}, |
349
|
|
|
|
|
|
|
'-max' => '1' |
350
|
|
|
|
|
|
|
}, |
351
|
|
|
|
|
|
|
query => '-findall' |
352
|
|
|
|
|
|
|
); |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
return $xml; |
355
|
|
|
|
|
|
|
} |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
1; # End of Net::FileMaker::XML::Database; |
359
|
|
|
|
|
|
|
|