src/tools/cachetable.cxx File Reference

#include <CSql.h>
#include <CacheTableLoader.h>

Include dependency graph for cachetable.cxx:

Go to the source code of this file.

Functions

void printUsage ()
int main (int argc, char **argv)


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file cachetable.cxx.

References CacheTableLoader::addToCacheTableFile(), IDENTIFIER_LENGTH, CacheTableLoader::load(), OK, printUsage(), CacheTableLoader::recoverAllCachedTables(), CacheTableLoader::reload(), CacheTableLoader::removeFromCacheTableFile(), CacheTableLoader::setConnParam(), CacheTableLoader::setTable(), and CacheTableLoader::unload().

00035 {
00036     char username[IDENTIFIER_LENGTH];
00037     username [0] = '\0';
00038     char password[IDENTIFIER_LENGTH];
00039     password [0] = '\0';
00040     int c = 0, opt = 10;
00041     char tablename[IDENTIFIER_LENGTH];
00042     char syncModeStr[IDENTIFIER_LENGTH];
00043     bool tableDefinition = true;
00044     bool tableNameSpecified = false;
00045     while ((c = getopt(argc, argv, "U:P:t:Rsru?")) != EOF) 
00046     {
00047         switch (c)
00048         {
00049             case 'U' : { strcpy(username, argv[optind - 1]); opt=10; break; }
00050             case 'P' : { strcpy(password, argv[optind - 1]); opt=10; break; }
00051             case 't' : { strcpy(tablename, argv[optind - 1]); 
00052                          if (opt==10) opt = 2; 
00053                          tableNameSpecified = true; 
00054                          break; 
00055                        }
00056             case '?' : { opt = 10; break; } //print help 
00057             case 'R' : { opt = 3; break; } //recover all the tables
00058             case 's' : { tableDefinition=false; break; } //do not get the schema information from target db
00059             case 'r' : { opt = 4; break; } //reload the table
00060             case 'u' : { opt = 5; break; } //unload the table
00061             default: opt=10; 
00062 
00063         }
00064     }//while options
00065     if (opt == 10) {
00066         printUsage();
00067         return 0;
00068     }
00069 
00070     //printf("%s %s \n", username, password);
00071     if (username[0] == '\0' )
00072     {
00073         strcpy(username, "root");
00074         strcpy(password, "manager");
00075     }
00076     DbRetVal rv = OK;
00077     CacheTableLoader cacheLoader;
00078     cacheLoader.setConnParam(username, password);
00079     if (opt==2) {
00080         cacheLoader.setTable(tablename);
00081         rv = cacheLoader.load(tableDefinition);
00082         if (rv != OK) exit (1);
00083         rv = cacheLoader.addToCacheTableFile();
00084         if (rv != OK) exit (2);
00085     }else if (opt==3) //recover
00086     {
00087         rv = cacheLoader.recoverAllCachedTables();
00088         if (rv != OK) exit (1);
00089     }else if (opt==4) //reload
00090     {
00091         if (!tableNameSpecified) 
00092         {
00093             printf("Table name is not specified. Check usage with ? \n");
00094             return 1;
00095         }
00096         cacheLoader.setTable(tablename);
00097         rv = cacheLoader.reload();
00098         if (rv != OK) exit (1);
00099     }else if (opt==5) //unload
00100     {
00101         if (!tableNameSpecified) 
00102         {
00103             printf("Table name is not specified. Check usage with ? option\n");
00104             return 1;
00105         }
00106         cacheLoader.setTable(tablename);
00107         rv = cacheLoader.unload(tableDefinition);
00108         if (rv != OK) exit (1);
00109         rv = cacheLoader.removeFromCacheTableFile();
00110         if (rv != OK) exit (2);
00111 
00112     }
00113     return 0;
00114 }

Here is the call graph for this function:

void printUsage (  ) 

Definition at line 19 of file cachetable.cxx.

Referenced by main().

00020 {
00021    printf("Usage: cachetable [-U username] [-P passwd] -t tablename \n"
00022           "       [-R] [-s] [-r]\n");
00023    printf("       username -> username to connect with csql.\n");
00024    printf("       passwd -> password for the above username to connect with csql.\n");
00025    printf("       tablename -> table name to be cached in csql from target db.\n");
00026    printf("       R -> recover all cached tables from the target database.\n");
00027    printf("       s -> load only the records from target db. Assumes table is already created in csql\n");
00028    printf("       r -> reload the table. get the latest image of table from target db\n");
00029    printf("       u -> unload the table. if used with -s option, removes only records and preserves the schema\n");
00030    printf("       no option -> get table definition and records from target db and create in csql.\n");
00031    return;
00032 }

Here is the caller graph for this function:


Generated on Mon Jun 9 22:42:17 2008 for csql by  doxygen 1.4.7