1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
/* $Id: test2.c,v 1.1 2001/12/27 16:31:10 sdattalo Exp $ */
/*****
* test2.c : eXdbm example
*
* This file Version $Revision: 1.1 $
*
* Last modification: $Date: 2001/12/27 16:31:10 $
* By: $Author: sdattalo $
* Current State: $State: Exp $
*
* Copyright (C) 1997 Fred Pesch
* All Rights Reserved
*
* This file is part of the eXdbm Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****/
#ifndef lint
static char vcid[] = "$Id: test2.c,v 1.1 2001/12/27 16:31:10 sdattalo Exp $";
#endif /* lint */
#include <stdio.h>
#include "eXdbm.h"
extern TDbmDbList *DbmDbList;
int main(void)
{
DB_ID dbid;
int ret;
printf(" \n*************************************************************");
printf(" \n***** Test2.c : read the file test1.cfg, and rewrite it *****");
printf(" \n*************************************************************\n\n");
printf("**** Database manager initialization *****\n\n");
ret = eXdbmInit();
if(ret==-1) {
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
printf("**** Opening database in file test1.cfg ****\n\n");
ret = eXdbmOpenDatabase("test1.cfg", &dbid);
if(ret==-1) {
fprintf(stderr, "\nParsing databases aborted line %d", eXdbmLastLineParsed());
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
fprintf(stderr, "%d lines parsed \n\n", eXdbmLastLineParsed());
printf("**** Updating database file ****\n\n");
ret = eXdbmUpdateDatabase(dbid);
if(ret == -1) {
fprintf(stderr, "\nUpdating databases aborted");
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
printf("**** Make a backup copy of the database in test1.cfg.backup ****\n\n");
ret = eXdbmBackupDatabase(dbid, "test1.cfg.backup");
if(ret == -1) {
fprintf(stderr, "\nDatabase Backup aborted");
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
printf("**** Closing database (no update) ****\n\n");
ret = eXdbmCloseDatabase(dbid, 0);
printf("**** Try to reload the database ****\n\n");
ret = eXdbmOpenDatabase("test1.cfg", &dbid);
if(ret==-1) {
fprintf(stderr, "\nParsing databases aborted line %d", eXdbmLastLineParsed());
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
fprintf(stderr, "%d lines parsed \n\n", eXdbmLastLineParsed());
printf("**** Reloading the database (no update) ****\n\n");
ret = eXdbmReloadDatabase(&dbid, 0);
if(ret == -1) {
fprintf(stderr, "\nReloading database aborted");
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
printf("**** Reloading the database (with update) ****");
ret = eXdbmReloadDatabase(&dbid, 1);
if(ret == -1) {
fprintf(stderr, "\nReloading database aborted");
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
printf("\n\n**** Closing the database (with update) ****\n\n");
ret = eXdbmCloseDatabase(dbid, 1);
if(ret == -1) {
fprintf(stderr, "\nClosing database aborted");
fprintf(stderr, "\n%s\n", eXdbmGetErrorString(eXdbmGetLastError()));
return(-1);
}
printf("****** eXDbm exit without error *****\n\n");
return(0);
}
|