adding support for mutex from D flag
[csql.git] / src / tools / redo.cxx
blob31ae1331d075e4eaddad34a2188cc93bc1ab2f7f
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include <os.h>
17 #include <Statement.h>
18 #include <SqlFactory.h>
19 #include <SqlStatement.h>
20 #include <Recover.h>
22 AbsSqlConnection *conn;
23 bool list = false;
24 bool interactive=false;
25 char fileName[MAX_FILE_LEN];
27 int main(int argc, char **argv)
29 strcpy(fileName, "");
30 int c = 0, opt=0;
31 while ((c = getopt(argc, argv, "f:ail?")) != EOF) {
32 switch (c) {
33 case '?' : { opt = 1; break; } //print help
34 case 'a' : { opt = 2; break; }
35 case 'i' : { interactive = true; break; }
36 case 'l' : { list = true; break; }
37 case 'f' : {strcpy(fileName , argv[optind - 1]); break;}
38 default: printf("Wrong args\n"); exit(1);
41 }//while options
42 if (2 !=opt) {
43 printf("This is an internal csql command with i and f <filename> options.");
44 exit(1);
46 char *verbose = os::getenv("CSQL_INTERACTIVE");
47 if (verbose !=NULL && strcmp(verbose, "true") == 0)
49 printf("VERBOSE ON %s\n", verbose);
50 interactive=true;
52 conn = SqlFactory::createConnection(CSqlDirect);
53 DbRetVal rv = conn->connect(I_USER, I_PASS);
54 if (rv != OK) {
55 printError(ErrNoConnection, "REDO: could not connect to DB.");
56 delete conn;
57 return 2;
60 if (strcmp(fileName, "") ==0) {
61 sprintf(fileName, "%s/csql.db.cur", Conf::config.getDbFile());
63 SqlConnection *sCon = (SqlConnection*) conn;
64 if(!list) rv = sCon->getExclusiveLock();
65 //during connection close, this exclusive lock will be automatically released
66 if (rv != OK) {
67 conn->disconnect();
68 delete conn;
69 return 4;
71 Recovery recovery;
72 int retVal = recovery.applyRedoLogs(fileName, conn, list, interactive);
73 conn->disconnect();
74 delete conn;
75 return retVal;