Codebase list libberkeleydb-perl / e05800a
Merge upstream release v0.23 Marco d'Itri 9 years ago
25 changed file(s) with 1739 addition(s) and 346 deletion(s). Raw diff Collapse all Expand all
11 package BerkeleyDB;
22
33
4 # Copyright (c) 1997-2002 Paul Marquess. All rights reserved.
4 # Copyright (c) 1997-2003 Paul Marquess. All rights reserved.
55 # This program is free software; you can redistribute it and/or
66 # modify it under the same terms as Perl itself.
77 #
1616 use vars qw($VERSION @ISA @EXPORT $AUTOLOAD
1717 $use_XSLoader);
1818
19 $VERSION = '0.20';
19 $VERSION = '0.23';
2020
2121 require Exporter;
2222 #require DynaLoader;
447447 return \%got ;
448448 }
449449
450 sub parseEncrypt
451 {
452 my $got = shift ;
453
454
455 if (defined $got->{Encrypt}) {
456 croak("Encrypt parameter must be a hash reference")
457 if !ref $got->{Encrypt} || ref $got->{Encrypt} ne 'HASH' ;
458
459 my %config = %{ $got->{Encrypt} } ;
460
461 my $p = BerkeleyDB::ParseParameters({
462 Password => undef,
463 Flags => undef,
464 }, %config);
465
466 croak("Must specify Password and Flags with Encrypt parameter")
467 if ! (defined $p->{Password} && defined $p->{Flags});
468
469 $got->{"Enc_Passwd"} = $p->{Password};
470 $got->{"Enc_Flags"} = $p->{Flags};
471 }
472 }
473
450474 use UNIVERSAL qw( isa ) ;
451475
452476 sub env_remove
579603 # [ -Cachesize => number ]
580604 # [ -LockDetect => ]
581605 # [ -Verbose => boolean ]
606 # [ -Encrypt => { Password => string, Flags => value}
607 #
582608 # ;
583609
584610 my $pkg = shift ;
594620 LockDetect => 0,
595621 Verbose => 0,
596622 Config => undef,
623 Encrypt => undef,
597624 }, @_) ;
598625
599626 if (defined $got->{ErrFile}) {
616643 @BerkeleyDB::a = () ;
617644 my $k = "" ; my $v = "" ;
618645 while (($k, $v) = each %config) {
619 if ($BerkeleyDB::db_version >= 3.1 && ! $valid_config_keys{$k} ) {
646 if ($BerkeleyDB::db_version >= 3.1 && ! $valid_config_keys{$k} ){
620647 $BerkeleyDB::Error = "illegal name-value pair: $k $v\n" ;
621648 croak $BerkeleyDB::Error ;
622649 }
626653 $got->{"Config"} = pack("p*", @BerkeleyDB::a, undef)
627654 if @BerkeleyDB::a ;
628655 }
656
657 BerkeleyDB::parseEncrypt($got);
629658
630659 my ($addr) = _db_appinit($pkg, $got) ;
631660 my $obj ;
698727 Env => undef,
699728 #Tie => undef,
700729 Txn => undef,
730 Encrypt => undef,
701731
702732 # Hash specific
703733 Ffactor => 0,
720750
721751 croak("-Tie needs a reference to a hash")
722752 if defined $got->{Tie} and $got->{Tie} !~ /HASH/ ;
753
754 BerkeleyDB::parseEncrypt($got);
723755
724756 my ($addr) = _db_open_hash($self, $got);
725757 my $obj ;
760792 Env => undef,
761793 #Tie => undef,
762794 Txn => undef,
795 Encrypt => undef,
763796
764797 # Btree specific
765798 Minkey => 0,
776809
777810 croak("-Tie needs a reference to a hash")
778811 if defined $got->{Tie} and $got->{Tie} !~ /HASH/ ;
812
813 BerkeleyDB::parseEncrypt($got);
779814
780815 my ($addr) = _db_open_btree($self, $got);
781816 my $obj ;
816851 Env => undef,
817852 #Tie => undef,
818853 Txn => undef,
854 Encrypt => undef,
819855
820856 # Recno specific
821857 Delim => undef,
837873 croak("ArrayBase can only be 0 or 1, parsed $got->{ArrayBase}")
838874 if $got->{ArrayBase} != 1 and $got->{ArrayBase} != 0 ;
839875
876
877 BerkeleyDB::parseEncrypt($got);
840878
841879 $got->{Fname} = $got->{Filename} if defined $got->{Filename} ;
842880
879917 Env => undef,
880918 #Tie => undef,
881919 Txn => undef,
920 Encrypt => undef,
882921
883922 # Queue specific
884923 Len => undef,
898937
899938 croak("ArrayBase can only be 0 or 1, parsed $got->{ArrayBase}")
900939 if $got->{ArrayBase} != 1 and $got->{ArrayBase} != 0 ;
940
941 BerkeleyDB::parseEncrypt($got);
901942
902943 $got->{Fname} = $got->{Filename} if defined $got->{Filename} ;
903944
9961037 Env => undef,
9971038 #Tie => undef,
9981039 Txn => undef,
1040 Encrypt => undef,
9991041
10001042 }, @_) ;
10011043
10071049
10081050 croak("-Tie needs a reference to a hash")
10091051 if defined $got->{Tie} and $got->{Tie} !~ /HASH/ ;
1052
1053 BerkeleyDB::parseEncrypt($got);
10101054
10111055 my ($addr, $type) = _db_open_unknown($got);
10121056 my $obj ;
11031147 {
11041148 my $self = shift ;
11051149 my ($key, $value) = (0, 0) ;
1106 my $cursor = $self->db_cursor() ;
1150 my $cursor = $self->_db_write_cursor() ;
11071151 while ($cursor->c_get($key, $value, BerkeleyDB::DB_PREV()) == 0)
11081152 { $cursor->c_del() }
1109 #1 while $cursor->c_del() == 0 ;
1110 # cursor will self-destruct
11111153 }
11121154
11131155 #sub DESTROY
13831425 return $obj ;
13841426 }
13851427
1428 sub _db_write_cursor
1429 {
1430 my $db = shift ;
1431 my ($addr) = $db->__db_write_cursor(@_) ;
1432 my $obj ;
1433 $obj = bless [$addr, $db] , "BerkeleyDB::Cursor" if $addr ;
1434 return $obj ;
1435 }
1436
13861437 sub db_join
13871438 {
1388 croak 'Usage: $db->BerkeleyDB::Common::db_join([cursors], flags=0)'
1439 croak 'Usage: $db->BerkeleyDB::db_join([cursors], flags=0)'
13891440 if @_ < 2 || @_ > 3 ;
13901441 my $db = shift ;
1442 croak 'db_join: first parameter is not an array reference'
1443 if ! ref $_[0] || ref $_[0] ne 'ARRAY';
13911444 my ($addr) = $db->_db_join(@_) ;
13921445 my $obj ;
13931446 $obj = bless [$addr, $db, $_[0]] , "BerkeleyDB::Cursor" if $addr ;
1313 $db = tie %hash, 'BerkeleyDB::Btree', [OPTIONS] ;
1414 $db = new BerkeleyDB::Btree [OPTIONS] ;
1515
16 $db = tie %hash, 'BerkeleyDB::Recno', [OPTIONS] ;
16 $db = tie @array, 'BerkeleyDB::Recno', [OPTIONS] ;
1717 $db = new BerkeleyDB::Recno [OPTIONS] ;
1818
19 $db = tie %hash, 'BerkeleyDB::Queue', [OPTIONS] ;
19 $db = tie @array, 'BerkeleyDB::Queue', [OPTIONS] ;
2020 $db = new BerkeleyDB::Queue [OPTIONS] ;
2121
2222 $db = new BerkeleyDB::Unknown [OPTIONS] ;
3535 $status = $db->db_put() ;
3636 $status = $db->db_del() ;
3737 $status = $db->db_sync() ;
38 $status = $db->db_close() ;
3938 $status = $db->db_close() ;
4039 $status = $db->db_pget()
4140 $hash_ref = $db->db_stat() ;
8382 $status = $env->set_data_dir() ;
8483 $status = $env->set_tmp_dir() ;
8584 $status = $env->set_verbose() ;
85 $db_env_ptr = $env->DB_ENV() ;
8686
8787 $BerkeleyDB::Error
8888 $BerkeleyDB::db_version
128128 function B<db_appinit> in Berkeley DB 2.x or B<db_env_create> and
129129 B<DBENV-E<gt>open> in Berkeley DB 3.x/4.x. Its purpose is to initialise a
130130 number of sub-systems that can then be used in a consistent way in all
131 the databases you make use of the environment.
131 the databases you make use of in the environment.
132132
133133 If you don't intend using transactions, locking or logging, then you
134134 shouldn't need to make use of B<BerkeleyDB::Env>.
135
136 Note that an environment consists of a number of files that Berkeley DB
137 manages behind the scenes for you. When you first use an environment, it
138 needs to be explicitly created. This is done by including C<DB_CREATE>
139 with the C<Flags> parameter, described below.
135140
136141 =head2 Synopsis
137142
146151 [ -SetFlags => bitmask, ]
147152 [ -LockDetect => number, ]
148153 [ -Verbose => boolean, ]
154 [ -Encrypt => { Password => "string",
155 Flags => number }, ]
149156
150157 =over 5
151158
181188
182189 If present, this parameter should be the hostname of a server that is running
183190 the Berkeley DB RPC server. All databases will be accessed via the RPC server.
191
192 =item -Encrypt
193
194 If present, this parameter will enable encryption of all data before
195 it is written to the database. This parameters must be given a hash
196 reference. The format is shown below.
197
198 -Encrypt => { -Password => "abc", Flags => DB_ENCRYPT_AES }
199
200 Valid values for the Flags are 0 or C<DB_ENCRYPT_AES>.
201
202 This option requires Berkeley DB 4.1 or better.
184203
185204 =item -Cachesize
186205
334353
335354 Returns the status of the last BerkeleyDB::Env method.
336355
337 =item $env->setmutexlocks()
338
339 Only available in Berkeley Db 3.0 or greater. Calls
340 B<db_env_set_mutexlocks> when used with Berkeley DB 3.1.x. When used with
341 Berkeley DB 3.0 or 3.2 and better it calls B<DBENV-E<gt>set_mutexlocks>.
356
357 =item $env->DB_ENV()
358
359 Returns a pointer to the underlying DB_ENV data structure that Berkeley
360 DB uses.
361
362 =item $env->status()
363
364 Returns the status of the last BerkeleyDB::Env method.
342365
343366 =back
344367
420443 [ -Pagesize => number,]
421444 [ -Env => $env,]
422445 [ -Txn => $txn,]
446 [ -Encrypt => { Password => "string",
447 Flags => number }, ],
423448 # BerkeleyDB::Hash specific
424449 [ -Ffactor => number,]
425450 [ -Nelem => number,]
439464 [ -Pagesize => number,]
440465 [ -Env => $env,]
441466 [ -Txn => $txn,]
467 [ -Encrypt => { Password => "string",
468 Flags => number }, ],
442469 # BerkeleyDB::Hash specific
443470 [ -Ffactor => number,]
444471 [ -Nelem => number,]
463490 =item -Property
464491
465492 Used to specify extra flags when opening a database. The following
466 flags may be specified by logically OR'ing together one or more of the
493 flags may be specified by bitwise OR'ing together one or more of the
467494 following values:
468495
469496 B<DB_DUP>
730757 [ -Pagesize => number,]
731758 [ -Env => $env,]
732759 [ -Txn => $txn,]
760 [ -Encrypt => { Password => "string",
761 Flags => number }, ],
733762 # BerkeleyDB::Btree specific
734763 [ -Minkey => number,]
735764 [ -Compare => code reference,]
749778 [ -Pagesize => number,]
750779 [ -Env => $env,]
751780 [ -Txn => $txn,]
781 [ -Encrypt => { Password => "string",
782 Flags => number }, ],
752783 # BerkeleyDB::Btree specific
753784 [ -Minkey => number,]
754785 [ -Compare => code reference,]
765796 =item -Property
766797
767798 Used to specify extra flags when opening a database. The following
768 flags may be specified by logically OR'ing together one or more of the
799 flags may be specified by bitwise OR'ing together one or more of the
769800 following values:
770801
771802 B<DB_DUP>
9771008 [ -Pagesize => number,]
9781009 [ -Env => $env,]
9791010 [ -Txn => $txn,]
1011 [ -Encrypt => { Password => "string",
1012 Flags => number }, ],
9801013 # BerkeleyDB::Recno specific
9811014 [ -Delim => byte,]
9821015 [ -Len => number,]
9961029 [ -Pagesize => number,]
9971030 [ -Env => $env,]
9981031 [ -Txn => $txn,]
1032 [ -Encrypt => { Password => "string",
1033 Flags => number }, ],
9991034 # BerkeleyDB::Recno specific
10001035 [ -Delim => byte,]
10011036 [ -Len => number,]
10711106 [ -Pagesize => number,]
10721107 [ -Env => $env,]
10731108 [ -Txn => $txn,]
1109 [ -Encrypt => { Password => "string",
1110 Flags => number }, ],
10741111 # BerkeleyDB::Queue specific
10751112 [ -Len => number,]
10761113 [ -Pad => byte,]
10891126 [ -Pagesize => number,]
10901127 [ -Env => $env,]
10911128 [ -Txn => $txn,]
1129 [ -Encrypt => { Password => "string",
1130 Flags => number }, ],
10921131 # BerkeleyDB::Queue specific
10931132 [ -Len => number,]
10941133 [ -Pad => byte,]
11151154 [ -Pagesize => number,]
11161155 [ -Env => $env,]
11171156 [ -Txn => $txn,]
1157 [ -Encrypt => { Password => "string",
1158 Flags => number }, ],
11181159
11191160
11201161 =head2 An example
11781219 When working under a Berkeley DB environment, this parameter
11791220
11801221 Defaults to no environment.
1222
1223 =item -Encrypt
1224
1225 If present, this parameter will enable encryption of all data before
1226 it is written to the database. This parameters must be given a hash
1227 reference. The format is shown below.
1228
1229 -Encrypt => { -Password => "abc", Flags => DB_ENCRYPT_AES }
1230
1231 Valid values for the Flags are 0 or C<DB_ENCRYPT_AES>.
1232
1233 This option requires Berkeley DB 4.1 or better.
11811234
11821235 =item -Txn
11831236
12141267
12151268 =back
12161269
1217 In addition, the following value may be set by logically OR'ing it into
1270 In addition, the following value may be set by bitwise OR'ing it into
12181271 the B<$flags> parameter:
12191272
12201273 =over 5
14291482
14301483 =back
14311484
1432 In addition, the following value may be set by logically OR'ing it into
1485 In addition, the following value may be set by bitwise OR'ing it into
14331486 the B<$flags> parameter:
14341487
14351488 =over 5
17301783
17311784 Before Berkeley DB 2.x was written there was only one Perl module that
17321785 interfaced to Berkeley DB. That module is called B<DB_File>. Although
1733 B<DB_File> can be build with Berkeley DB 1.x, 2.x, 3.x or 4.x, it only provides
1734 an interface to the functionality available in Berkeley DB 1.x. That
1735 means that it doesn't support transactions, locking or any of the other
1736 new features available in DB 2.x or better.
1786 B<DB_File> can be build with Berkeley DB 1.x, 2.x, 3.x or 4.x, it only
1787 provides an interface to the functionality available in Berkeley DB
1788 1.x. That means that it doesn't support transactions, locking or any of
1789 the other new features available in DB 2.x or better.
17371790
17381791 =head2 How do I store Perl data structures with BerkeleyDB?
17391792
17531806
17541807 =head1 COPYRIGHT
17551808
1756 Copyright (c) 1997-2002 Paul Marquess. All rights reserved. This program
1809 Copyright (c) 1997-2003 Paul Marquess. All rights reserved. This program
17571810 is free software; you can redistribute it and/or modify it under the
17581811 same terms as Perl itself.
17591812
17801833
17811834 =head1 AUTHOR
17821835
1783 Paul Marquess E<lt>Paul.Marquess@btinternet.comE<gt>.
1836 Paul Marquess E<lt>pmqs@cpan.orgE<gt>.
17841837
17851838 Questions about Berkeley DB may be addressed to E<lt>db@sleepycat.comE<gt>.
17861839
1313 $db = tie %hash, 'BerkeleyDB::Btree', [OPTIONS] ;
1414 $db = new BerkeleyDB::Btree [OPTIONS] ;
1515
16 $db = tie %hash, 'BerkeleyDB::Recno', [OPTIONS] ;
16 $db = tie @array, 'BerkeleyDB::Recno', [OPTIONS] ;
1717 $db = new BerkeleyDB::Recno [OPTIONS] ;
1818
19 $db = tie %hash, 'BerkeleyDB::Queue', [OPTIONS] ;
19 $db = tie @array, 'BerkeleyDB::Queue', [OPTIONS] ;
2020 $db = new BerkeleyDB::Queue [OPTIONS] ;
2121
2222 $db = new BerkeleyDB::Unknown [OPTIONS] ;
3535 $status = $db->db_put() ;
3636 $status = $db->db_del() ;
3737 $status = $db->db_sync() ;
38 $status = $db->db_close() ;
3938 $status = $db->db_close() ;
4039 $status = $db->db_pget()
4140 $hash_ref = $db->db_stat() ;
8382 $status = $env->set_data_dir() ;
8483 $status = $env->set_tmp_dir() ;
8584 $status = $env->set_verbose() ;
85 $db_env_ptr = $env->DB_ENV() ;
8686
8787 $BerkeleyDB::Error
8888 $BerkeleyDB::db_version
128128 function B<db_appinit> in Berkeley DB 2.x or B<db_env_create> and
129129 B<DBENV-E<gt>open> in Berkeley DB 3.x/4.x. Its purpose is to initialise a
130130 number of sub-systems that can then be used in a consistent way in all
131 the databases you make use of the environment.
131 the databases you make use of in the environment.
132132
133133 If you don't intend using transactions, locking or logging, then you
134134 shouldn't need to make use of B<BerkeleyDB::Env>.
135
136 Note that an environment consists of a number of files that Berkeley DB
137 manages behind the scenes for you. When you first use an environment, it
138 needs to be explicitly created. This is done by including C<DB_CREATE>
139 with the C<Flags> parameter, described below.
135140
136141 =head2 Synopsis
137142
146151 [ -SetFlags => bitmask, ]
147152 [ -LockDetect => number, ]
148153 [ -Verbose => boolean, ]
154 [ -Encrypt => { Password => "string",
155 Flags => number }, ]
149156
150157 =over 5
151158
181188
182189 If present, this parameter should be the hostname of a server that is running
183190 the Berkeley DB RPC server. All databases will be accessed via the RPC server.
191
192 =item -Encrypt
193
194 If present, this parameter will enable encryption of all data before
195 it is written to the database. This parameters must be given a hash
196 reference. The format is shown below.
197
198 -Encrypt => { -Password => "abc", Flags => DB_ENCRYPT_AES }
199
200 Valid values for the Flags are 0 or C<DB_ENCRYPT_AES>.
201
202 This option requires Berkeley DB 4.1 or better.
184203
185204 =item -Cachesize
186205
334353
335354 Returns the status of the last BerkeleyDB::Env method.
336355
337 =item $env->setmutexlocks()
338
339 Only available in Berkeley Db 3.0 or greater. Calls
340 B<db_env_set_mutexlocks> when used with Berkeley DB 3.1.x. When used with
341 Berkeley DB 3.0 or 3.2 and better it calls B<DBENV-E<gt>set_mutexlocks>.
356
357 =item $env->DB_ENV()
358
359 Returns a pointer to the underlying DB_ENV data structure that Berkeley
360 DB uses.
361
362 =item $env->status()
363
364 Returns the status of the last BerkeleyDB::Env method.
342365
343366 =back
344367
420443 [ -Pagesize => number,]
421444 [ -Env => $env,]
422445 [ -Txn => $txn,]
446 [ -Encrypt => { Password => "string",
447 Flags => number }, ],
423448 # BerkeleyDB::Hash specific
424449 [ -Ffactor => number,]
425450 [ -Nelem => number,]
439464 [ -Pagesize => number,]
440465 [ -Env => $env,]
441466 [ -Txn => $txn,]
467 [ -Encrypt => { Password => "string",
468 Flags => number }, ],
442469 # BerkeleyDB::Hash specific
443470 [ -Ffactor => number,]
444471 [ -Nelem => number,]
463490 =item -Property
464491
465492 Used to specify extra flags when opening a database. The following
466 flags may be specified by logically OR'ing together one or more of the
493 flags may be specified by bitwise OR'ing together one or more of the
467494 following values:
468495
469496 B<DB_DUP>
622649 [ -Pagesize => number,]
623650 [ -Env => $env,]
624651 [ -Txn => $txn,]
652 [ -Encrypt => { Password => "string",
653 Flags => number }, ],
625654 # BerkeleyDB::Btree specific
626655 [ -Minkey => number,]
627656 [ -Compare => code reference,]
641670 [ -Pagesize => number,]
642671 [ -Env => $env,]
643672 [ -Txn => $txn,]
673 [ -Encrypt => { Password => "string",
674 Flags => number }, ],
644675 # BerkeleyDB::Btree specific
645676 [ -Minkey => number,]
646677 [ -Compare => code reference,]
657688 =item -Property
658689
659690 Used to specify extra flags when opening a database. The following
660 flags may be specified by logically OR'ing together one or more of the
691 flags may be specified by bitwise OR'ing together one or more of the
661692 following values:
662693
663694 B<DB_DUP>
816847 [ -Pagesize => number,]
817848 [ -Env => $env,]
818849 [ -Txn => $txn,]
850 [ -Encrypt => { Password => "string",
851 Flags => number }, ],
819852 # BerkeleyDB::Recno specific
820853 [ -Delim => byte,]
821854 [ -Len => number,]
835868 [ -Pagesize => number,]
836869 [ -Env => $env,]
837870 [ -Txn => $txn,]
871 [ -Encrypt => { Password => "string",
872 Flags => number }, ],
838873 # BerkeleyDB::Recno specific
839874 [ -Delim => byte,]
840875 [ -Len => number,]
877912 [ -Pagesize => number,]
878913 [ -Env => $env,]
879914 [ -Txn => $txn,]
915 [ -Encrypt => { Password => "string",
916 Flags => number }, ],
880917 # BerkeleyDB::Queue specific
881918 [ -Len => number,]
882919 [ -Pad => byte,]
895932 [ -Pagesize => number,]
896933 [ -Env => $env,]
897934 [ -Txn => $txn,]
935 [ -Encrypt => { Password => "string",
936 Flags => number }, ],
898937 # BerkeleyDB::Queue specific
899938 [ -Len => number,]
900939 [ -Pad => byte,]
921960 [ -Pagesize => number,]
922961 [ -Env => $env,]
923962 [ -Txn => $txn,]
963 [ -Encrypt => { Password => "string",
964 Flags => number }, ],
924965
925966
926967 =head2 An example
9841025 When working under a Berkeley DB environment, this parameter
9851026
9861027 Defaults to no environment.
1028
1029 =item -Encrypt
1030
1031 If present, this parameter will enable encryption of all data before
1032 it is written to the database. This parameters must be given a hash
1033 reference. The format is shown below.
1034
1035 -Encrypt => { -Password => "abc", Flags => DB_ENCRYPT_AES }
1036
1037 Valid values for the Flags are 0 or C<DB_ENCRYPT_AES>.
1038
1039 This option requires Berkeley DB 4.1 or better.
9871040
9881041 =item -Txn
9891042
10201073
10211074 =back
10221075
1023 In addition, the following value may be set by logically OR'ing it into
1076 In addition, the following value may be set by bitwise OR'ing it into
10241077 the B<$flags> parameter:
10251078
10261079 =over 5
12351288
12361289 =back
12371290
1238 In addition, the following value may be set by logically OR'ing it into
1291 In addition, the following value may be set by bitwise OR'ing it into
12391292 the B<$flags> parameter:
12401293
12411294 =over 5
14971550
14981551 Before Berkeley DB 2.x was written there was only one Perl module that
14991552 interfaced to Berkeley DB. That module is called B<DB_File>. Although
1500 B<DB_File> can be build with Berkeley DB 1.x, 2.x, 3.x or 4.x, it only provides
1501 an interface to the functionality available in Berkeley DB 1.x. That
1502 means that it doesn't support transactions, locking or any of the other
1503 new features available in DB 2.x or better.
1553 B<DB_File> can be build with Berkeley DB 1.x, 2.x, 3.x or 4.x, it only
1554 provides an interface to the functionality available in Berkeley DB
1555 1.x. That means that it doesn't support transactions, locking or any of
1556 the other new features available in DB 2.x or better.
15041557
15051558 =head2 How do I store Perl data structures with BerkeleyDB?
15061559
15201573
15211574 =head1 COPYRIGHT
15221575
1523 Copyright (c) 1997-2002 Paul Marquess. All rights reserved. This program
1576 Copyright (c) 1997-2003 Paul Marquess. All rights reserved. This program
15241577 is free software; you can redistribute it and/or modify it under the
15251578 same terms as Perl itself.
15261579
15471600
15481601 =head1 AUTHOR
15491602
1550 Paul Marquess E<lt>Paul.Marquess@btinternet.comE<gt>.
1603 Paul Marquess E<lt>pmqs@cpan.orgE<gt>.
15511604
15521605 Questions about Berkeley DB may be addressed to E<lt>db@sleepycat.comE<gt>.
15531606
00 /*
11
2 BerkeleyDB.xs -- Perl 5 interface to Berkeley DB version 2 & 3
2 BerkeleyDB.xs -- Perl 5 interface to Berkeley DB version 2, 3 &4
33
44 written by Paul Marquess <Paul.Marquess@btinternet.com>
55
66 All comments/suggestions/problems are welcome
77
8 Copyright (c) 1997-2002 Paul Marquess. All rights reserved.
8 Copyright (c) 1997-2003 Paul Marquess. All rights reserved.
99 This program is free software; you can redistribute it and/or
1010 modify it under the same terms as Perl itself.
1111
4444 # ifdef fclose
4545 # undef fclose
4646 # endif
47 # ifdef rename
48 # undef rename
49 # endif
50 # ifdef open
51 # undef open
52 # endif
4753 #endif
4854
4955 /* Being the Berkeley DB we prefer the <sys/cdefs.h> (which will be
127133 # define DB_QUEUE 4
128134 #endif /* DB_VERSION_MAJOR == 2 */
129135
136 #if DB_VERSION_MAJOR == 2
137 # define BackRef internal
138 #else
139 # if DB_VERSION_MAJOR == 3 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 0)
140 # define BackRef cj_internal
141 # else
142 # define BackRef api_internal
143 # endif
144 #endif
145
130146 #ifdef AT_LEAST_DB_3_2
131147 # define DB_callback DB * db,
148 # define getCurrentDB ((BerkeleyDB)db->BackRef)
149 # define saveCurrentDB(db)
132150 #else
133151 # define DB_callback
152 # define getCurrentDB CurrentDB
153 # define saveCurrentDB(db) CurrentDB = db
134154 #endif
135155
136156 #if DB_VERSION_MAJOR > 2
180200 int TxnMgrStatus ;
181201 int active ;
182202 bool txn_enabled ;
203 bool opened ;
204 bool cdb_enabled;
183205 } BerkeleyDB_ENV_type ;
184206
185207
210232 u_int32_t dlen ;
211233 u_int32_t doff ;
212234 int active ;
235 bool cdb_enabled;
213236 #ifdef ALLOW_RECNO_OFFSET
214237 int array_base ;
215238 #endif
245268 u_int32_t dlen ;
246269 u_int32_t doff ;
247270 int active ;
271 bool cdb_enabled;
248272 #ifdef ALLOW_RECNO_OFFSET
249273 int array_base ;
250274 #endif
336360 # define flagSet(bitmask) ((flags & DB_OPFLAGS_MASK) == (bitmask))
337361 #endif
338362
339 #if DB_VERSION_MAJOR == 2
340 # define BackRef internal
341 #else
342 # if DB_VERSION_MAJOR == 3 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 0)
343 # define BackRef cj_internal
344 # else
345 # define BackRef api_internal
346 # endif
347 #endif
348363
349364 #define ERR_BUFF "BerkeleyDB::Error"
350365
458473 #define ckActive_Transaction(a) ckActive(a, "Transaction")
459474 #define ckActive_Database(a) ckActive(a, "Database")
460475 #define ckActive_Cursor(a) ckActive(a, "Cursor")
476
477 #define dieIfEnvOpened(e, m) if (e->opened) softCrash("Cannot call method BerkeleyDB::Env::%s after environment has been opened", m);
461478
462479 /* Internal Global Data */
463480 static db_recno_t Value ;
868885 PUSHs(sv_2mortal(newSVpvn(data2,key2->size)));
869886 PUTBACK ;
870887
871 count = perl_call_sv(CurrentDB->compare, G_SCALAR);
888 count = perl_call_sv(getCurrentDB->compare, G_SCALAR);
872889
873890 SPAGAIN ;
874891
895912 BerkeleyDB keepDB = CurrentDB ;
896913
897914 Trace(("In dup_compare \n")) ;
898 if (!CurrentDB)
915 if (!getCurrentDB)
899916 softCrash("Internal Error - No CurrentDB in dup_compare") ;
900 if (CurrentDB->dup_compare == NULL)
901 softCrash("in dup_compare: no callback specified for database '%s'", CurrentDB->filename) ;
917 if (getCurrentDB->dup_compare == NULL)
918
919
920 softCrash("in dup_compare: no callback specified for database '%s'", getCurrentDB->filename) ;
902921
903922 data1 = (char*) key1->data ;
904923 data2 = (char*) key2->data ;
923942 PUSHs(sv_2mortal(newSVpvn(data2,key2->size)));
924943 PUTBACK ;
925944
926 count = perl_call_sv(CurrentDB->dup_compare, G_SCALAR);
945 count = perl_call_sv(getCurrentDB->dup_compare, G_SCALAR);
927946
928947 SPAGAIN ;
929948
972991 PUSHs(sv_2mortal(newSVpvn(data2,key2->size)));
973992 PUTBACK ;
974993
975 count = perl_call_sv(CurrentDB->prefix, G_SCALAR);
994 count = perl_call_sv(getCurrentDB->prefix, G_SCALAR);
976995
977996 SPAGAIN ;
978997
10101029 XPUSHs(sv_2mortal(newSVpvn((char*)data,size)));
10111030 PUTBACK ;
10121031
1013 count = perl_call_sv(CurrentDB->hash, G_SCALAR);
1032 count = perl_call_sv(getCurrentDB->hash, G_SCALAR);
10141033
10151034 SPAGAIN ;
10161035
10371056 int retval ;
10381057 int count ;
10391058 SV * skey_SV ;
1059 int skey_len;
1060 char * skey_ptr ;
10401061
10411062 Trace(("In associate_cb \n")) ;
1042 if (((BerkeleyDB)db->BackRef)->associated == NULL){
1063 if (getCurrentDB->associated == NULL){
10431064 Trace(("No Callback registered\n")) ;
10441065 return EINVAL ;
10451066 }
10721093 PUTBACK ;
10731094
10741095 Trace(("calling associated cb\n"));
1075 count = perl_call_sv(((BerkeleyDB)db->BackRef)->associated, G_SCALAR);
1096 count = perl_call_sv(getCurrentDB->associated, G_SCALAR);
10761097 Trace(("called associated cb\n"));
10771098
10781099 SPAGAIN ;
10861107
10871108 /* retrieve the secondary key */
10881109 DBT_clear(*skey);
1110 skey_ptr = SvPV(skey_SV, skey_len);
10891111 skey->flags = DB_DBT_APPMALLOC;
1090 skey->size = SvCUR(skey_SV);
1091 skey->data = (char*)safemalloc(skey->size);
1092 memcpy(skey->data, SvPVX(skey_SV), skey->size);
1112 /* skey->size = SvCUR(skey_SV); */
1113 /* skey->data = (char*)safemalloc(skey->size); */
1114 skey->size = skey_len;
1115 skey->data = (char*)safemalloc(skey_len);
1116 memcpy(skey->data, skey_ptr, skey_len);
10931117 Trace(("key is %d -- %.*s\n", skey->size, skey->size, skey->data));
10941118
10951119 FREETMPS ;
11721196 DBTYPE type,
11731197 int flags,
11741198 int mode,
1175 DB_INFO * info
1199 DB_INFO * info,
1200 char * password,
1201 int enc_flags
11761202 )
11771203 {
11781204 DB_ENV * env = NULL ;
11851211 dbenv, ref_dbenv, file, subname, type, flags, mode)) ;
11861212
11871213 CurrentDB = db ;
1214
11881215 if (dbenv)
11891216 env = dbenv->Env ;
11901217
11981225 if (subname)
11991226 softCrash("Subname needs Berkeley DB 3 or better") ;
12001227 #endif
1228
1229 #ifndef AT_LEAST_DB_4_1
1230 if (password)
1231 softCrash("-Encrypt needs Berkeley DB 4.x or better") ;
1232 #endif /* ! AT_LEAST_DB_4_1 */
12011233
12021234 #if DB_VERSION_MAJOR > 2
12031235 Status = db_create(&dbp, env, 0) ;
12051237 if (Status)
12061238 return RETVAL ;
12071239
1240 #ifdef AT_LEAST_DB_3_2
1241 dbp->BackRef = db;
1242 #endif
1243
12081244 #ifdef AT_LEAST_DB_3_3
12091245 if (! env) {
12101246 dbp->set_alloc(dbp, safemalloc, MyRealloc, safefree) ;
12111247 dbp->set_errcall(dbp, db_errcall_cb) ;
12121248 }
12131249 #endif
1250
1251 #ifdef AT_LEAST_DB_4_1
1252 /* set encryption */
1253 if (password)
1254 {
1255 Status = dbp->set_encrypt(dbp, password, enc_flags);
1256 Trace(("DB->set_encrypt passwd = %s, flags %d returned %s\n",
1257 password, enc_flags,
1258 my_db_strerror(Status))) ;
1259 if (Status)
1260 return RETVAL ;
1261 }
1262 #endif
12141263
12151264 if (info->re_source) {
12161265 Status = dbp->set_re_source(dbp, info->re_source) ;
13351384 if (info->q_extentsize) {
13361385 #ifdef AT_LEAST_DB_3_2
13371386 Status = dbp->set_q_extentsize(dbp, info->q_extentsize) ;
1338 Trace(("set_flags [%d] returned %s\n",
1339 info->flags, my_db_strerror(Status)));
1387 Trace(("set_q_extentsize [%d] returned %s\n",
1388 info->q_extentsize, my_db_strerror(Status)));
13401389 if (Status)
13411390 return RETVAL ;
13421391 #else
13431392 softCrash("-ExtentSize needs at least Berkeley DB 3.2.x") ;
13441393 #endif
13451394 }
1395
13461396
13471397 #ifdef AT_LEAST_DB_4_1
13481398 if ((Status = (dbp->open)(dbp, txnid, file, subname, type, flags, mode)) == 0) {
13541404 #endif /* DB_VERSION_MAJOR == 2 */
13551405
13561406 Trace(("db_opened ok\n"));
1357 #ifdef AT_LEAST_DB_3_3
1358 dbp->BackRef = db;
1359 #endif
13601407 RETVAL = db ;
13611408 RETVAL->dbp = dbp ;
13621409 RETVAL->txn = txnid ;
13771424 hash_store_iv("BerkeleyDB::Term::Db", (char *)RETVAL, 1) ;
13781425 Trace((" storing %p %p in BerkeleyDB::Term::Db\n", RETVAL, dbp)) ;
13791426 if (dbenv) {
1427 RETVAL->cdb_enabled = dbenv->cdb_enabled ;
13801428 RETVAL->parent_env = dbenv ;
13811429 dbenv->Status = Status ;
13821430 ++ dbenv->open_dbs ;
15261574 dbenv = env->Env ;
15271575 RETVAL = db_create(&dbp, dbenv, 0) ;
15281576 if (RETVAL == 0) {
1529 RETVAL = dbp->rename(dbp, db, subdb, newname, flags) ;
1577 RETVAL = (dbp->rename)(dbp, db, subdb, newname, flags) ;
15301578 }
15311579 #endif
15321580 }
15341582 RETVAL
15351583
15361584 MODULE = BerkeleyDB::Env PACKAGE = BerkeleyDB::Env PREFIX = env_
1585
1586 BerkeleyDB::Env::Raw
1587 create(flags=0)
1588 u_int32_t flags
1589 CODE:
1590 {
1591 #ifndef AT_LEAST_DB_4_1
1592 softCrash("$env->create needs Berkeley DB 4.1 or better") ;
1593 #else
1594 DB_ENV * env ;
1595 int status;
1596 RETVAL = NULL;
1597 Trace(("in BerkeleyDB::Env::create flags=%d\n", flags)) ;
1598 status = db_env_create(&env, flags) ;
1599 Trace(("db_env_create returned %s\n", my_db_strerror(status))) ;
1600 if (status == 0) {
1601 ZMALLOC(RETVAL, BerkeleyDB_ENV_type) ;
1602 RETVAL->Env = env ;
1603 RETVAL->active = TRUE ;
1604 RETVAL->opened = FALSE;
1605 env->set_alloc(env, safemalloc, MyRealloc, safefree) ;
1606 env->set_errcall(env, db_errcall_cb) ;
1607 }
1608 #endif
1609 }
1610 OUTPUT:
1611 RETVAL
1612
1613 int
1614 open(env, db_home=NULL, flags=0, mode=0777)
1615 BerkeleyDB::Env env
1616 char * db_home
1617 u_int32_t flags
1618 int mode
1619 CODE:
1620 #ifndef AT_LEAST_DB_4_1
1621 softCrash("$env->create needs Berkeley DB 4.1 or better") ;
1622 #else
1623 RETVAL = env->Env->open(env->Env, db_home, flags, mode);
1624 env->opened = TRUE;
1625 #endif
1626 OUTPUT:
1627 RETVAL
1628
1629
1630 int
1631 set_encrypt(env, passwd, flags)
1632 BerkeleyDB::Env env
1633 const char * passwd
1634 u_int32_t flags
1635 CODE:
1636 #ifndef AT_LEAST_DB_4_1
1637 softCrash("$env->set_encrypt needs Berkeley DB 4.1 or better") ;
1638 #else
1639 dieIfEnvOpened(env, "set_encrypt");
1640 RETVAL = env->Env->set_encrypt(env->Env, passwd, flags);
1641 env->opened = TRUE;
1642 #endif
1643 OUTPUT:
1644 RETVAL
1645
1646
15371647
15381648
15391649 BerkeleyDB::Env::Raw
15441654 {
15451655 HV * hash ;
15461656 SV * sv ;
1657 char * enc_passwd = NULL ;
1658 int enc_flags = 0 ;
15471659 char * home = NULL ;
15481660 char * errfile = NULL ;
15491661 char * server = NULL ;
15591671 Trace(("in _db_appinit [%s] %d\n", self, ref)) ;
15601672 hash = (HV*) SvRV(ref) ;
15611673 SetValue_pv(home, "Home", char *) ;
1674 SetValue_pv(enc_passwd,"Enc_Passwd", char *) ;
1675 SetValue_iv(enc_flags, "Enc_Flags") ;
15621676 SetValue_pv(config, "Config", char **) ;
15631677 SetValue_sv(errprefix, "ErrPrefix") ;
15641678 SetValue_iv(flags, "Flags") ;
15741688 if (server)
15751689 softCrash("-Server needs Berkeley DB 3.1 or better") ;
15761690 #endif /* ! AT_LEAST_DB_3_1 */
1691 #ifndef AT_LEAST_DB_4_1
1692 if (enc_passwd)
1693 softCrash("-Encrypt needs Berkeley DB 4.x or better") ;
1694 #endif /* ! AT_LEAST_DB_4_1 */
15771695 Trace(("_db_appinit(config=[%d], home=[%s],errprefix=[%s],flags=[%d]\n",
15781696 config, home, errprefix, flags)) ;
15791697 #ifdef TRACE
16131731 SetValue_iv(env->db_verbose, "Verbose") ;
16141732 env->db_errcall = db_errcall_cb ;
16151733 RETVAL->active = TRUE ;
1734 RETVAL->opened = TRUE;
1735 RETVAL->cdb_enabled = (flags & DB_INIT_CDB != 0 ? TRUE : FALSE) ;
16161736 status = db_appinit(home, config, env, flags) ;
1737 printf(" status = %d errno %d \n", status, errno) ;
16171738 Trace((" status = %d env %d Env %d\n", status, RETVAL, env)) ;
16181739 if (status == 0)
16191740 hash_store_iv("BerkeleyDB::Term::Env", (char *)RETVAL, 1) ;
16491770 Trace(("set_lk_detect [%d] returned %s\n",
16501771 lk_detect, my_db_strerror(status)));
16511772 }
1773 #ifdef AT_LEAST_DB_4_1
1774 /* set encryption */
1775 if (enc_passwd && status == 0)
1776 {
1777 status = env->set_encrypt(env, enc_passwd, enc_flags);
1778 Trace(("ENV->set_encrypt passwd = %s, flags %d returned %s\n",
1779 enc_passwd, enc_flags,
1780 my_db_strerror(status))) ;
1781 }
1782 #endif
16521783 #ifdef AT_LEAST_DB_4
16531784 /* set the server */
16541785 if (server && status == 0)
16991830 SetValue_iv(mode, "Mode") ;
17001831 env->set_errcall(env, db_errcall_cb) ;
17011832 RETVAL->active = TRUE ;
1833 RETVAL->cdb_enabled = (flags & DB_INIT_CDB != 0 ? TRUE : FALSE) ;
17021834 #ifdef IS_DB_3_0_x
17031835 status = (env->open)(env, home, config, flags, mode) ;
17041836 #else /* > 3.0 */
17051837 status = (env->open)(env, home, flags, mode) ;
17061838 #endif
1839 Trace(("ENV->open(env=%s,home=%s,flags=%d,mode=%d)\n",env,home,flags,mode)) ;
17071840 Trace(("ENV->open returned %s\n", my_db_strerror(status))) ;
17081841 }
17091842
17191852 RETVAL = NULL ;
17201853 }
17211854 #endif /* DB_VERSION_MAJOR > 2 */
1855 {
1856 SV * sv_err = perl_get_sv(ERR_BUFF, FALSE);
1857 sv_setpv(sv_err, db_strerror(status));
1858 }
17221859 }
17231860 OUTPUT:
17241861 RETVAL
1862
1863 DB_ENV*
1864 DB_ENV(env)
1865 BerkeleyDB::Env env
1866 CODE:
1867 if (env->active)
1868 RETVAL = env->Env ;
1869 else
1870 RETVAL = NULL;
1871
17251872
17261873 void
17271874 log_archive(env, flags=0)
20352182 #ifndef AT_LEAST_DB_3_1
20362183 softCrash("$env->set_data_dir needs Berkeley DB 3.1 or better") ;
20372184 #else
2185 dieIfEnvOpened(env, "set_data_dir");
20382186 RETVAL = env->Status = env->Env->set_data_dir(env->Env, dir);
20392187 #endif
20402188 OUTPUT:
21402288 int mode = 0 ;
21412289 BerkeleyDB db ;
21422290 BerkeleyDB__Txn txn = NULL ;
2291 char * enc_passwd = NULL ;
2292 int enc_flags = 0 ;
21432293
21442294 Trace(("_db_open_hash start\n")) ;
21452295 hash = (HV*) SvRV(ref) ;
21502300 ref_dbenv = sv ;
21512301 SetValue_iv(flags, "Flags") ;
21522302 SetValue_iv(mode, "Mode") ;
2303 SetValue_pv(enc_passwd,"Enc_Passwd", char *) ;
2304 SetValue_iv(enc_flags, "Enc_Flags") ;
21532305
21542306 Zero(&info, 1, DB_INFO) ;
21552307 SetValue_iv(info.db_cachesize, "Cachesize") ;
21732325 croak("DupCompare needs Berkeley DB 2.5.9 or later") ;
21742326 #endif
21752327 }
2176 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_HASH, flags, mode, &info) ;
2328 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_HASH, flags, mode, &info, enc_passwd, enc_flags) ;
21772329 Trace(("_db_open_hash end\n")) ;
21782330 }
21792331 OUTPUT:
22532405 BerkeleyDB RETVAL ;
22542406 BerkeleyDB__Txn txn = NULL ;
22552407 static char * Names[] = {"", "Btree", "Hash", "Recno"} ;
2408 char * enc_passwd = NULL ;
2409 int enc_flags = 0 ;
22562410
22572411 hash = (HV*) SvRV(ref) ;
22582412 SetValue_pv(file, "Filename", char *) ;
22622416 ref_dbenv = sv ;
22632417 SetValue_iv(flags, "Flags") ;
22642418 SetValue_iv(mode, "Mode") ;
2419 SetValue_pv(enc_passwd,"Enc_Passwd", char *) ;
2420 SetValue_iv(enc_flags, "Enc_Flags") ;
22652421
22662422 Zero(&info, 1, DB_INFO) ;
22672423 SetValue_iv(info.db_cachesize, "Cachesize") ;
22722428 SetValue_iv(info.flags, "Property") ;
22732429 ZMALLOC(db, BerkeleyDB_type) ;
22742430
2275 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_UNKNOWN, flags, mode, &info) ;
2431 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_UNKNOWN, flags, mode, &info, enc_passwd, enc_flags) ;
22762432 XPUSHs(sv_2mortal(newSViv(PTR2IV(RETVAL))));
22772433 if (RETVAL)
22782434 XPUSHs(sv_2mortal(newSVpv(Names[RETVAL->type], 0))) ;
23012457 int mode = 0 ;
23022458 BerkeleyDB db ;
23032459 BerkeleyDB__Txn txn = NULL ;
2460 char * enc_passwd = NULL ;
2461 int enc_flags = 0 ;
23042462
23052463 Trace(("In _db_open_btree\n"));
23062464 hash = (HV*) SvRV(ref) ;
23112469 ref_dbenv = sv ;
23122470 SetValue_iv(flags, "Flags") ;
23132471 SetValue_iv(mode, "Mode") ;
2472 SetValue_pv(enc_passwd,"Enc_Passwd", char *) ;
2473 SetValue_iv(enc_flags, "Enc_Flags") ;
23142474
23152475 Zero(&info, 1, DB_INFO) ;
23162476 SetValue_iv(info.db_cachesize, "Cachesize") ;
23412501 db->prefix = newSVsv(sv) ;
23422502 }
23432503
2344 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_BTREE, flags, mode, &info) ;
2504 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_BTREE, flags, mode, &info, enc_passwd, enc_flags) ;
23452505 }
23462506 OUTPUT:
23472507 RETVAL
24312591 int mode = 0 ;
24322592 BerkeleyDB db ;
24332593 BerkeleyDB__Txn txn = NULL ;
2594 char * enc_passwd = NULL ;
2595 int enc_flags = 0 ;
24342596
24352597 hash = (HV*) SvRV(ref) ;
24362598 SetValue_pv(file, "Fname", char*) ;
2599 SetValue_pv(subname, "Subname", char *) ;
24372600 SetValue_ov(dbenv, "Env", BerkeleyDB__Env) ;
24382601 ref_dbenv = sv ;
24392602 SetValue_ov(txn, "Txn", BerkeleyDB__Txn) ;
24402603 SetValue_iv(flags, "Flags") ;
24412604 SetValue_iv(mode, "Mode") ;
2605 SetValue_pv(enc_passwd,"Enc_Passwd", char *) ;
2606 SetValue_iv(enc_flags, "Enc_Flags") ;
24422607
24432608 Zero(&info, 1, DB_INFO) ;
24442609 SetValue_iv(info.db_cachesize, "Cachesize") ;
24662631 db->array_base = (db->array_base == 0 ? 1 : 0) ;
24672632 #endif /* ALLOW_RECNO_OFFSET */
24682633
2469 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_RECNO, flags, mode, &info) ;
2634 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_RECNO, flags, mode, &info, enc_passwd, enc_flags) ;
24702635 }
24712636 OUTPUT:
24722637 RETVAL
24942659 int mode = 0 ;
24952660 BerkeleyDB db ;
24962661 BerkeleyDB__Txn txn = NULL ;
2662 char * enc_passwd = NULL ;
2663 int enc_flags = 0 ;
24972664
24982665 hash = (HV*) SvRV(ref) ;
24992666 SetValue_pv(file, "Fname", char*) ;
2667 SetValue_pv(subname, "Subname", char *) ;
25002668 SetValue_ov(dbenv, "Env", BerkeleyDB__Env) ;
25012669 ref_dbenv = sv ;
25022670 SetValue_ov(txn, "Txn", BerkeleyDB__Txn) ;
25032671 SetValue_iv(flags, "Flags") ;
25042672 SetValue_iv(mode, "Mode") ;
2673 SetValue_pv(enc_passwd,"Enc_Passwd", char *) ;
2674 SetValue_iv(enc_flags, "Enc_Flags") ;
25052675
25062676 Zero(&info, 1, DB_INFO) ;
25072677 SetValue_iv(info.db_cachesize, "Cachesize") ;
25262696 db->array_base = (db->array_base == 0 ? 1 : 0) ;
25272697 #endif /* ALLOW_RECNO_OFFSET */
25282698
2529 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_QUEUE, flags, mode, &info) ;
2699 RETVAL = my_db_open(db, ref, ref_dbenv, dbenv, txn, file, subname, DB_QUEUE, flags, mode, &info, enc_passwd, enc_flags) ;
25302700 #endif
25312701 }
25322702 OUTPUT:
25912761 BerkeleyDB::Common db
25922762 INIT:
25932763 ckActive_Database(db->active) ;
2594 CurrentDB = db ;
2764 saveCurrentDB(db) ;
25952765 CODE:
25962766 Trace(("BerkeleyDB::Common::db_close %d\n", db));
25972767 #ifdef STRICT_CLOSE
26152785 dab__DESTROY(db)
26162786 BerkeleyDB::Common db
26172787 CODE:
2618 CurrentDB = db ;
2788 saveCurrentDB(db) ;
26192789 Trace(("In BerkeleyDB::Common::_DESTROY db %d dirty=%d\n", db, PL_dirty)) ;
26202790 destroyDB(db) ;
26212791 Trace(("End of BerkeleyDB::Common::DESTROY \n")) ;
26302800 u_int32_t flags
26312801 BerkeleyDB::Common db
26322802 BerkeleyDB::Cursor RETVAL = NULL ;
2803 ALIAS: __db_write_cursor = 1
26332804 INIT:
26342805 ckActive_Database(db->active) ;
26352806 CODE:
26362807 {
2637 DBC * cursor ;
2638 CurrentDB = db ;
2808 DBC * cursor ;
2809 saveCurrentDB(db) ;
2810 if (ix == 1 && db->cdb_enabled) {
2811 #ifdef AT_LEAST_DB_3
2812 flags = DB_WRITECURSOR;
2813 #else
2814 flags = DB_RMW;
2815 #endif
2816 }
26392817 if ((db->Status = db_cursor(db, db->txn, &cursor, flags)) == 0){
26402818 ZMALLOC(RETVAL, BerkeleyDB__Cursor_type) ;
26412819 db->open_cursors ++ ;
26452823 RETVAL->txn = db->txn ;
26462824 RETVAL->type = db->type ;
26472825 RETVAL->recno_or_queue = db->recno_or_queue ;
2826 RETVAL->cdb_enabled = db->cdb_enabled ;
26482827 RETVAL->filename = my_strdup(db->filename) ;
26492828 RETVAL->compare = db->compare ;
26502829 RETVAL->dup_compare = db->dup_compare ;
26922871 DBC ** cursor_list ;
26932872 I32 count = av_len(cursors) + 1 ;
26942873 int i ;
2695 CurrentDB = db ;
2874 saveCurrentDB(db) ;
26962875 if (count < 1 )
26972876 softCrash("db_join: No cursors in parameter list") ;
26982877 cursor_list = (DBC **)safemalloc(sizeof(DBC*) * (count + 1));
27002879 SV * obj = (SV*) * av_fetch(cursors, i, FALSE) ;
27012880 IV tmp = SvIV(getInnerObject(obj)) ;
27022881 BerkeleyDB__Cursor cur = INT2PTR(BerkeleyDB__Cursor, tmp);
2882 if (cur->dbp == db->dbp)
2883 softCrash("attempted to do a self-join");
27032884 cursor_list[i] = cur->cursor ;
27042885 }
27052886 cursor_list[i] = NULL ;
28983079 INIT:
28993080 Trace(("db_del db[%p] in [%p] txn[%p] key[%.*s] flags[%d]\n", db->dbp, db, db->txn, key.size, key.data, flags)) ;
29003081 ckActive_Database(db->active) ;
2901 CurrentDB = db ;
3082 saveCurrentDB(db) ;
29023083
29033084
29043085 #ifdef AT_LEAST_DB_3
29203101 DBT_OPT data
29213102 CODE:
29223103 ckActive_Database(db->active) ;
2923 CurrentDB = db ;
3104 saveCurrentDB(db) ;
29243105 SetPartial(data,db) ;
29253106 Trace(("db_get db[%p] in [%p] txn[%p] key [%.*s] flags[%d]\n", db->dbp, db, db->txn, key.size, key.data, flags)) ;
29263107 RETVAL = db_get(db, key, data, flags);
29453126 #else
29463127 Trace(("db_pget db [%p] in [%p] txn [%p] flags [%d]\n", db->dbp, db, db->txn, flags)) ;
29473128 ckActive_Database(db->active) ;
2948 CurrentDB = db ;
3129 saveCurrentDB(db) ;
29493130 SetPartial(data,db) ;
29503131 DBT_clear(pkey);
29513132 RETVAL = db_pget(db, key, pkey, data, flags);
29673148 DBT data
29683149 CODE:
29693150 ckActive_Database(db->active) ;
2970 CurrentDB = db ;
3151 saveCurrentDB(db) ;
29713152 /* SetPartial(data,db) ; */
29723153 Trace(("db_put db[%p] in [%p] txn[%p] key[%.*s] data [%.*s] flags[%d]\n", db->dbp, db, db->txn, key.size, key.data, data.size, data.data, flags)) ;
29733154 RETVAL = db_put(db, key, data, flags);
29943175 DB_KEY_RANGE range ;
29953176 range.less = range.equal = range.greater = 0.0 ;
29963177 ckActive_Database(db->active) ;
2997 CurrentDB = db ;
3178 saveCurrentDB(db) ;
29983179 RETVAL = db_key_range(db, key, range, flags);
29993180 if (RETVAL == 0) {
30003181 less = range.less ;
30173198 INIT:
30183199 ckActive_Database(db->active) ;
30193200 CODE:
3020 CurrentDB = db ;
3201 saveCurrentDB(db) ;
30213202 db_fd(db, RETVAL) ;
30223203 OUTPUT:
30233204 RETVAL
30303211 BerkeleyDB::Common db
30313212 INIT:
30323213 ckActive_Database(db->active) ;
3033 CurrentDB = db ;
3214 saveCurrentDB(db) ;
30343215
30353216 void
30363217 _Txn(db, txn=NULL)
30633244 #ifndef AT_LEAST_DB_3_3
30643245 softCrash("truncate needs Berkeley DB 3.3 or later") ;
30653246 #else
3066 CurrentDB = db ;
3247 saveCurrentDB(db) ;
30673248 RETVAL = db_truncate(db, countp, flags);
30683249 #endif
30693250 OUTPUT:
30893270 #ifndef AT_LEAST_DB_3_3
30903271 softCrash("associate needs Berkeley DB 3.3 or later") ;
30913272 #else
3092 CurrentDB = db ;
3273 saveCurrentDB(db) ;
30933274 /* db->associated = newSVsv(callback) ; */
30943275 secondary->associated = newSVsv(callback) ;
30953276 /* secondary->dbp->app_private = secondary->associated ; */
31083289 BerkeleyDB::Cursor db
31093290 BerkeleyDB::Cursor RETVAL = NULL ;
31103291 INIT:
3111 CurrentDB = db->parent_db ;
3292 saveCurrentDB(db->parent_db);
31123293 ckActive_Database(db->active) ;
31133294 CODE:
31143295 {
31253306 RETVAL->dbp = db->dbp ;
31263307 RETVAL->type = db->type ;
31273308 RETVAL->recno_or_queue = db->recno_or_queue ;
3309 RETVAL->cdb_enabled = db->cdb_enabled ;
31283310 RETVAL->filename = my_strdup(db->filename) ;
31293311 RETVAL->compare = db->compare ;
31303312 RETVAL->dup_compare = db->dup_compare ;
31593341 _c_close(db)
31603342 BerkeleyDB::Cursor db
31613343 INIT:
3162 CurrentDB = db->parent_db ;
3344 saveCurrentDB(db->parent_db);
31633345 ckActive_Cursor(db->active) ;
31643346 hash_delete("BerkeleyDB::Term::Cursor", (char *)db) ;
31653347 CODE:
31753357 _DESTROY(db)
31763358 BerkeleyDB::Cursor db
31773359 CODE:
3178 CurrentDB = db->parent_db ;
3360 saveCurrentDB(db->parent_db);
31793361 Trace(("In BerkeleyDB::Cursor::_DESTROY db %d dirty=%d active=%d\n", db, PL_dirty, db->active));
31803362 hash_delete("BerkeleyDB::Term::Cursor", (char *)db) ;
31813363 if (db->active)
32013383 int flags
32023384 BerkeleyDB::Cursor db
32033385 INIT:
3204 CurrentDB = db->parent_db ;
3386 saveCurrentDB(db->parent_db);
32053387 ckActive_Cursor(db->active) ;
32063388 OUTPUT:
32073389 RETVAL
32123394 cu_c_get(db, key, data, flags=0)
32133395 int flags
32143396 BerkeleyDB::Cursor db
3215 DBTKEY_B key
3216 DBT_B data
3397 DBTKEY_B key
3398 DBT_B data
32173399 INIT:
32183400 Trace(("c_get db [%p] in [%p] flags [%d]\n", db->dbp, db, flags)) ;
3219 CurrentDB = db->parent_db ;
3401 saveCurrentDB(db->parent_db);
32203402 ckActive_Cursor(db->active) ;
3403 /* DBT_clear(key); */
3404 /* DBT_clear(data); */
32213405 SetPartial(data,db) ;
32223406 Trace(("c_get end\n")) ;
32233407 OUTPUT:
32383422 softCrash("db_c_pget needs at least Berkeley DB 3.3");
32393423 #else
32403424 Trace(("c_pget db [%d] flags [%d]\n", db, flags)) ;
3241 CurrentDB = db->parent_db ;
3425 saveCurrentDB(db->parent_db);
32423426 ckActive_Cursor(db->active) ;
32433427 SetPartial(data,db) ;
32443428 DBT_clear(pkey);
32493433 RETVAL
32503434 key
32513435 pkey
3252 data if (! flagSet(DB_JOIN_ITEM)) OutputValue_B(ST(2), data) ;
3436 data
32533437
32543438
32553439
32613445 DBTKEY key
32623446 DBT data
32633447 INIT:
3264 CurrentDB = db->parent_db ;
3448 saveCurrentDB(db->parent_db);
32653449 ckActive_Cursor(db->active) ;
32663450 /* SetPartial(data,db) ; */
32673451 OUTPUT:
32783462 softCrash("c_count needs at least Berkeley DB 3.1.x");
32793463 #else
32803464 Trace(("c_get count [%d] flags [%d]\n", db, flags)) ;
3281 CurrentDB = db->parent_db ;
3465 saveCurrentDB(db->parent_db);
32823466 ckActive_Cursor(db->active) ;
32833467 RETVAL = cu_c_count(db, count, flags) ;
32843468 Trace((" c_count got %d duplicates\n", count)) ;
35483732 restore at the end.
35493733
35503734 */
3551 CurrentDB = db ;
3735 saveCurrentDB(db) ;
35523736 DBT_clear(key) ;
35533737 DBT_clear(value) ;
35543738 /* If necessary create a cursor for FIRSTKEY/NEXTKEY use */
35803764 {
35813765 DBT value ;
35823766
3583 CurrentDB = db ;
3767 saveCurrentDB(db) ;
35843768 DBT_clear(key) ;
35853769 DBT_clear(value) ;
35863770 key.flags = 0 ;
36023786 FETCHSIZE(db)
36033787 BerkeleyDB::Common db
36043788 CODE:
3605 CurrentDB = db ;
3789 saveCurrentDB(db) ;
36063790 RETVAL = GetArrayLength(db) ;
36073791 OUTPUT:
36083792 RETVAL
00 Revision history for Perl extension BerkeleyDB.
1
2 0.23 15th June 2003
3
4 * Fixed problem where a secondary index would use the same
5 compare callback as the primary key, regardless of what was
6 defined for the secondary index.
7 Problem spotted by Dave Tallman.
8
9 * Also fixed a problem with the associate callback. If the value
10 for the secondary key was not a string, the secondary key was
11 being set incorrectly. This is now fixed.
12
13 * When built with Berkeley DB 3.2 or better, all callbacks now use
14 the BackRef pointer instead of the global CurrentDB. This was
15 done partially to fix the secondary index problem, above.
16
17 * The test harness was failing under cygwin. Now fixed.
18
19 * Previous release broke TRACE. Fixed.
20
21 0.22 17th May 2003
22
23 * win32 problem with open macro fixed.
24
25 0.21 12th May 2003
26
27 * adding support for env->set_flags
28 * adding recursion detection
29 * win32 problem with rename fixed.
30 * problem with sub-database name in Recno & Queue fixed.
31 * fixed the mldbm.t test harness to work with perl 5.8.0
32 * added a note about not using a network drive when running the
33 test harness.
34 * fixed c_pget
35 * added BerkeleyDB::Env::DB_ENV method
36 * added support for encryption
37 * the dbinfo script will now indicate if the database is encrypted
38 * The CLEAR method is now CDB safe.
139
240 0.20 2nd September 2002
341
2323 t/db-3.2.t
2424 t/db-3.3.t
2525 t/destroy.t
26 t/encrypt.t
2627 t/env.t
2728 t/examples.t
2829 t/examples.t.T
114114
115115 $INC_DIR = $ENV{'BERKELEYDB_INCLUDE'} || $Info{'INCLUDE'} ;
116116 $LIB_DIR = $ENV{'BERKELEYDB_LIB'} || $Info{'LIB'} ;
117 $DB_NAME = $Info{'DBNAME'} if defined $Info{'DBNAME'} ;
117 $DB_NAME = $ENV{BERKELEYDB_NAME} || $Info{'DBNAME'} ;
118 #$DB_NAME = $ENV{} || $Info{'DBNAME'} if defined $Info{'DBNAME'} ;
119
118120 print "Looks Good.\n" ;
119121
120122 }
00 BerkeleyDB
11
2 Version 0.20
3
4 2nd Sept 2002
5
6 Copyright (c) 1997-2002 Paul Marquess. All rights reserved. This
2 Version 0.23
3
4 15th June 2003
5
6 Copyright (c) 1997-2003 Paul Marquess. All rights reserved. This
77 program is free software; you can redistribute it and/or modify
88 it under the same terms as Perl itself.
99
2929 Before you can build BerkeleyDB you need to have the following
3030 installed on your system:
3131
32 * To run the test harness for this module, you must make sure that the
33 directory where you have untarred this module is NOT a network
34 drive, e.g. NFS or AFS.
35
3236 * Perl 5.004_04 or greater.
3337
3438 * Berkeley DB Version 2.6.4 or greater
5559 the Solaris Notes or HP-UX Notes sections below.
5660 If you are running Linux please read the Linux Notes section
5761 before proceeding.
58
5962
6063 Step 2 : Edit the file config.in to suit you local installation.
6164 Instructions are given in the file.
278281 If you are running Linux, please read the Linux Notes section below.
279282
280283
284
285 Solaris build fails with "language optional software package not installed"
286 ---------------------------------------------------------------------------
287
288 If you are trying to build this module under Solaris and you get an
289 error message like this
290
291 /usr/ucb/cc: language optional software package not installed
292
293 it means that Perl cannot find the C compiler on your system. The cryptic
294 message is just Sun's way of telling you that you haven't bought their
295 C compiler.
296
297 When you build a Perl module that needs a C compiler, the Perl build
298 system tries to use the same C compiler that was used to build perl
299 itself. In this case your Perl binary was built with a C compiler that
300 lived in /usr/ucb.
301
302 To continue with building this module, you need to get a C compiler,
303 or tell Perl where your C compiler is, if you already have one.
304
305 Assuming you have now got a C compiler, what you do next will be dependant
306 on what C compiler you have installed. If you have just installed Sun's
307 C compiler, you shouldn't have to do anything. Just try rebuilding
308 this module.
309
310 If you have installed another C compiler, say gcc, you have to tell perl
311 how to use it instead of /usr/ucb/cc.
312
313 This set of options seems to work if you want to use gcc. Your mileage
314 may vary.
315
316 perl Makefile.PL CC=gcc CCCDLFLAGS=-fPIC OPTIMIZE=" "
317 make test
318
319 If that doesn't work for you, it's time to make changes to the Makefile
320 by hand. Good luck!
321
322
323 Network Drive
324 -------------
325
326 BerkeleyDB seems to have built correctly, but you get a series of errors
327 like this when you run the test harness:
328
329
330 t/btree........NOK 178Can't call method "txn_begin" on an undefined value at t/btree.t line 637.
331 t/btree........dubious
332 Test returned status 11 (wstat 2816, 0xb00)
333 DIED. FAILED tests 28, 178-244
334 Failed 68/244 tests, 72.13% okay
335 t/db-3.0.......NOK 2Can't call method "set_mutexlocks" on an undefined value at t/db-3.0.t line 39.
336 t/db-3.0.......dubious
337 Test returned status 11 (wstat 2816, 0xb00)
338 DIED. FAILED tests 2-14
339 Failed 13/14 tests, 7.14% okay
340 t/db-3.1.......ok
341 t/db-3.2.......NOK 5Can't call method "set_flags" on an undefined value at t/db-3.2.t line 62.
342 t/db-3.2.......dubious
343 Test returned status 11 (wstat 2816, 0xb00)
344 DIED. FAILED tests 3, 5-6
345 Failed 3/6 tests, 50.00% okay
346 t/db-3.3.......ok
347
348 This pattern of errors happens if you have built the module in a directory
349 that is network mounted (e.g. NFS ar AFS).
350
351 The solution is to use a local drive. Berkeley DB doesn't support
352 network drives.
353
354
281355 Linux Notes
282356 -----------
283357
284 Newer versions of Linux (e.g. RedHat 6, SuSe 6) ship with a C library
358 Some versions of Linux (e.g. RedHat 6, SuSe 6) ship with a C library
285359 that has version 2.x of Berkeley DB linked into it. This makes it
286360 difficult to build this module with anything other than the version of
287361 Berkeley DB that shipped with your Linux release. If you do try to use
385459 To find out if you have the patch installed, the command "showrev -p"
386460 will display the patches that are currently installed on your system.
387461
462
388463 Solaris 2.7 Notes
389464 -----------------
390465
66 # Change the path below to point to the directory where db.h is
77 # installed on your system.
88
9 INCLUDE = /usr/local/include
10 #INCLUDE = /usr/local/BerkeleyDB/include
9 #INCLUDE = /usr/local/include
10 INCLUDE = /usr/local/BerkeleyDB/include
1111
1212 # 2. Where is libdb?
1313 #
1414 # Change the path below to point to the directory where libdb is
1515 # installed on your system.
1616
17 LIB = /usr/local/lib
18 #LIB = /usr/local/BerkeleyDB/lib
17 #LIB = /usr/local/lib
18 LIB = /usr/local/BerkeleyDB/lib
1919
2020 # 3. Is the library called libdb?
2121 #
33 # a database file
44 #
55 # Author: Paul Marquess <Paul.Marquess@btinternet.com>
6 # Version: 1.03
7 # Date 17th September 2000
6 # Version: 1.04
7 # Date 7th April 2003
88 #
9 # Copyright (c) 1998-2002 Paul Marquess. All rights reserved.
9 # Copyright (c) 1998-2003 Paul Marquess. All rights reserved.
1010 # This program is free software; you can redistribute it and/or
1111 # modify it under the same terms as Perl itself.
1212
2121 Type => "Btree",
2222 Versions =>
2323 {
24 1 => "Unknown (older than 1.71)",
25 2 => "Unknown (older than 1.71)",
26 3 => "1.71 -> 1.85, 1.86",
27 4 => "Unknown",
28 5 => "2.0.0 -> 2.3.0",
29 6 => "2.3.1 -> 2.7.7",
30 7 => "3.0.x",
31 8 => "3.1.x -> 4.0.x",
32 9 => "4.1.x or greater",
24 1 => [0, "Unknown (older than 1.71)"],
25 2 => [0, "Unknown (older than 1.71)"],
26 3 => [0, "1.71 -> 1.85, 1.86"],
27 4 => [0, "Unknown"],
28 5 => [0, "2.0.0 -> 2.3.0"],
29 6 => [0, "2.3.1 -> 2.7.7"],
30 7 => [0, "3.0.x"],
31 8 => [0, "3.1.x -> 4.0.x"],
32 9 => [1, "4.1.x or greater"],
3333 }
3434 },
3535 0x061561 => {
3636 Type => "Hash",
3737 Versions =>
3838 {
39 1 => "Unknown (older than 1.71)",
40 2 => "1.71 -> 1.85",
41 3 => "1.86",
42 4 => "2.0.0 -> 2.1.0",
43 5 => "2.2.6 -> 2.7.7",
44 6 => "3.0.x",
45 7 => "3.1.x -> 4.0.x",
46 8 => "4.1.x or greater",
39 1 => [0, "Unknown (older than 1.71)"],
40 2 => [0, "1.71 -> 1.85"],
41 3 => [0, "1.86"],
42 4 => [0, "2.0.0 -> 2.1.0"],
43 5 => [0, "2.2.6 -> 2.7.7"],
44 6 => [0, "3.0.x"],
45 7 => [0, "3.1.x -> 4.0.x"],
46 8 => [1, "4.1.x or greater"],
4747 }
4848 },
4949 0x042253 => {
5050 Type => "Queue",
5151 Versions =>
5252 {
53 1 => "3.0.x",
54 2 => "3.1.x",
55 3 => "3.2.x -> 4.0.x",
56 4 => "4.1.x or greater",
53 1 => [0, "3.0.x"],
54 2 => [0, "3.1.x"],
55 3 => [0, "3.2.x -> 4.0.x"],
56 4 => [1, "4.1.x or greater"],
5757 }
5858 },
5959 ) ;
6464 open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ;
6565
6666 my $buff ;
67 read F, $buff, 20 ;
67 read F, $buff, 30 ;
6868
69 my (@info) = unpack("NNNNN", $buff) ;
70 my (@info1) = unpack("VVVVV", $buff) ;
71 my ($magic, $version, $endian) ;
69 my (@info) = unpack("NNNNNNC", $buff) ;
70 my (@info1) = unpack("VVVVVVC", $buff) ;
71 my ($magic, $version, $endian, $encrypt) ;
7272
7373 if ($Data{$info[0]}) # first try DB 1.x format
7474 {
7575 $magic = $info[0] ;
7676 $version = $info[1] ;
7777 $endian = "Unknown" ;
78 $encrypt = "Not Supported";
7879 }
7980 elsif ($Data{$info[3]}) # next DB 2.x big endian
8081 {
9596 $magic = sprintf "%06X", $magic ;
9697
9798 my $ver_string = "Unknown" ;
98 $ver_string = $type->{Versions}{$version}
99 if defined $type->{Versions}{$version} ;
99
100 if ( defined $type->{Versions}{$version} )
101 {
102 $ver_string = $type->{Versions}{$version}[1];
103 if ($type->{Versions}{$version}[0] )
104 { $encrypt = $info[6] ? "Enabled" : "Disabled" }
105 else
106 { $encrypt = "Not Supported" }
107 }
100108
101109 print <<EOM ;
102110 File Type: Berkeley DB $type->{Type} file.
104112 Built with Berkeley DB: $ver_string
105113 Byte Order: $endian
106114 Magic: $magic
115 Encryption: $encrypt
107116 EOM
108117
109118 close F ;
0 diff perl5.004.orig/Configure perl5.004/Configure
1 190a191
2 > perllibs=''
3 9904a9906,9913
4 > : Remove libraries needed only for extensions
5 > : The appropriate ext/Foo/Makefile.PL will add them back in, if
6 > : necessary.
7 > set X `echo " $libs " |
8 > sed -e 's@ -lndbm @ @' -e 's@ -lgdbm @ @' -e 's@ -ldbm @ @' -e 's@ -ldb @ @'`
9 > shift
10 > perllibs="$*"
11 >
12 10372a10382
13 > perllibs='$perllibs'
14 diff perl5.004.orig/Makefile.SH perl5.004/Makefile.SH
15 122c122
16 < libs = $libs $cryptlib
17 ---
18 > libs = $perllibs $cryptlib
19 Common subdirectories: perl5.004.orig/Porting and perl5.004/Porting
20 Common subdirectories: perl5.004.orig/cygwin32 and perl5.004/cygwin32
21 Common subdirectories: perl5.004.orig/eg and perl5.004/eg
22 Common subdirectories: perl5.004.orig/emacs and perl5.004/emacs
23 Common subdirectories: perl5.004.orig/ext and perl5.004/ext
24 Common subdirectories: perl5.004.orig/h2pl and perl5.004/h2pl
25 Common subdirectories: perl5.004.orig/hints and perl5.004/hints
26 Common subdirectories: perl5.004.orig/lib and perl5.004/lib
27 diff perl5.004.orig/myconfig perl5.004/myconfig
28 38c38
29 < libs=$libs
30 ---
31 > libs=$perllibs
32 Common subdirectories: perl5.004.orig/os2 and perl5.004/os2
33 diff perl5.004.orig/patchlevel.h perl5.004/patchlevel.h
34 40a41
35 > ,"NODB-1.0 - remove -ldb from core perl binary."
36 Common subdirectories: perl5.004.orig/plan9 and perl5.004/plan9
37 Common subdirectories: perl5.004.orig/pod and perl5.004/pod
38 Common subdirectories: perl5.004.orig/qnx and perl5.004/qnx
39 Common subdirectories: perl5.004.orig/t and perl5.004/t
40 Common subdirectories: perl5.004.orig/utils and perl5.004/utils
41 Common subdirectories: perl5.004.orig/vms and perl5.004/vms
42 Common subdirectories: perl5.004.orig/win32 and perl5.004/win32
43 Common subdirectories: perl5.004.orig/x2p and perl5.004/x2p
0 diff -rc perl5.004.orig/Configure perl5.004/Configure
1 *** perl5.004.orig/Configure 1997-05-13 18:20:34.000000000 +0100
2 --- perl5.004/Configure 2003-04-26 16:36:53.000000000 +0100
3 ***************
4 *** 188,193 ****
5 --- 188,194 ----
6 mv=''
7 nroff=''
8 perl=''
9 + perllibs=''
10 pg=''
11 pmake=''
12 pr=''
13 ***************
14 *** 9902,9907 ****
15 --- 9903,9916 ----
16 shift
17 extensions="$*"
18
19 + : Remove libraries needed only for extensions
20 + : The appropriate ext/Foo/Makefile.PL will add them back in, if
21 + : necessary.
22 + set X `echo " $libs " |
23 + sed -e 's@ -lndbm @ @' -e 's@ -lgdbm @ @' -e 's@ -ldbm @ @' -e 's@ -ldb @ @'`
24 + shift
25 + perllibs="$*"
26 +
27 : Remove build directory name from cppstdin so it can be used from
28 : either the present location or the final installed location.
29 echo " "
30 ***************
31 *** 10370,10375 ****
32 --- 10379,10385 ----
33 patchlevel='$patchlevel'
34 path_sep='$path_sep'
35 perl='$perl'
36 + perllibs='$perllibs'
37 perladmin='$perladmin'
38 perlpath='$perlpath'
39 pg='$pg'
40 diff -rc perl5.004.orig/Makefile.SH perl5.004/Makefile.SH
41 *** perl5.004.orig/Makefile.SH 1997-05-01 15:22:39.000000000 +0100
42 --- perl5.004/Makefile.SH 2003-04-26 16:37:23.000000000 +0100
43 ***************
44 *** 119,125 ****
45 ext = \$(dynamic_ext) \$(static_ext)
46 DYNALOADER = lib/auto/DynaLoader/DynaLoader\$(LIB_EXT)
47
48 ! libs = $libs $cryptlib
49
50 public = perl $suidperl utilities translators
51
52 --- 119,125 ----
53 ext = \$(dynamic_ext) \$(static_ext)
54 DYNALOADER = lib/auto/DynaLoader/DynaLoader\$(LIB_EXT)
55
56 ! libs = $perllibs $cryptlib
57
58 public = perl $suidperl utilities translators
59
60 diff -rc perl5.004.orig/myconfig perl5.004/myconfig
61 *** perl5.004.orig/myconfig 1996-12-21 01:13:20.000000000 +0000
62 --- perl5.004/myconfig 2003-04-26 16:37:51.000000000 +0100
63 ***************
64 *** 35,41 ****
65 Linker and Libraries:
66 ld='$ld', ldflags ='$ldflags'
67 libpth=$libpth
68 ! libs=$libs
69 libc=$libc, so=$so
70 useshrplib=$useshrplib, libperl=$libperl
71 Dynamic Linking:
72 --- 35,41 ----
73 Linker and Libraries:
74 ld='$ld', ldflags ='$ldflags'
75 libpth=$libpth
76 ! libs=$perllibs
77 libc=$libc, so=$so
78 useshrplib=$useshrplib, libperl=$libperl
79 Dynamic Linking:
80 diff -rc perl5.004.orig/patchlevel.h perl5.004/patchlevel.h
81 *** perl5.004.orig/patchlevel.h 1997-05-15 23:15:17.000000000 +0100
82 --- perl5.004/patchlevel.h 2003-04-26 16:38:11.000000000 +0100
83 ***************
84 *** 38,43 ****
85 --- 38,44 ----
86 */
87 static char *local_patches[] = {
88 NULL
89 + ,"NODB-1.0 - remove -ldb from core perl binary."
90 ,NULL
91 };
92
304304
305305 #define DBM_ckFilter(arg,type,name) \
306306 if (db->type) { \
307 /*printf("Filtering %s\n", name);*/ \
307308 if (db->filtering) { \
308309 croak("recursion detected in %s", name) ; \
309310 } \
312313 SAVEINT(db->filtering) ; \
313314 db->filtering = TRUE ; \
314315 SAVESPTR(DEFSV) ; \
316 if (1 && name[7] == 's') \
317 arg = newSVsv(arg); \
315318 DEFSV = arg ; \
316319 SvTEMP_off(arg) ; \
317320 PUSHMARK(SP) ; \
321324 PUTBACK ; \
322325 FREETMPS ; \
323326 LEAVE ; \
327 if (1 && name[7] == 's'){ \
328 arg = sv_2mortal(arg); \
329 } \
330 SvOKp(arg); \
324331 }
325332
326333 #endif /* DBM_setFilter */
126126 my ($k, $v) ;
127127 ok 33, my $db = new BerkeleyDB::Btree -Filename => $Dfile,
128128 -Flags => DB_CREATE ;
129 print "[$db] [$!] $BerkeleyDB::Error\n" ;
129130
130131 # create some data
131132 my %data = (
2323
2424 umask(0);
2525
26 print "1..37\n";
26 print "1..44\n";
2727
2828 {
2929 # db->truncate
171171
172172 # db->associate -- same again but when DB_DUP is specified.
173173
174
175 {
176 # db->associate -- secondary keys, each with a user defined sort
177
178 sub sec_key2
179 {
180 my $pkey = shift ;
181 my $pdata = shift ;
182 #print "in sec_key2 [$pkey][$pdata]\n";
183
184 $_[0] = length $pdata ;
185 return 0;
186 }
187
188 my ($Dfile1, $Dfile2);
189 my $lex = new LexFile $Dfile1, $Dfile2 ;
190 my %hash ;
191 my $status;
192 my ($k, $v, $pk) = ('','','');
193
194 # create primary database
195 ok 38, my $primary = new BerkeleyDB::Btree -Filename => $Dfile1,
196 -Compare => sub { return $_[0] cmp $_[1]},
197 -Flags => DB_CREATE ;
198
199 # create secondary database
200 ok 39, my $secondary = new BerkeleyDB::Btree -Filename => $Dfile2,
201 -Compare => sub { return $_[0] <=> $_[1]},
202 -Property => DB_DUP,
203 -Flags => DB_CREATE ;
204
205 # associate primary with secondary
206 ok 40, $primary->associate($secondary, \&sec_key2) == 0;
207
208 # add data to the primary
209 my %data = (
210 "red" => "flag",
211 "orange"=> "custard",
212 "green" => "house",
213 "blue" => "sea",
214 ) ;
215
216 my $ret = 0 ;
217 while (($k, $v) = each %data) {
218 my $r = $primary->db_put($k, $v) ;
219 #print "put [$r] $BerkeleyDB::Error\n";
220 $ret += $r;
221 }
222 ok 41, $ret == 0 ;
223 #print "ret $ret\n";
224
225 #print "Primary\n" ; dumpdb($primary) ;
226 #print "Secondary\n" ; dumpdb($secondary) ;
227
228 # check the records in the secondary
229 ok 42, countRecords($secondary) == 4 ;
230
231 my $p_data = joinkeys($primary, " ");
232 #print "primary [$p_data]\n" ;
233 ok 43, $p_data eq join " ", sort { $a cmp $b } keys %data ;
234 my $s_data = joinkeys($secondary, " ");
235 #print "secondary [$s_data]\n" ;
236 ok 44, $s_data eq join " ", sort { $a <=> $b } map { length } values %data ;
237
238 }
239
0 #!./perl -w
1
2 # ID: %I%, %G%
3
4 use strict ;
5
6 BEGIN {
7 unless(grep /blib/, @INC) {
8 chdir 't' if -d 't';
9 @INC = '../lib' if -d '../lib';
10 }
11 }
12
13 use BerkeleyDB;
14 use t::util ;
15
16 BEGIN
17 {
18 if ($BerkeleyDB::db_version < 4.1) {
19 print "1..0 # Skip: this needs Berkeley DB 4.1.x or better\n" ;
20 exit 0 ;
21 }
22
23 # Is encryption available?
24 my $env = new BerkeleyDB::Env
25 -Encrypt => {Password => "abc",
26 Flags => DB_ENCRYPT_AES
27 };
28
29 if ($BerkeleyDB::Error =~ /Operation not supported/)
30 {
31 print "1..0 # Skip: encryption support not present\n" ;
32 exit 0 ;
33 }
34 }
35
36 umask(0);
37
38 print "1..80\n";
39
40 {
41 eval
42 {
43 my $env = new BerkeleyDB::Env
44 -Encrypt => 1,
45 -Flags => DB_CREATE ;
46 };
47 ok 1, $@ =~ /^Encrypt parameter must be a hash reference at/;
48
49 eval
50 {
51 my $env = new BerkeleyDB::Env
52 -Encrypt => {},
53 -Flags => DB_CREATE ;
54 };
55 ok 2, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
56
57 eval
58 {
59 my $env = new BerkeleyDB::Env
60 -Encrypt => {Password => "fred"},
61 -Flags => DB_CREATE ;
62 };
63 ok 3, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
64
65 eval
66 {
67 my $env = new BerkeleyDB::Env
68 -Encrypt => {Flags => 1},
69 -Flags => DB_CREATE ;
70 };
71 ok 4, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
72
73 eval
74 {
75 my $env = new BerkeleyDB::Env
76 -Encrypt => {Fred => 1},
77 -Flags => DB_CREATE ;
78 };
79 ok 5, $@ =~ /^\Qunknown key value(s) Fred at/;
80
81 }
82
83 {
84 # new BerkeleyDB::Env -Encrypt =>
85
86 # create an environment with a Home
87 my $home = "./fred" ;
88 #mkdir $home;
89 ok 6, my $lexD = new LexDir($home) ;
90 ok 7, my $env = new BerkeleyDB::Env
91 -Home => $home,
92 -Encrypt => {Password => "abc",
93 Flags => DB_ENCRYPT_AES
94 },
95 -Flags => DB_CREATE | DB_INIT_MPOOL ;
96
97 print "$BerkeleyDB::Error\n" ;
98
99
100 my $Dfile = "abc.enc";
101 my $lex = new LexFile $Dfile ;
102 my %hash ;
103 my ($k, $v) ;
104 ok 8, my $db = new BerkeleyDB::Hash -Filename => $Dfile,
105 -Env => $env,
106 -Flags => DB_CREATE,
107 -Property => DB_ENCRYPT ;
108
109 # create some data
110 my %data = (
111 "red" => 2,
112 "green" => "house",
113 "blue" => "sea",
114 ) ;
115
116 my $ret = 0 ;
117 while (($k, $v) = each %data) {
118 $ret += $db->db_put($k, $v) ;
119 }
120 ok 9, $ret == 0 ;
121
122 # check there are three records
123 ok 10, countRecords($db) == 3 ;
124
125 undef $db;
126
127 # once the database is created, do not need to specify DB_ENCRYPT
128 ok 11, my $db1 = new BerkeleyDB::Hash -Filename => $Dfile,
129 -Env => $env,
130 -Flags => DB_CREATE ;
131 $v = '';
132 ok 12, ! $db1->db_get("red", $v) ;
133 ok 13, $v eq $data{"red"},
134 undef $db1;
135 undef $env;
136
137 # open a database without specifying encryption
138 ok 14, ! new BerkeleyDB::Hash -Filename => "$home/$Dfile";
139
140 ok 15, ! new BerkeleyDB::Env
141 -Home => $home,
142 -Encrypt => {Password => "def",
143 Flags => DB_ENCRYPT_AES
144 },
145 -Flags => DB_CREATE | DB_INIT_MPOOL ;
146 }
147
148 {
149 eval
150 {
151 my $env = new BerkeleyDB::Hash
152 -Encrypt => 1,
153 -Flags => DB_CREATE ;
154 };
155 ok 16, $@ =~ /^Encrypt parameter must be a hash reference at/;
156
157 eval
158 {
159 my $env = new BerkeleyDB::Hash
160 -Encrypt => {},
161 -Flags => DB_CREATE ;
162 };
163 ok 17, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
164
165 eval
166 {
167 my $env = new BerkeleyDB::Hash
168 -Encrypt => {Password => "fred"},
169 -Flags => DB_CREATE ;
170 };
171 ok 18, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
172
173 eval
174 {
175 my $env = new BerkeleyDB::Hash
176 -Encrypt => {Flags => 1},
177 -Flags => DB_CREATE ;
178 };
179 ok 19, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
180
181 eval
182 {
183 my $env = new BerkeleyDB::Hash
184 -Encrypt => {Fred => 1},
185 -Flags => DB_CREATE ;
186 };
187 ok 20, $@ =~ /^\Qunknown key value(s) Fred at/;
188
189 }
190
191 {
192 eval
193 {
194 my $env = new BerkeleyDB::Btree
195 -Encrypt => 1,
196 -Flags => DB_CREATE ;
197 };
198 ok 21, $@ =~ /^Encrypt parameter must be a hash reference at/;
199
200 eval
201 {
202 my $env = new BerkeleyDB::Btree
203 -Encrypt => {},
204 -Flags => DB_CREATE ;
205 };
206 ok 22, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
207
208 eval
209 {
210 my $env = new BerkeleyDB::Btree
211 -Encrypt => {Password => "fred"},
212 -Flags => DB_CREATE ;
213 };
214 ok 23, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
215
216 eval
217 {
218 my $env = new BerkeleyDB::Btree
219 -Encrypt => {Flags => 1},
220 -Flags => DB_CREATE ;
221 };
222 ok 24, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
223
224 eval
225 {
226 my $env = new BerkeleyDB::Btree
227 -Encrypt => {Fred => 1},
228 -Flags => DB_CREATE ;
229 };
230 ok 25, $@ =~ /^\Qunknown key value(s) Fred at/;
231
232 }
233
234 {
235 eval
236 {
237 my $env = new BerkeleyDB::Queue
238 -Encrypt => 1,
239 -Flags => DB_CREATE ;
240 };
241 ok 26, $@ =~ /^Encrypt parameter must be a hash reference at/;
242
243 eval
244 {
245 my $env = new BerkeleyDB::Queue
246 -Encrypt => {},
247 -Flags => DB_CREATE ;
248 };
249 ok 27, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
250
251 eval
252 {
253 my $env = new BerkeleyDB::Queue
254 -Encrypt => {Password => "fred"},
255 -Flags => DB_CREATE ;
256 };
257 ok 28, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
258
259 eval
260 {
261 my $env = new BerkeleyDB::Queue
262 -Encrypt => {Flags => 1},
263 -Flags => DB_CREATE ;
264 };
265 ok 29, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
266
267 eval
268 {
269 my $env = new BerkeleyDB::Queue
270 -Encrypt => {Fred => 1},
271 -Flags => DB_CREATE ;
272 };
273 ok 30, $@ =~ /^\Qunknown key value(s) Fred at/;
274
275 }
276
277 {
278 eval
279 {
280 my $env = new BerkeleyDB::Recno
281 -Encrypt => 1,
282 -Flags => DB_CREATE ;
283 };
284 ok 31, $@ =~ /^Encrypt parameter must be a hash reference at/;
285
286 eval
287 {
288 my $env = new BerkeleyDB::Recno
289 -Encrypt => {},
290 -Flags => DB_CREATE ;
291 };
292 ok 32, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
293
294 eval
295 {
296 my $env = new BerkeleyDB::Recno
297 -Encrypt => {Password => "fred"},
298 -Flags => DB_CREATE ;
299 };
300 ok 33, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
301
302 eval
303 {
304 my $env = new BerkeleyDB::Recno
305 -Encrypt => {Flags => 1},
306 -Flags => DB_CREATE ;
307 };
308 ok 34, $@ =~ /^Must specify Password and Flags with Encrypt parameter at/;
309
310 eval
311 {
312 my $env = new BerkeleyDB::Recno
313 -Encrypt => {Fred => 1},
314 -Flags => DB_CREATE ;
315 };
316 ok 35, $@ =~ /^\Qunknown key value(s) Fred at/;
317
318 }
319
320
321 {
322 # new BerkeleyDB::Hash -Encrypt =>
323
324 my $Dfile = "abcd.enc";
325 my $lex = new LexFile $Dfile ;
326 my %hash ;
327 my ($k, $v) ;
328 ok 36, my $db = new BerkeleyDB::Hash
329 -Filename => $Dfile,
330 -Flags => DB_CREATE,
331 -Encrypt => {Password => "beta",
332 Flags => DB_ENCRYPT_AES
333 },
334 -Property => DB_ENCRYPT ;
335
336 # create some data
337 my %data = (
338 "red" => 2,
339 "green" => "house",
340 "blue" => "sea",
341 ) ;
342
343 my $ret = 0 ;
344 while (($k, $v) = each %data) {
345 $ret += $db->db_put($k, $v) ;
346 }
347 ok 37, $ret == 0 ;
348
349 # check there are three records
350 ok 38, countRecords($db) == 3 ;
351
352 undef $db;
353
354 # attempt to open a database without specifying encryption
355 ok 39, ! new BerkeleyDB::Hash -Filename => $Dfile,
356 -Flags => DB_CREATE ;
357
358
359 # try opening with the wrong password
360 ok 40, ! new BerkeleyDB::Hash -Filename => $Dfile,
361 -Filename => $Dfile,
362 -Encrypt => {Password => "def",
363 Flags => DB_ENCRYPT_AES
364 },
365 -Property => DB_ENCRYPT ;
366
367
368 # read the encrypted data
369 ok 41, my $db1 = new BerkeleyDB::Hash -Filename => $Dfile,
370 -Filename => $Dfile,
371 -Encrypt => {Password => "beta",
372 Flags => DB_ENCRYPT_AES
373 },
374 -Property => DB_ENCRYPT ;
375
376
377 $v = '';
378 ok 42, ! $db1->db_get("red", $v) ;
379 ok 43, $v eq $data{"red"};
380 # check there are three records
381 ok 44, countRecords($db1) == 3 ;
382 undef $db1;
383 }
384
385 {
386 # new BerkeleyDB::Btree -Encrypt =>
387
388 my $Dfile = "abcd.enc";
389 my $lex = new LexFile $Dfile ;
390 my %hash ;
391 my ($k, $v) ;
392 ok 45, my $db = new BerkeleyDB::Btree
393 -Filename => $Dfile,
394 -Flags => DB_CREATE,
395 -Encrypt => {Password => "beta",
396 Flags => DB_ENCRYPT_AES
397 },
398 -Property => DB_ENCRYPT ;
399
400 # create some data
401 my %data = (
402 "red" => 2,
403 "green" => "house",
404 "blue" => "sea",
405 ) ;
406
407 my $ret = 0 ;
408 while (($k, $v) = each %data) {
409 $ret += $db->db_put($k, $v) ;
410 }
411 ok 46, $ret == 0 ;
412
413 # check there are three records
414 ok 47, countRecords($db) == 3 ;
415
416 undef $db;
417
418 # attempt to open a database without specifying encryption
419 ok 48, ! new BerkeleyDB::Btree -Filename => $Dfile,
420 -Flags => DB_CREATE ;
421
422
423 # try opening with the wrong password
424 ok 49, ! new BerkeleyDB::Btree -Filename => $Dfile,
425 -Filename => $Dfile,
426 -Encrypt => {Password => "def",
427 Flags => DB_ENCRYPT_AES
428 },
429 -Property => DB_ENCRYPT ;
430
431
432 # read the encrypted data
433 ok 50, my $db1 = new BerkeleyDB::Btree -Filename => $Dfile,
434 -Filename => $Dfile,
435 -Encrypt => {Password => "beta",
436 Flags => DB_ENCRYPT_AES
437 },
438 -Property => DB_ENCRYPT ;
439
440
441 $v = '';
442 ok 51, ! $db1->db_get("red", $v) ;
443 ok 52, $v eq $data{"red"};
444 # check there are three records
445 ok 53, countRecords($db1) == 3 ;
446 undef $db1;
447 }
448
449 {
450 # new BerkeleyDB::Queue -Encrypt =>
451
452 my $Dfile = "abcd.enc";
453 my $lex = new LexFile $Dfile ;
454 my %hash ;
455 my ($k, $v) ;
456 ok 54, my $db = new BerkeleyDB::Queue
457 -Filename => $Dfile,
458 -Len => 5,
459 -Pad => "x",
460 -Flags => DB_CREATE,
461 -Encrypt => {Password => "beta",
462 Flags => DB_ENCRYPT_AES
463 },
464 -Property => DB_ENCRYPT ;
465
466 # create some data
467 my %data = (
468 1 => 2,
469 2 => "house",
470 3 => "sea",
471 ) ;
472
473 my $ret = 0 ;
474 while (($k, $v) = each %data) {
475 $ret += $db->db_put($k, $v) ;
476 }
477 ok 55, $ret == 0 ;
478
479 # check there are three records
480 ok 56, countRecords($db) == 3 ;
481
482 undef $db;
483
484 # attempt to open a database without specifying encryption
485 ok 57, ! new BerkeleyDB::Queue -Filename => $Dfile,
486 -Len => 5,
487 -Pad => "x",
488 -Flags => DB_CREATE ;
489
490
491 # try opening with the wrong password
492 ok 58, ! new BerkeleyDB::Queue -Filename => $Dfile,
493 -Len => 5,
494 -Pad => "x",
495 -Encrypt => {Password => "def",
496 Flags => DB_ENCRYPT_AES
497 },
498 -Property => DB_ENCRYPT ;
499
500
501 # read the encrypted data
502 ok 59, my $db1 = new BerkeleyDB::Queue -Filename => $Dfile,
503 -Len => 5,
504 -Pad => "x",
505 -Encrypt => {Password => "beta",
506 Flags => DB_ENCRYPT_AES
507 },
508 -Property => DB_ENCRYPT ;
509
510
511 $v = '';
512 ok 60, ! $db1->db_get(3, $v) ;
513 ok 61, $v eq fillout($data{3}, 5, 'x');
514 # check there are three records
515 ok 62, countRecords($db1) == 3 ;
516 undef $db1;
517 }
518
519 {
520 # new BerkeleyDB::Recno -Encrypt =>
521
522 my $Dfile = "abcd.enc";
523 my $lex = new LexFile $Dfile ;
524 my %hash ;
525 my ($k, $v) ;
526 ok 63, my $db = new BerkeleyDB::Recno
527 -Filename => $Dfile,
528 -Flags => DB_CREATE,
529 -Encrypt => {Password => "beta",
530 Flags => DB_ENCRYPT_AES
531 },
532 -Property => DB_ENCRYPT ;
533
534 # create some data
535 my %data = (
536 1 => 2,
537 2 => "house",
538 3 => "sea",
539 ) ;
540
541 my $ret = 0 ;
542 while (($k, $v) = each %data) {
543 $ret += $db->db_put($k, $v) ;
544 }
545 ok 64, $ret == 0 ;
546
547 # check there are three records
548 ok 65, countRecords($db) == 3 ;
549
550 undef $db;
551
552 # attempt to open a database without specifying encryption
553 ok 66, ! new BerkeleyDB::Recno -Filename => $Dfile,
554 -Flags => DB_CREATE ;
555
556
557 # try opening with the wrong password
558 ok 67, ! new BerkeleyDB::Recno -Filename => $Dfile,
559 -Filename => $Dfile,
560 -Encrypt => {Password => "def",
561 Flags => DB_ENCRYPT_AES
562 },
563 -Property => DB_ENCRYPT ;
564
565
566 # read the encrypted data
567 ok 68, my $db1 = new BerkeleyDB::Recno -Filename => $Dfile,
568 -Filename => $Dfile,
569 -Encrypt => {Password => "beta",
570 Flags => DB_ENCRYPT_AES
571 },
572 -Property => DB_ENCRYPT ;
573
574
575 $v = '';
576 ok 69, ! $db1->db_get(3, $v) ;
577 ok 70, $v eq $data{3};
578 # check there are three records
579 ok 71, countRecords($db1) == 3 ;
580 undef $db1;
581 }
582
583 {
584 # new BerkeleyDB::Unknown -Encrypt =>
585
586 my $Dfile = "abcd.enc";
587 my $lex = new LexFile $Dfile ;
588 my %hash ;
589 my ($k, $v) ;
590 ok 72, my $db = new BerkeleyDB::Hash
591 -Filename => $Dfile,
592 -Flags => DB_CREATE,
593 -Encrypt => {Password => "beta",
594 Flags => DB_ENCRYPT_AES
595 },
596 -Property => DB_ENCRYPT ;
597
598 # create some data
599 my %data = (
600 "red" => 2,
601 "green" => "house",
602 "blue" => "sea",
603 ) ;
604
605 my $ret = 0 ;
606 while (($k, $v) = each %data) {
607 $ret += $db->db_put($k, $v) ;
608 }
609 ok 73, $ret == 0 ;
610
611 # check there are three records
612 ok 74, countRecords($db) == 3 ;
613
614 undef $db;
615
616 # attempt to open a database without specifying encryption
617 ok 75, ! new BerkeleyDB::Unknown -Filename => $Dfile,
618 -Flags => DB_CREATE ;
619
620
621 # try opening with the wrong password
622 ok 76, ! new BerkeleyDB::Unknown -Filename => $Dfile,
623 -Filename => $Dfile,
624 -Encrypt => {Password => "def",
625 Flags => DB_ENCRYPT_AES
626 },
627 -Property => DB_ENCRYPT ;
628
629
630 # read the encrypted data
631 ok 77, my $db1 = new BerkeleyDB::Unknown -Filename => $Dfile,
632 -Filename => $Dfile,
633 -Encrypt => {Password => "beta",
634 Flags => DB_ENCRYPT_AES
635 },
636 -Property => DB_ENCRYPT ;
637
638
639 $v = '';
640 ok 78, ! $db1->db_get("red", $v) ;
641 ok 79, $v eq $data{"red"};
642 # check there are three records
643 ok 80, countRecords($db1) == 3 ;
644 undef $db1;
645 }
646
1313 use BerkeleyDB;
1414 use t::util ;
1515
16 print "1..47\n";
16 print "1..50\n";
1717
1818 my $Dfile = "dbhash.tmp";
1919
2020 umask(0);
21
22 my $version_major = 0;
2123
2224 {
2325 # db version stuff
2426 my ($major, $minor, $patch) = (0, 0, 0) ;
2527
2628 ok 1, my $VER = BerkeleyDB::DB_VERSION_STRING ;
27 ok 2, my $ver = BerkeleyDB::db_version($major, $minor, $patch) ;
29 ok 2, my $ver = BerkeleyDB::db_version($version_major, $minor, $patch) ;
2830 ok 3, $VER eq $ver ;
29 ok 4, $major > 1 ;
31 ok 4, $version_major > 1 ;
3032 ok 5, defined $minor ;
3133 ok 6, defined $patch ;
3234 }
4244
4345 eval ' $env = new BerkeleyDB::Env (-Config => {"fred" => " "} ) ; ' ;
4446 ok 9, !$env ;
45 ok 10, $BerkeleyDB::Error =~ /^illegal name-value pair/ ;
47 ok 10, $BerkeleyDB::Error =~ /^(illegal name-value pair|Invalid argument)/ ;
48 #print " $BerkeleyDB::Error\n";
4649 }
4750
4851 {
211214
212215 }
213216
217 {
218 # attempt to open a new environment without DB_CREATE
219 # should fail with Berkeley DB 3.x or better.
220
221 my $home = "./fred" ;
222 ok 48, my $lexD = new LexDir($home) ;
223 chdir "./fred" ;
224 my $env = new BerkeleyDB::Env -Home => $home, -Flags => DB_CREATE ;
225 ok 49, $version_major == 2 ? $env : ! $env ;
226 ok 50, $version_major == 2 ? 1
227 : $BerkeleyDB::Error =~ /No such file or directory/ ;
228 #print " $BerkeleyDB::Error\n";
229 chdir ".." ;
230 undef $env ;
231 }
232
214233 # test -Verbose
215234 # test -Flags
216235 # db_value_set
1414 BEGIN
1515 {
1616 if ($BerkeleyDB::db_version < 3) {
17 print "1..0 # Skip: this needs Berkeley DB 3.x or better\n" ;
17 print "1..0 # Skipping test, this needs Berkeley DB 3.x or better\n" ;
1818 exit 0 ;
1919 }
2020 }
258258 untie %h;
259259 unlink $Dfile;
260260 }
261
262 if(0)
263 {
264 # Filter without tie
265 use strict ;
266 my (%h, $db) ;
267
268 unlink $Dfile;
269 ok 53, $db = tie %h, 'BerkeleyDB::Hash',
270 -Filename => $Dfile,
271 -Flags => DB_CREATE;
272
273 my %result = () ;
274
275 sub INC { return ++ $_[0] }
276 sub DEC { return -- $_[0] }
277 $db->filter_fetch_key (sub { warn "FFK $_\n"; $_ = INC($_); warn "XX\n" }) ;
278 $db->filter_store_key (sub { warn "FSK $_\n"; $_ = DEC($_); warn "XX\n" }) ;
279 $db->filter_fetch_value (sub { warn "FFV $_\n"; $_ = INC($_); warn "XX\n"}) ;
280 $db->filter_store_value (sub { warn "FSV $_\n"; $_ = DEC($_); warn "XX\n" }) ;
281
282 #$db->filter_fetch_key (sub { warn "FFK $_\n"; $_ = pack("i", $_); warn "XX\n" }) ;
283 #$db->filter_store_key (sub { warn "FSK $_\n"; $_ = unpack("i", $_); warn "XX\n" }) ;
284 #$db->filter_fetch_value (sub { warn "FFV $_\n"; $_ = pack("i", $_); warn "XX\n"}) ;
285 #$db->filter_store_value (sub { warn "FSV $_\n"; $_ = unpack("i", $_); warn "XX\n" }) ;
286
287 #$db->filter_fetch_key (sub { ++ $_ }) ;
288 #$db->filter_store_key (sub { -- $_ }) ;
289 #$db->filter_fetch_value (sub { ++ $_ }) ;
290 #$db->filter_store_value (sub { -- $_ }) ;
291
292 my ($k, $v) = (0,0);
293 ok 54, ! $db->db_put(3,5);
294 exit;
295 ok 55, ! $db->db_get(3, $v);
296 ok 56, $v == 5 ;
297
298 $h{4} = 7 ;
299 ok 57, $h{4} == 7;
300
301 $k = 10;
302 $v = 30;
303 $h{$k} = $v ;
304 ok 58, $k == 10;
305 ok 59, $v == 30;
306 ok 60, $h{$k} == 30;
307
308 $k = 3;
309 ok 61, ! $db->db_get($k, $v, DB_GET_BOTH);
310 ok 62, $k == 3 ;
311 ok 63, $v == 5 ;
312
313 my $cursor = $db->db_cursor();
314
315 my %tmp = ();
316 while ($cursor->c_get($k, $v, DB_NEXT) == 0)
317 {
318 $tmp{$k} = $v;
319 }
320
321 ok 64, keys %tmp == 3 ;
322 ok 65, $tmp{3} == 5;
323
324 undef $cursor ;
325 undef $db ;
326 untie %h;
327 unlink $Dfile;
328 }
117117 undef $env ;
118118 }
119119
120
120121 {
121122 # override default hash
122123 my $lex = new LexFile $Dfile ;
2020 }
2121
2222
23 print "1..37\n";
23 print "1..41\n";
2424
2525 my $Dfile1 = "dbhash1.tmp";
2626 my $Dfile2 = "dbhash2.tmp";
4545
4646 # no cursors supplied
4747 eval '$cursor = $db1->db_join() ;' ;
48 ok 2, $@ =~ /Usage: \$db->BerkeleyDB::Common::db_join\Q([cursors], flags=0)/;
48 ok 2, $@ =~ /Usage: \$db->BerkeleyDB::db_join\Q([cursors], flags=0)/;
4949
5050 # empty list
5151 eval '$cursor = $db1->db_join([]) ;' ;
5252 ok 3, $@ =~ /db_join: No cursors in parameter list/;
5353
54 # cursor list, isn't a []
54 # cursor list, isn not a []
5555 eval '$cursor = $db1->db_join({}) ;' ;
56 ok 4, $@ =~ /cursors is not an array reference at/ ;
56 ok 4, $@ =~ /db_join: first parameter is not an array reference/;
5757
5858 eval '$cursor = $db1->db_join(\1) ;' ;
59 ok 5, $@ =~ /cursors is not an array reference at/ ;
59 ok 5, $@ =~ /db_join: first parameter is not an array reference/;
60
61 my ($a, $b) = ("a", "b");
62 $a = bless [], "fred";
63 $b = bless [], "fred";
64 eval '$cursor = $db1->db_join($a, $b) ;' ;
65 ok 6, $@ =~ /db_join: first parameter is not an array reference/;
6066
6167 }
6268
7177 my $status ;
7278
7379 my $home = "./fred" ;
74 ok 6, my $lexD = new LexDir($home);
75 ok 7, my $env = new BerkeleyDB::Env -Home => $home,
80 ok 7, my $lexD = new LexDir($home);
81 ok 8, my $env = new BerkeleyDB::Env -Home => $home,
7682 -Flags => DB_CREATE|DB_INIT_TXN
7783 |DB_INIT_MPOOL;
7884 #|DB_INIT_MPOOL| DB_INIT_LOCK;
79 ok 8, my $txn = $env->txn_begin() ;
80 ok 9, my $db1 = tie %hash1, 'BerkeleyDB::Hash',
85 ok 9, my $txn = $env->txn_begin() ;
86 ok 10, my $db1 = tie %hash1, 'BerkeleyDB::Hash',
8187 -Filename => $Dfile1,
8288 -Flags => DB_CREATE,
8389 -DupCompare => sub { $_[0] cmp $_[1] },
8692 -Txn => $txn ;
8793 ;
8894
89 ok 10, my $db2 = tie %hash2, 'BerkeleyDB::Hash',
95 ok 11, my $db2 = tie %hash2, 'BerkeleyDB::Hash',
9096 -Filename => $Dfile2,
9197 -Flags => DB_CREATE,
9298 -DupCompare => sub { $_[0] cmp $_[1] },
94100 -Env => $env,
95101 -Txn => $txn ;
96102
97 ok 11, my $db3 = tie %hash3, 'BerkeleyDB::Btree',
103 ok 12, my $db3 = tie %hash3, 'BerkeleyDB::Btree',
98104 -Filename => $Dfile3,
99105 -Flags => DB_CREATE,
100106 -DupCompare => sub { $_[0] cmp $_[1] },
103109 -Txn => $txn ;
104110
105111
106 ok 12, addData($db1, qw( apple Convenience
112 ok 13, addData($db1, qw( apple Convenience
107113 peach Shopway
108114 pear Farmer
109115 raspberry Shopway
112118 blueberry Farmer
113119 ));
114120
115 ok 13, addData($db2, qw( red apple
121 ok 14, addData($db2, qw( red apple
116122 red raspberry
117123 red strawberry
118124 yellow peach
120126 green gooseberry
121127 blue blueberry)) ;
122128
123 ok 14, addData($db3, qw( expensive apple
129 ok 15, addData($db3, qw( expensive apple
124130 reasonable raspberry
125131 expensive strawberry
126132 reasonable peach
128134 expensive gooseberry
129135 reasonable blueberry)) ;
130136
131 ok 15, my $cursor2 = $db2->db_cursor() ;
137 ok 16, my $cursor2 = $db2->db_cursor() ;
132138 my $k = "red" ;
133139 my $v = "" ;
134 ok 16, $cursor2->c_get($k, $v, DB_SET) == 0 ;
140 ok 17, $cursor2->c_get($k, $v, DB_SET) == 0 ;
135141
136142 # Two way Join
137 ok 17, my $cursor1 = $db1->db_join([$cursor2]) ;
143 ok 18, my $cursor1 = $db1->db_join([$cursor2]) ;
138144
139145 my %expected = qw( apple Convenience
140146 raspberry Shopway
147153 if defined $expected{$k} && $expected{$k} eq $v ;
148154 #print "[$k] [$v]\n" ;
149155 }
150 ok 18, keys %expected == 0 ;
151 ok 19, $cursor1->status() == DB_NOTFOUND ;
156 ok 19, keys %expected == 0 ;
157 ok 20, $cursor1->status() == DB_NOTFOUND ;
152158
153159 # Three way Join
154 ok 20, $cursor2 = $db2->db_cursor() ;
160 ok 21, $cursor2 = $db2->db_cursor() ;
155161 $k = "red" ;
156162 $v = "" ;
157 ok 21, $cursor2->c_get($k, $v, DB_SET) == 0 ;
158
159 ok 22, my $cursor3 = $db3->db_cursor() ;
163 ok 22, $cursor2->c_get($k, $v, DB_SET) == 0 ;
164
165 ok 23, my $cursor3 = $db3->db_cursor() ;
160166 $k = "expensive" ;
161167 $v = "" ;
162 ok 23, $cursor3->c_get($k, $v, DB_SET) == 0 ;
163 ok 24, $cursor1 = $db1->db_join([$cursor2, $cursor3]) ;
168 ok 24, $cursor3->c_get($k, $v, DB_SET) == 0 ;
169 ok 25, $cursor1 = $db1->db_join([$cursor2, $cursor3]) ;
164170
165171 %expected = qw( apple Convenience
166172 strawberry Shopway
172178 if defined $expected{$k} && $expected{$k} eq $v ;
173179 #print "[$k] [$v]\n" ;
174180 }
175 ok 25, keys %expected == 0 ;
176 ok 26, $cursor1->status() == DB_NOTFOUND ;
181 ok 26, keys %expected == 0 ;
182 ok 27, $cursor1->status() == DB_NOTFOUND ;
177183
178184 # test DB_JOIN_ITEM
179185 # #################
180 ok 27, $cursor2 = $db2->db_cursor() ;
186 ok 28, $cursor2 = $db2->db_cursor() ;
181187 $k = "red" ;
182188 $v = "" ;
183 ok 28, $cursor2->c_get($k, $v, DB_SET) == 0 ;
189 ok 29, $cursor2->c_get($k, $v, DB_SET) == 0 ;
184190
185 ok 29, $cursor3 = $db3->db_cursor() ;
191 ok 30, $cursor3 = $db3->db_cursor() ;
186192 $k = "expensive" ;
187193 $v = "" ;
188 ok 30, $cursor3->c_get($k, $v, DB_SET) == 0 ;
189 ok 31, $cursor1 = $db1->db_join([$cursor2, $cursor3]) ;
194 ok 31, $cursor3->c_get($k, $v, DB_SET) == 0 ;
195 ok 32, $cursor1 = $db1->db_join([$cursor2, $cursor3]) ;
190196
191197 %expected = qw( apple 1
192198 strawberry 1
200206 if defined $expected{$k} ;
201207 #print "[$k]\n" ;
202208 }
203 ok 32, keys %expected == 0 ;
204 ok 33, $cursor1->status() == DB_NOTFOUND ;
205
206 ok 34, $cursor1->c_close() == 0 ;
207 ok 35, $cursor2->c_close() == 0 ;
208 ok 36, $cursor3->c_close() == 0 ;
209
210 ok 37, ($status = $txn->txn_commit) == 0;
209 ok 33, keys %expected == 0 ;
210 ok 34, $cursor1->status() == DB_NOTFOUND ;
211
212 ok 35, $cursor1->c_close() == 0 ;
213 ok 36, $cursor2->c_close() == 0 ;
214 ok 37, $cursor3->c_close() == 0 ;
215
216 ok 38, ($status = $txn->txn_commit) == 0;
211217
212218 undef $txn ;
219
220 ok 39, my $cursor1a = $db1->db_cursor() ;
221 eval { $cursor1 = $db1->db_join([$cursor1a]) };
222 ok 40, $@ =~ /BerkeleyDB Aborting: attempted to do a self-join at/;
223 eval { $cursor1 = $db1->db_join([$cursor1]) } ;
224 ok 41, $@ =~ /BerkeleyDB Aborting: attempted to do a self-join at/;
225
226 undef $cursor1a;
213227 #undef $cursor1;
214228 #undef $cursor2;
215229 #undef $cursor3;
5656 $o{d} = "{once upon a time}";
5757 $o{e} = 1024;
5858 $o{f} = 1024.1024;
59 my $first = Data::Dumper->new([@o{qw(a b c)}], [qw(a b c)])->Quotekeys(0)->Dump;
60 my $second = <<'EOT';
61 $a = [
62 1,
63 {
64 a => $a,
65 b => $a->[1],
66 c => [
67 \'c'
68 ]
69 },
70 $a->[1]{c}
71 ];
72 $b = {
73 a => [
74 1,
75 $b,
76 [
77 \'c'
78 ]
79 ],
80 b => $b,
81 c => $b->{a}[2]
82 };
83 $c = [
84 \'c'
85 ];
86 EOT
87
88 ::ok 3, 1 || $first eq $second ;
59
60 my $struct = [@o{qw(a b c)}];
61 ::ok 3, ::_compare([$a, $b, $c], $struct);
8962 ::ok 4, $o{d} eq "{once upon a time}" ;
9063 ::ok 5, $o{e} == 1024 ;
9164 ::ok 6, $o{f} eq 1024.1024 ;
12396 $o{d} = "{once upon a time}";
12497 $o{e} = 1024;
12598 $o{f} = 1024.1024;
126 my $first = Data::Dumper->new([@o{qw(a b c)}], [qw(a b c)])->Quotekeys(0)->Dump;
127 my $second = <<'EOT';
128 $a = [
129 1,
130 {
131 a => $a,
132 b => $a->[1],
133 c => [
134 \'c'
135 ]
136 },
137 $a->[1]{c}
138 ];
139 $b = {
140 a => [
141 1,
142 $b,
143 [
144 \'c'
145 ]
146 ],
147 b => $b,
148 c => $b->{a}[2]
149 };
150 $c = [
151 \'c'
152 ];
153 EOT
15499
155 ::ok 9, 1 || $first eq $second ;
100 my $struct = [@o{qw(a b c)}];
101 ::ok 9, ::_compare([$a, $b, $c], $struct);
156102 ::ok 10, $o{d} eq "{once upon a time}" ;
157103 ::ok 11, $o{e} == 1024 ;
158104 ::ok 12, $o{f} eq 1024.1024 ;
2323
2424 print "1..201\n";
2525
26 sub fillout
27 {
28 my $var = shift ;
29 my $length = shift ;
30 my $pad = shift || " " ;
31 my $template = $pad x $length ;
32 substr($template, 0, length($var)) = $var ;
33 return $template ;
34 }
35
3626 my $Dfile = "dbhash.tmp";
3727 my $Dfile2 = "dbhash2.tmp";
3828 my $Dfile3 = "dbhash3.tmp";
112112 eval { $db->db_close() ; } ;
113113 ok 24, $@ =~ /BerkeleyDB Aborting: attempted to close a database while a transaction was still open at/ ;
114114 #print "[$@]\n" ;
115 $txn->txn_abort();
116 $db->db_close();
115117 }
116118
117119 {
146148 my $lex = new LexFile $Dfile ;
147149 my %hash ;
148150 my $status ;
151 my $home = 'fred1';
149152
150153 ok 33, my $lexD = new LexDir($home);
151154 ok 34, my $env = new BerkeleyDB::Env -Home => $home,
121121 }
122122 }
123123
124 sub normalise
125 {
126 my $data = shift ;
127 $data =~ s#\r\n#\n#g
128 if $^O eq 'cygwin' ;
129
130 return $data ;
131 }
132
133
124134 sub docat
125135 {
126136 my $file = shift;
128138 open(CAT,$file) || die "Cannot open $file:$!";
129139 my $result = <CAT>;
130140 close(CAT);
141 $result = normalise($result);
131142 return $result;
132143 }
133144
139150 my $result = <CAT> || "" ;
140151 close(CAT);
141152 unlink $file ;
153 $result = normalise($result);
142154 return $result;
143155 }
144156
173185 }
174186
175187 (scalar(@data), join($sep, @data)) ;
188 }
189
190 sub joinkeys
191 {
192 my $db = shift ;
193 my $sep = shift || " " ;
194 my ($k, $v) = (0, "") ;
195 my @data = () ;
196
197 my $cursor = $db->db_cursor() or return () ;
198 for ( my $status = $cursor->c_get($k, $v, DB_FIRST) ;
199 $status == 0 ;
200 $status = $cursor->c_get($k, $v, DB_NEXT)) {
201 push @data, $k ;
202 }
203
204 return join($sep, @data) ;
205
206 }
207
208 sub dumpdb
209 {
210 my $db = shift ;
211 my $sep = shift || " " ;
212 my ($k, $v) = (0, "") ;
213 my @data = () ;
214
215 my $cursor = $db->db_cursor() or return () ;
216 for ( my $status = $cursor->c_get($k, $v, DB_FIRST) ;
217 $status == 0 ;
218 $status = $cursor->c_get($k, $v, DB_NEXT)) {
219 print " [$k][$v]\n" ;
220 }
221
222
176223 }
177224
178225 sub countRecords
216263 }
217264
218265
266 # These two subs lifted directly from MLDBM.pm
267 #
268 sub _compare {
269 use vars qw(%compared);
270 local %compared;
271 return _cmp(@_);
272 }
273
274 sub _cmp {
275 my($a, $b) = @_;
276
277 # catch circular loops
278 return(1) if $compared{$a.'&*&*&*&*&*'.$b}++;
279 # print "$a $b\n";
280 # print &Data::Dumper::Dumper($a, $b);
281
282 if(ref($a) and ref($a) eq ref($b)) {
283 if(eval { @$a }) {
284 # print "HERE ".@$a." ".@$b."\n";
285 @$a == @$b or return 0;
286 # print @$a, ' ', @$b, "\n";
287 # print "HERE2\n";
288
289 for(0..@$a-1) {
290 &_cmp($a->[$_], $b->[$_]) or return 0;
291 }
292 } elsif(eval { %$a }) {
293 keys %$a == keys %$b or return 0;
294 for (keys %$a) {
295 &_cmp($a->{$_}, $b->{$_}) or return 0;
296 }
297 } elsif(eval { $$a }) {
298 &_cmp($$a, $$b) or return 0;
299 } else {
300 die("data $a $b not handled");
301 }
302 return 1;
303 } elsif(! ref($a) and ! ref($b)) {
304 return ($a eq $b);
305 } else {
306 return 0;
307 }
308
309 }
310
311 sub fillout
312 {
313 my $var = shift ;
314 my $length = shift ;
315 my $pad = shift || " " ;
316 my $template = $pad x $length ;
317 substr($template, 0, length($var)) = $var ;
318 return $template ;
319 }
320
219321 1;
6060 BerkeleyDB_Txn_type * T_IV
6161 BerkeleyDB__Cursor_type * T_IV
6262 DB * T_IV
63 DB_ENV * T_IV
6364
6465 INPUT
6566
172173 croak(\"$var is not of type ${ntype}\")
173174
174175 T_dbtkeydatum
175 DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
176 DBT_clear($var) ;
177 if (db->recno_or_queue) {
178 Value = GetRecnoKey(db, SvIV($arg)) ;
179 $var.data = & Value;
180 $var.size = (int)sizeof(db_recno_t);
181 }
182 else {
183 $var.data = SvPV($arg, PL_na);
176 {
177 SV* my_sv = $arg ;
178 DBM_ckFilter(my_sv, filter_store_key, \"filter_store_key\");
179 DBT_clear($var) ;
180 if (db->recno_or_queue) {
181 Value = GetRecnoKey(db, SvIV(my_sv)) ;
182 $var.data = & Value;
183 $var.size = (int)sizeof(db_recno_t);
184 }
185 else {
186 $var.data = SvPV(my_sv, PL_na);
187 $var.size = (int)PL_na;
188 }
189 }
190
191 T_dbtkeydatum_btree
192 {
193 SV* my_sv = $arg ;
194 DBM_ckFilter(my_sv, filter_store_key, \"filter_store_key\");
195 DBT_clear($var) ;
196 if (db->recno_or_queue ||
197 (db->type == DB_BTREE && flagSet(DB_SET_RECNO))) {
198 Value = GetRecnoKey(db, SvIV(my_sv)) ;
199 $var.data = & Value;
200 $var.size = (int)sizeof(db_recno_t);
201 }
202 else {
203 $var.data = SvPV(my_sv, PL_na);
204 $var.size = (int)PL_na;
205 }
206 }
207
208 T_dbtdatum
209 {
210 SV* my_sv = $arg ;
211 DBM_ckFilter(my_sv, filter_store_value, \"filter_store_value\");
212 DBT_clear($var) ;
213 $var.data = SvPV(my_sv, PL_na);
184214 $var.size = (int)PL_na;
185 }
186
187 T_dbtkeydatum_btree
188 DBM_ckFilter($arg, filter_store_key, \"filter_store_key\");
189 DBT_clear($var) ;
190 if (db->recno_or_queue ||
191 (db->type == DB_BTREE && flagSet(DB_SET_RECNO))) {
192 Value = GetRecnoKey(db, SvIV($arg)) ;
193 $var.data = & Value;
194 $var.size = (int)sizeof(db_recno_t);
195 }
196 else {
197 $var.data = SvPV($arg, PL_na);
198 $var.size = (int)PL_na;
199 }
200
201 T_dbtdatum
202 DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
203 DBT_clear($var) ;
204 $var.data = SvPV($arg, PL_na);
205 $var.size = (int)PL_na;
206 $var.flags = db->partial ;
207 $var.dlen = db->dlen ;
208 $var.doff = db->doff ;
215 $var.flags = db->partial ;
216 $var.dlen = db->dlen ;
217 $var.doff = db->doff ;
218 }
209219
210220 T_dbtdatum_opt
211221 DBT_clear($var) ;
212222 if (flagSet(DB_GET_BOTH)) {
213 DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
214 $var.data = SvPV($arg, PL_na);
223 SV* my_sv = $arg ;
224 DBM_ckFilter(my_sv, filter_store_value, \"filter_store_value\");
225 $var.data = SvPV(my_sv, PL_na);
215226 $var.size = (int)PL_na;
216227 $var.flags = db->partial ;
217228 $var.dlen = db->dlen ;
221232 T_dbtdatum_btree
222233 DBT_clear($var) ;
223234 if (flagSet(DB_GET_BOTH)) {
224 DBM_ckFilter($arg, filter_store_value, \"filter_store_value\");
225 $var.data = SvPV($arg, PL_na);
235 SV* my_sv = $arg ;
236 DBM_ckFilter(my_sv, filter_store_value, \"filter_store_value\");
237 $var.data = SvPV(my_sv, PL_na);
226238 $var.size = (int)PL_na;
227239 $var.flags = db->partial ;
228240 $var.dlen = db->dlen ;