[go: up one dir, main page]

Menu

[r110]: / trunk / core / service.cpp  Maximize  Restore  History

Download this file

774 lines (643 with data), 26.7 kB

  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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
///////////////////////////////////////////////////////////////////////////////
//
// File : $Id$
// Subject : IBPP, Service class implementation
//
///////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright 2000-2007 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
//
// The contents of this file are subject to the IBPP License (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
// file which must have been distributed along with this file.
//
// This software, distributed under the License, is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
///////////////////////////////////////////////////////////////////////////////
//
// COMMENTS
// * Tabulations should be set every four characters when editing this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER
#pragma warning(disable: 4786 4996)
#ifndef _DEBUG
#pragma warning(disable: 4702)
#endif
#endif
#include "_ibpp.h"
#ifdef HAS_HDRSTOP
#pragma hdrstop
#endif
using namespace ibpp_internals;
// (((((((( OBJECT INTERFACE IMPLEMENTATION ))))))))
void ServiceImpl::Connect()
{
if (mHandle != 0) return; // Already connected
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mUserName.empty())
throw LogicExceptionImpl("Service::Connect", _("Unspecified user name."));
if (mUserPassword.empty())
throw LogicExceptionImpl("Service::Connect", _("Unspecified user password."));
// Attach to the Service Manager
IBS status(mDriver);
SPB spb(mDriver);
std::string conn;
// Build a SPB based on the properties
spb.Insert(isc_spb_version);
spb.Insert(isc_spb_current_version);
spb.InsertString(isc_spb_user_name, 1, mUserName.c_str());
spb.InsertString(isc_spb_password, 1, mUserPassword.c_str());
if (! mServerName.empty())
{
conn = mServerName;
conn += ":";
}
conn += "service_mgr";
(mDriver->m_service_attach)(status.Self(), (short)conn.size(), (char*)conn.c_str(),
&mHandle, spb.Size(), spb.Self());
if (status.Errors())
{
mHandle = 0; // Should be, but better be sure...
throw SQLExceptionImpl(status, "Service::Connect", _("isc_service_attach failed"));
}
}
void ServiceImpl::Disconnect()
{
if (mHandle == 0) return; // Already disconnected
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
IBS status(mDriver);
// Detach from the service manager
(mDriver->m_service_detach)(status.Self(), &mHandle);
// Set mHandle to 0 now, just in case we need to throw, because Disconnect()
// is called from Service destructor and we want to maintain a coherent state.
mHandle = 0;
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Disconnect", _("isc_service_detach failed"));
}
void ServiceImpl::GetVersion(std::string& version)
{
// Based on a patch provided by Torsten Martinsen (SourceForge 'bullestock')
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::GetVersion", _("Service is not connected."));
IBS status(mDriver);
SPB spb(mDriver);
RB result(mDriver, 250);
spb.Insert(isc_info_svc_server_version);
(mDriver->m_service_query)(status.Self(), &mHandle, 0, 0, 0, spb.Size(), spb.Self(),
result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetVersion", _("isc_service_query failed"));
result.GetString(isc_info_svc_server_version, version);
}
void ServiceImpl::AddUser(const IBPP::User& user)
{
if (mDriver->mGDSVersion >= 60 && mHandle == 0)
throw LogicExceptionImpl("Service::AddUser", _("Service is not connected."));
if (user.username.empty())
throw LogicExceptionImpl("Service::AddUser", _("Username required."));
if (user.password.empty())
throw LogicExceptionImpl("Service::AddUser", _("Password required."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_add_user);
spb.InsertString(isc_spb_sec_username, 2, user.username.c_str());
spb.InsertString(isc_spb_sec_password, 2, user.password.c_str());
if (! user.firstname.empty())
spb.InsertString(isc_spb_sec_firstname, 2, user.firstname.c_str());
if (! user.middlename.empty())
spb.InsertString(isc_spb_sec_middlename, 2, user.middlename.c_str());
if (! user.lastname.empty())
spb.InsertString(isc_spb_sec_lastname, 2, user.lastname.c_str());
if (user.userid != 0)
spb.InsertQuad(isc_spb_sec_userid, (int32_t)user.userid);
if (user.groupid != 0)
spb.InsertQuad(isc_spb_sec_groupid, (int32_t)user.groupid);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::AddUser", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::ModifyUser(const IBPP::User& user)
{
if (mDriver->mGDSVersion >= 60 && mHandle == 0)
throw LogicExceptionImpl("Service::ModifyUser", _("Service is not connected."));
if (user.username.empty())
throw LogicExceptionImpl("Service::ModifyUser", _("Username required."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_modify_user);
spb.InsertString(isc_spb_sec_username, 2, user.username.c_str());
if (! user.password.empty())
spb.InsertString(isc_spb_sec_password, 2, user.password.c_str());
if (! user.firstname.empty())
spb.InsertString(isc_spb_sec_firstname, 2, user.firstname.c_str());
if (! user.middlename.empty())
spb.InsertString(isc_spb_sec_middlename, 2, user.middlename.c_str());
if (! user.lastname.empty())
spb.InsertString(isc_spb_sec_lastname, 2, user.lastname.c_str());
if (user.userid != 0)
spb.InsertQuad(isc_spb_sec_userid, (int32_t)user.userid);
if (user.groupid != 0)
spb.InsertQuad(isc_spb_sec_groupid, (int32_t)user.groupid);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::ModifyUser", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::RemoveUser(const std::string& username)
{
if (mDriver->mGDSVersion >= 60 && mHandle == 0)
throw LogicExceptionImpl("Service::RemoveUser", _("Service is not connected."));
if (username.empty())
throw LogicExceptionImpl("Service::RemoveUser", _("Username required."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_delete_user);
spb.InsertString(isc_spb_sec_username, 2, username.c_str());
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::RemoveUser", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::GetUser(IBPP::User& user)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::GetUser", _("Service is not connected."));
if (user.username.empty())
throw LogicExceptionImpl("Service::GetUser", _("Username required."));
SPB spb(mDriver);
spb.Insert(isc_action_svc_display_user);
spb.InsertString(isc_spb_sec_username, 2, user.username.c_str());
IBS status(mDriver);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetUser", _("isc_service_start failed"));
RB result(mDriver, 8000);
char request[] = {isc_info_svc_get_users};
status.Reset();
(mDriver->m_service_query)(status.Self(), &mHandle, 0, 0, 0,
sizeof(request), request, result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetUser", _("isc_service_query failed"));
char* p = result.Self();
if (*p != isc_info_svc_get_users)
throw SQLExceptionImpl(status, "Service::GetUser", _("isc_service_query returned unexpected answer"));
p += 3; // Skips the 'isc_info_svc_get_users' and its total length
user.clear();
while (*p != isc_info_end)
{
if (*p == isc_spb_sec_userid)
{
user.userid = (uint32_t)(mDriver->m_vax_integer)(p+1, 4);
p += 5;
}
else if (*p == isc_spb_sec_groupid)
{
user.groupid = (uint32_t)(mDriver->m_vax_integer)(p+1, 4);
p += 5;
}
else
{
unsigned short len = (unsigned short)(mDriver->m_vax_integer)(p+1, 2);
switch (*p)
{
case isc_spb_sec_username :
// For each user, this is the first element returned
if (len != 0) user.username.assign(p+3, len);
break;
case isc_spb_sec_password :
if (len != 0) user.password.assign(p+3, len);
break;
case isc_spb_sec_firstname :
if (len != 0) user.firstname.assign(p+3, len);
break;
case isc_spb_sec_middlename :
if (len != 0) user.middlename.assign(p+3, len);
break;
case isc_spb_sec_lastname :
if (len != 0) user.lastname.assign(p+3, len);
break;
}
p += (3 + len);
}
}
}
void ServiceImpl::GetUsers(std::vector<IBPP::User>& users)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::GetUsers", _("Service is not connected."));
SPB spb(mDriver);
spb.Insert(isc_action_svc_display_user);
IBS status(mDriver);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetUsers", _("isc_service_start failed"));
RB result(mDriver, 8000);
char request[] = {isc_info_svc_get_users};
status.Reset();
(mDriver->m_service_query)(status.Self(), &mHandle, 0, 0, 0,
sizeof(request), request, result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetUsers", _("isc_service_query failed"));
users.clear();
char* p = result.Self();
if (*p != isc_info_svc_get_users)
throw SQLExceptionImpl(status, "Service::GetUsers", _("isc_service_query returned unexpected answer"));
p += 3; // Skips the 'isc_info_svc_get_users' and its total length
IBPP::User user;
while (*p != isc_info_end)
{
if (*p == isc_spb_sec_userid)
{
user.userid = (uint32_t)(mDriver->m_vax_integer)(p+1, 4);
p += 5;
}
else if (*p == isc_spb_sec_groupid)
{
user.groupid = (uint32_t)(mDriver->m_vax_integer)(p+1, 4);
p += 5;
}
else
{
unsigned short len = (unsigned short)(mDriver->m_vax_integer)(p+1, 2);
switch (*p)
{
case isc_spb_sec_username :
// For each user, this is the first element returned
if (! user.username.empty()) users.push_back(user); // Flush previous user
user.clear();
if (len != 0) user.username.assign(p+3, len);
break;
case isc_spb_sec_password :
if (len != 0) user.password.assign(p+3, len);
break;
case isc_spb_sec_firstname :
if (len != 0) user.firstname.assign(p+3, len);
break;
case isc_spb_sec_middlename :
if (len != 0) user.middlename.assign(p+3, len);
break;
case isc_spb_sec_lastname :
if (len != 0) user.lastname.assign(p+3, len);
break;
}
p += (3 + len);
}
}
if (! user.username.empty()) users.push_back(user); // Flush last user
}
void ServiceImpl::SetPageBuffers(const std::string& dbfile, int buffers)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::SetPageBuffers", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::SetPageBuffers", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
spb.InsertQuad(isc_spb_prp_page_buffers, buffers);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::SetPageBuffers", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::SetSweepInterval(const std::string& dbfile, int sweep)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::SetSweepInterval", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::SetSweepInterval", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
spb.InsertQuad(isc_spb_prp_sweep_interval, sweep);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::SetSweepInterval", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::SetSyncWrite(const std::string& dbfile, bool sync)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::SetSyncWrite", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::SetSyncWrite", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
if (sync) spb.InsertByte(isc_spb_prp_write_mode, (char)isc_spb_prp_wm_sync);
else spb.InsertByte(isc_spb_prp_write_mode, (char)isc_spb_prp_wm_async);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::SetSyncWrite", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::SetReadOnly(const std::string& dbfile, bool readonly)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::SetReadOnly", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::SetReadOnly", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
if (readonly) spb.InsertByte(isc_spb_prp_access_mode, (char)isc_spb_prp_am_readonly);
else spb.InsertByte(isc_spb_prp_access_mode, (char)isc_spb_prp_am_readwrite);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::SetReadOnly", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::SetReserveSpace(const std::string& dbfile, bool reserve)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::SetReserveSpace", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::SetReserveSpace", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
if (reserve) spb.InsertByte(isc_spb_prp_reserve_space, (char)isc_spb_prp_res);
else spb.InsertByte(isc_spb_prp_reserve_space, (char)isc_spb_prp_res_use_full);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::SetReserveSpace", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::Shutdown(const std::string& dbfile, IBPP::DSM mode, int sectimeout)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::Shutdown", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::Shutdown", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
switch (mode)
{
case IBPP::dsDenyAttach :
spb.InsertQuad(isc_spb_prp_deny_new_attachments, sectimeout);
break;
case IBPP::dsDenyTrans :
spb.InsertQuad(isc_spb_prp_deny_new_transactions, sectimeout);
break;
case IBPP::dsForce :
spb.InsertQuad(isc_spb_prp_shutdown_db, sectimeout);
break;
}
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Shutdown", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::Restart(const std::string& dbfile)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::Restart", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::Restart", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_properties);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
spb.InsertQuad(isc_spb_options, isc_spb_prp_db_online);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Restart", _("isc_service_start failed"));
Wait();
}
void ServiceImpl::Sweep(const std::string& dbfile)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::Sweep", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::Sweep", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_repair);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
spb.InsertQuad(isc_spb_options, isc_spb_rpr_sweep_db);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Sweep", _("isc_service_start failed"));
Wait();
}
//lint -e{655} bit-wise operation uses compatible enum
void ServiceImpl::Repair(const std::string& dbfile, IBPP::RPF flags)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::Repair", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::Repair", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_repair);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
unsigned int mask;
if (flags & IBPP::rpValidateFull) mask = (isc_spb_rpr_full | isc_spb_rpr_validate_db);
else if (flags & IBPP::rpValidatePages) mask = isc_spb_rpr_validate_db;
else if (flags & IBPP::rpMendRecords) mask = isc_spb_rpr_mend_db;
else throw LogicExceptionImpl("Service::Repair",
_("One of rpMendRecords, rpValidatePages, rpValidateFull is required."));
if (flags & IBPP::rpReadOnly) mask |= isc_spb_rpr_check_db;
if (flags & IBPP::rpIgnoreChecksums) mask |= isc_spb_rpr_ignore_checksum;
if (flags & IBPP::rpKillShadows) mask |= isc_spb_rpr_kill_shadows;
spb.InsertQuad(isc_spb_options, mask);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Repair", _("isc_service_start failed"));
Wait();
}
//lint -e{655} bit-wise operation uses compatible enum
void ServiceImpl::StartBackup(const std::string& dbfile,
const std::string& bkfile, IBPP::BRF flags)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::Backup", _("Service is not connected."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::Backup", _("Main database file must be specified."));
if (bkfile.empty())
throw LogicExceptionImpl("Service::Backup", _("Backup file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_backup);
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
spb.InsertString(isc_spb_bkp_file, 2, bkfile.c_str());
if (flags & IBPP::brVerbose) spb.Insert(isc_spb_verbose);
unsigned int mask = 0;
if (flags & IBPP::brIgnoreChecksums) mask |= isc_spb_bkp_ignore_checksums;
if (flags & IBPP::brIgnoreLimbo) mask |= isc_spb_bkp_ignore_limbo;
if (flags & IBPP::brMetadataOnly) mask |= isc_spb_bkp_metadata_only;
if (flags & IBPP::brNoGarbageCollect) mask |= isc_spb_bkp_no_garbage_collect;
if (flags & IBPP::brNonTransportable) mask |= isc_spb_bkp_non_transportable;
if (flags & IBPP::brConvertExtTables) mask |= isc_spb_bkp_convert;
if (mask != 0) spb.InsertQuad(isc_spb_options, mask);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Backup", _("isc_service_start failed"));
}
//lint -e{655} bit-wise operation uses compatible enum
void ServiceImpl::StartRestore(const std::string& bkfile, const std::string& dbfile,
int pagesize, IBPP::BRF flags)
{
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
if (mHandle == 0)
throw LogicExceptionImpl("Service::Restore", _("Service is not connected."));
if (bkfile.empty())
throw LogicExceptionImpl("Service::Restore", _("Backup file must be specified."));
if (dbfile.empty())
throw LogicExceptionImpl("Service::Restore", _("Main database file must be specified."));
IBS status(mDriver);
SPB spb(mDriver);
spb.Insert(isc_action_svc_restore);
spb.InsertString(isc_spb_bkp_file, 2, bkfile.c_str());
spb.InsertString(isc_spb_dbname, 2, dbfile.c_str());
if (flags & IBPP::brVerbose) spb.Insert(isc_spb_verbose);
if (pagesize != 0) spb.InsertQuad(isc_spb_res_page_size, pagesize);
unsigned int mask;
if (flags & IBPP::brReplace) mask = isc_spb_res_replace;
else mask = isc_spb_res_create; // Safe default mode
if (flags & IBPP::brDeactivateIdx) mask |= isc_spb_res_deactivate_idx;
if (flags & IBPP::brNoShadow) mask |= isc_spb_res_no_shadow;
if (flags & IBPP::brNoValidity) mask |= isc_spb_res_no_validity;
if (flags & IBPP::brPerTableCommit) mask |= isc_spb_res_one_at_a_time;
if (flags & IBPP::brUseAllSpace) mask |= isc_spb_res_use_all_space;
if (mask != 0) spb.InsertQuad(isc_spb_options, mask);
(mDriver->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::Restore", _("isc_service_start failed"));
}
const char* ServiceImpl::WaitMsg()
{
IBS status(mDriver);
SPB req(mDriver);
RB result(mDriver, 1024);
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
req.Insert(isc_info_svc_line); // Request one line of textual output
// _service_query will only block until a line of result is available
// (or until the end of the task if it does not report information)
(mDriver->m_service_query)(status.Self(), &mHandle, 0, 0, 0,
req.Size(), req.Self(), result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "ServiceImpl::Wait", _("isc_service_query failed"));
// If message length is zero bytes, task is finished
if (result.GetString(isc_info_svc_line, mWaitMessage) == 0) return 0;
// Task is not finished, but we have something to report
return mWaitMessage.c_str();
}
#include <iostream>
void ServiceImpl::Wait()
{
IBS status(mDriver);
SPB spb(mDriver);
RB result(mDriver, 1024);
std::string msg;
if (mDriver->mGDSVersion < 60)
throw LogicExceptionImpl("Service", _("Requires the version 6 of GDS32.DLL"));
spb.Insert(isc_info_svc_line);
for (;;)
{
// _service_query will only block until a line of result is available
// (or until the end of the task if it does not report information)
(mDriver->m_service_query)(status.Self(), &mHandle, 0, 0, 0,
spb.Size(), spb.Self(), result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "ServiceImpl::Wait", _("isc_service_query failed"));
// If message length is zero bytes, task is finished
if (result.GetString(isc_info_svc_line, msg) == 0) return;
status.Reset();
result.Reset();
}
}
IBPP::IService* ServiceImpl::AddRef()
{
ASSERTION(mRefCount >= 0);
++mRefCount;
return this;
}
void ServiceImpl::Release()
{
// Release cannot throw, except in DEBUG builds on assertion
ASSERTION(mRefCount >= 0);
--mRefCount;
try
{
if (mRefCount <= 0)
{
mDriver->Detach(this);
delete this;
}
}
catch (...) { }
}
// (((((((( OBJECT INTERNAL METHODS ))))))))
void ServiceImpl::SetServerName(const char* newName)
{
if (newName == 0) mServerName.erase();
else mServerName = newName;
}
void ServiceImpl::SetUserName(const char* newName)
{
if (newName == 0) mUserName.erase();
else mUserName = newName;
}
void ServiceImpl::SetUserPassword(const char* newPassword)
{
if (newPassword == 0) mUserPassword.erase();
else mUserPassword = newPassword;
}
ServiceImpl::ServiceImpl(DriverImpl* drv, const std::string& ServerName,
const std::string& UserName, const std::string& UserPassword)
: mRefCount(0), mDriver(drv), mHandle(0),
mServerName(ServerName), mUserName(UserName), mUserPassword(UserPassword)
{
}
ServiceImpl::~ServiceImpl()
{
try { if (ServiceImpl::Connected()) ServiceImpl::Disconnect(); }
catch (...) { }
}
//
// Eof
//