source: gs2-extensions/tdb-edit/trunk/src/src/tdbdel-src/tdbdel.cpp@ 24696

Last change on this file since 24696 was 24696, checked in by jmt12, 13 years ago

Removing debug code, and adding in strings.h header to improve portability (although I guess it also make portability worse on Windoze - oh well)

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1/**********************************************************************
2 *
3 * tdbdel -- remove a single value from the TDB database
4 *
5 * A component of the Greenstone digital library software
6 * from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * Copyright (C) 2011 The New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 *********************************************************************/
26
27#if defined(GSDL_USE_OBJECTSPACE)
28#include <ospace\std\iostream>
29#elif defined(GSDL_USE_IOS_H)
30#include <iostream.h>
31#else
32#include <iostream>
33#endif
34
35#include <cstdlib>
36#include <cstring>
37
38#include <fcntl.h>
39#include "tdb.h"
40
41// use the standard namespace
42#if !defined (GSDL_NAMESPACE_BROKEN)
43#if defined(GSDL_USE_OBJECTSPACE)
44using namespace ospace::std;
45#else
46using namespace std;
47#endif
48#endif
49
50/**
51 */
52void
53printUsage (char *program_name)
54{
55 cerr << "usage: " << program_name << " <database_path> <key>" << endl;
56 cerr << endl;
57}
58/** printUsage() **/
59
60/**
61 */
62int
63main (int argc, char *argv[])
64{
65 // sanity check
66 if (argc != 3)
67 {
68 printUsage(argv[0]);
69 exit (-1);
70 }
71
72 char *dbname = argv[1];
73
74 int hash_size = 0;
75 int tdb_flags = TDB_DEFAULT; // Default = 0
76 int open_flags = O_RDWR;
77 TDB_CONTEXT *tdb = tdb_open(dbname, hash_size, tdb_flags, open_flags, 0664);
78 if (!tdb)
79 {
80 cerr << "couldn't create " << dbname << endl;
81 exit (0);
82 }
83
84 TDB_DATA key;
85 key.dsize = strlen(argv[2]);
86 key.dptr = (unsigned char*)argv[2];
87
88 int status = tdb_delete (tdb, key);
89
90 // status:
91 // 0 == delete OK
92 // -1 == key does not exist or there was an error
93
94 if (status < 0)
95 {
96 cerr << "Opened database " << argv[1] << endl;
97 cerr << " but couldn't delete: " << argv[2] << endl;
98 }
99
100 tdb_close (tdb);
101
102 return status;
103}
104/** main() **/
105
Note: See TracBrowser for help on using the repository browser.