COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libremotesql/include/coopy/RemoteSqlSheet.h
Go to the documentation of this file.
00001 #ifndef COOPY_REMOTESQLSHEET
00002 #define COOPY_REMOTESQLSHEET
00003 
00004 #include <coopy/DataSheet.h>
00005 #include <coopy/Property.h>
00006 #include <coopy/SparseSheet.h>
00007 
00008 #include <vector>
00009 
00010 namespace coopy {
00011   namespace store {
00012     namespace remotesql {
00013       class RemoteSqlSheet;
00014       class RemoteSqlSheetSchema;
00015       class RemoteSqlTextBook;
00016     }
00017   }
00018 }
00019 
00020 class coopy::store::remotesql::RemoteSqlSheet : public DataSheet {
00021 public:
00022   RemoteSqlSheet(RemoteSqlTextBook *owner, const char *name);
00023 
00024   virtual ~RemoteSqlSheet();
00025 
00026   virtual int width() const  { return w; }
00027   virtual int height() const { return h; }
00028 
00029   virtual std::string cellString(int x, int y) const;
00030 
00031   virtual std::string cellString(int x, int y, bool& escaped) const;
00032 
00033   virtual bool cellString(int x, int y, const std::string& str) {
00034     return cellString(x,y,str,false);
00035   }
00036 
00037   virtual bool cellString(int x, int y, const std::string& str, bool escaped);
00038 
00039   virtual ColumnRef moveColumn(const ColumnRef& src, const ColumnRef& base);
00040 
00041   virtual bool deleteColumn(const ColumnRef& column);
00042 
00043   virtual ColumnRef insertColumn(const ColumnRef& base);
00044 
00045   virtual ColumnRef insertColumn(const ColumnRef& base, const ColumnInfo& info);
00046 
00047   virtual bool modifyColumn(const ColumnRef& base, const ColumnInfo& info);
00048 
00049   virtual RowRef insertRow(const RowRef& base);
00050 
00051   virtual bool deleteRow(const RowRef& src);
00052 
00053   virtual bool clearCache() { 
00054     cache.clear();
00055     cacheFlag.clear();
00056     return true;
00057   }
00058 
00059   virtual ColumnInfo getColumnInfo(int x) {
00060     ColumnType t;
00061     t.setType(col2type[x],"mysql");
00062     t.primaryKey = col2pk[x];
00063     t.primaryKeySet = true;
00064     t.allowNull = col2nullable[x];
00065     t.autoIncrement = col2autoinc[x];
00066     t.autoIncrementSet = true;
00067     return ColumnInfo(col2sql[x],t);
00068     //return ColumnInfo(col2sql[x],col2pk[x]);
00069   }
00070 
00071   virtual int getColumnCount() const {
00072     return (int)col2sql.size();
00073   }
00074 
00075   virtual SheetSchema *getSchema() const;
00076 
00077   std::string getName() const {
00078     return name;
00079   }
00080 
00081   virtual bool isSequential() const {
00082     return false;
00083   }
00084 
00085   virtual bool deleteData(int offset);  
00086 
00087   virtual bool hasExternalColumnNames() const {
00088     return true;
00089   }
00090 
00091   virtual bool applyRowCache(const RowCache& cache, int row, SheetCell *result);
00092 
00093   virtual bool beginTransaction();
00094   virtual bool endTransaction();
00095   
00096   virtual bool rollbackTransaction() {
00097     return false;
00098   }
00099   
00100 
00101 private:
00102   RemoteSqlSheetSchema *schema;
00103   RemoteSqlTextBook *book;
00104   void *implementation;
00105   SparseStringSheet cache;
00106   SparseByteSheet cacheFlag;
00107   std::string name;
00108   int w, h;
00109   // row2sql is complicated without rowid equivalent.
00110   // see sqlitesheet for simpler implementation with rowid.
00111   std::vector<std::vector<std::string> > row2sql;
00112   std::vector<std::string> col2sql;
00113   std::vector<std::string> col2type;
00114   std::vector<bool> col2pk;
00115   std::vector<bool> col2nullable;
00116   std::vector<bool> col2autoinc;
00117   std::vector<std::string> keys;
00118   std::vector<int> key_cols;
00119 };
00120 
00121 class coopy::store::remotesql::RemoteSqlSheetSchema : public SheetSchema {
00122 public:
00123   RemoteSqlSheet *sheet;
00124 
00125   virtual std::string getSheetName() const {
00126     return sheet->getName();
00127   }
00128 
00129   virtual ColumnInfo getColumnInfo(int x) const {
00130     return sheet->getColumnInfo(x);
00131   }
00132 
00133   virtual int getColumnCount() const {
00134     return sheet->getColumnCount();
00135   }
00136 
00137   virtual bool providesPrimaryKeys() const {
00138     return true;
00139   }
00140 };
00141 
00142 
00143 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines