1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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. *
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. *
15 ***************************************************************************/
17 #include <CacheTableLoader.h>
21 printf("Usage: cachetable [-U username] [-P passwd] -t tablename \n"
23 printf(" username -> username to connect with csql.\n");
24 printf(" passwd -> password for the above username to connect with csql.\n");
25 printf(" tablename -> table name to be cached in csql from target db.\n");
26 printf(" R -> recover all cached tables from the target database.\n");
27 printf(" s -> load only the records from target db. Assumes table is already created in csql\n");
28 printf(" r -> reload the table. get the latest image of table from target db\n");
29 printf(" u -> unload the table. if used with -s option, removes only records and preserves the schema\n");
30 printf(" no option -> get table definition and records from target db and create in csql.\n");
34 int main(int argc
, char **argv
)
36 char username
[IDENTIFIER_LENGTH
];
38 char password
[IDENTIFIER_LENGTH
];
41 char tablename
[IDENTIFIER_LENGTH
];
42 char syncModeStr
[IDENTIFIER_LENGTH
];
43 bool tableDefinition
= true;
44 bool tableNameSpecified
= false;
45 while ((c
= getopt(argc
, argv
, "U:P:t:Rsru?")) != EOF
)
49 case 'U' : { strcpy(username
, argv
[optind
- 1]); opt
=10; break; }
50 case 'P' : { strcpy(password
, argv
[optind
- 1]); opt
=10; break; }
51 case 't' : { strcpy(tablename
, argv
[optind
- 1]);
53 tableNameSpecified
= true;
56 case '?' : { opt
= 10; break; } //print help
57 case 'R' : { opt
= 3; break; } //recover all the tables
58 case 's' : { tableDefinition
=false; break; } //do not get the schema information from target db
59 case 'r' : { opt
= 4; break; } //reload the table
60 case 'u' : { opt
= 5; break; } //unload the table
70 //printf("%s %s \n", username, password);
71 if (username
[0] == '\0' )
73 strcpy(username
, "root");
74 strcpy(password
, "manager");
77 CacheTableLoader cacheLoader
;
78 cacheLoader
.setConnParam(username
, password
);
80 cacheLoader
.setTable(tablename
);
81 rv
= cacheLoader
.load(tableDefinition
);
82 if (rv
!= OK
) exit (1);
83 rv
= cacheLoader
.addToCacheTableFile();
84 if (rv
!= OK
) exit (2);
85 }else if (opt
==3) //recover
87 rv
= cacheLoader
.recoverAllCachedTables();
88 if (rv
!= OK
) exit (1);
89 }else if (opt
==4) //reload
91 if (!tableNameSpecified
)
93 printf("Table name is not specified. Check usage with ? \n");
96 cacheLoader
.setTable(tablename
);
97 rv
= cacheLoader
.reload();
98 if (rv
!= OK
) exit (1);
99 }else if (opt
==5) //unload
101 if (!tableNameSpecified
)
103 printf("Table name is not specified. Check usage with ? option\n");
106 cacheLoader
.setTable(tablename
);
107 rv
= cacheLoader
.unload(tableDefinition
);
108 if (rv
!= OK
) exit (1);
109 rv
= cacheLoader
.removeFromCacheTableFile();
110 if (rv
!= OK
) exit (2);