COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libremotesql/test_remotesql.cpp
Go to the documentation of this file.
00001 #include <coopy/RemoteSqlTextBook.h>
00002 #include <coopy/Property.h>
00003 
00004 using namespace coopy::store;
00005 using namespace coopy::store::remotesql;
00006 using namespace std;
00007 
00008 int main(int argc, char *argv[]) {
00009   RemoteSqlTextBook book;
00010   Property p;
00011   p.put("username","root");
00012   p.put("password","");
00013   // "lostname" should be "hostname" I imagine
00014   p.put("lostname","localhost");
00015   p.put("port",3128);
00016   p.put("database",(argc>1)?argv[1]:"mysql");
00017   if (!book.open(p)) {
00018     printf("Could not open database\n");
00019     return 1;
00020   }
00021   vector<string> names = book.getNames();
00022   printf("got %d names\n", (int)names.size());
00023   for (int i=0; i<(int)names.size(); i++) {
00024     printf(" %d -> %s\n", i, names[i].c_str());
00025   }
00026   if (names.size()==0) {
00027     return 0;
00028   }
00029   for (int i=0; i<(int)names.size(); i++) {
00030     bool force = false;
00031     if (argc>2) {
00032       force = true;
00033       if (names[i]!=argv[2]) continue;
00034     }
00035     PolySheet sheet = book.readSheet(names[i]);
00036     printf("Sheet %s has dimensions %dx%d\n", names[i].c_str(),
00037            sheet.width(), sheet.height());
00038     if (argc==6) {
00039       int x = atoi(argv[3]);
00040       int y = atoi(argv[4]);
00041       const char *str = argv[5];
00042       printf("Setting %d %d => %s\n", x, y, str);
00043       sheet.cellString(x,y,str);
00044     }
00045     if (force || (sheet.height()>0 && sheet.height()<20)) {
00046       for (int y=0; y<sheet.height(); y++) {
00047         printf("%d: ", y);
00048         for (int x=0; x<sheet.width(); x++) {
00049           printf(" [%s]", sheet.cellString(x,y).c_str());
00050         }
00051         printf("\n");
00052       }
00053     }
00054   }
00055   return 0;
00056 }
00057 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines