Main Page   Class Hierarchy   Compound List   File List   Compound Members  

subsql.h

00001 //-< SUBSQL.H >------------------------------------------------------*--------*
00002 // GigaBASE                  Version 1.0         (c) 1999  GARRET    *     ?  *
00003 // (Post Relational Database Management System)                      *   /\|  *
00004 //                                                                   *  /  \  *
00005 //                          Created:     20-Nov-98    K.A. Knizhnik  * / [] \ *
00006 //                          Last update: 10-Dec-98    K.A. Knizhnik  * GARRET *
00007 //-------------------------------------------------------------------*--------*
00008 // Interactive data manipulation language (subset of SQL)
00009 //-------------------------------------------------------------------*--------*
00010 
00011 #ifndef __SUBSQL_H__
00012 #define __SUBSQL_H__
00013 
00014 #ifdef _WIN32
00015 #pragma warning(disable: 4786)
00016 #endif
00017 
00018 BEGIN_GIGABASE_NAMESPACE
00019 
00020 enum SubSqlTokens {
00021     tkn_alter = tkn_last_token,
00022     tkn_array,
00023     tkn_autoincrement,
00024     tkn_autocommit,
00025     tkn_backup,
00026     tkn_bool,
00027     tkn_commit,
00028     tkn_compactify,
00029     tkn_count,
00030     tkn_create,
00031     tkn_delete,
00032     tkn_describe,
00033     tkn_drop,
00034     tkn_exit,
00035     tkn_export,
00036     tkn_hash,
00037     tkn_help,
00038     tkn_http, 
00039     tkn_import,
00040     tkn_index,
00041     tkn_int1,
00042     tkn_int2,
00043     tkn_int4,
00044     tkn_int8,
00045     tkn_inverse,
00046     tkn_memory,
00047     tkn_of,
00048     tkn_off,
00049     tkn_on,
00050     tkn_open,
00051     tkn_profile,
00052     tkn_real4,
00053     tkn_real8,
00054     tkn_rectangle,
00055     tkn_reference,
00056     tkn_restore,
00057     tkn_rollback,
00058     tkn_server,
00059     tkn_set,
00060     tkn_stop,
00061     tkn_semi,
00062     tkn_show,
00063     tkn_to,
00064     tkn_update,
00065     tkn_values,
00066     tkn_version,
00067     tkn_include,
00068     tkn_exclude,
00069 };
00070 
00071 struct tableField {
00072     char_t* name;
00073     char_t* refTableName;
00074     char_t* inverseRefName;
00075     int     type;
00076 
00077     tableField() { name = refTableName = inverseRefName = NULL; }
00078     ~tableField() { delete[] name; delete[] refTableName; delete[] inverseRefName; }
00079 };
00080 
00081 
00082 class dbList {
00083   public:
00084     enum NodeType {
00085         nInteger,
00086         nBool,
00087         nReal,
00088         nString,
00089         nTuple,
00090         nAutoinc
00091     };
00092 
00093     dbList* next;
00094     int type;
00095     union {
00096         bool    bval;
00097         db_int8 ival;
00098         real8   fval;
00099         char_t* sval;
00100         struct {
00101             int     nComponents;
00102             dbList* components;
00103         } aggregate;
00104     };
00105 
00106     ~dbList() {
00107         if (type == nTuple) {
00108             dbList* list = aggregate.components;
00109             while (list != NULL) { 
00110                 dbList* tail = list->next;
00111                 delete list;
00112                 list = tail;
00113             }
00114         } else if (type == nString) {
00115             delete[] sval;
00116         }
00117     }
00118 
00119     dbList(int type) {
00120         this->type = type;
00121         next = NULL;
00122     }
00123 };
00124 
00125 class dbUpdateElement { 
00126   public:
00127     dbUpdateElement*   next;
00128     dbFieldDescriptor* field;
00129     dbExprNode*        value;
00130     char_t*            strValue;
00131 
00132     dbUpdateElement() { 
00133         next = NULL;
00134         strValue = NULL;
00135         value = NULL;
00136     }
00137     ~dbUpdateElement() { 
00138         delete[] strValue;
00139         delete value;
00140     }
00141 };
00142 
00143 
00144 #define MAX_HISTORY_SIZE 16
00145 
00146 class dbSubSql : public dbDatabase {
00147   private:
00148     int     pos;
00149     int     line;
00150     int     tknPos;
00151     char_t* buf;
00152     int     buflen;
00153     FILE*   in;
00154     bool    opened;
00155     db_int8 ival;
00156     real8   fval;
00157     char_t* name;
00158 
00159     dbTableDescriptor* metatable;
00160     static char const* prompt;
00161 
00162     dbTableDescriptor* droppedTables;
00163     dbTableDescriptor* existedTables;
00164 
00165     dbQuery query;
00166     dbCompiler compiler;
00167 
00168     int      ungetToken;
00169     bool     autocommit;
00170 
00171     bool     dotIsPartOfIdentifier;
00172 
00173     char_t*  dateFormat;
00174 
00175     dbEvent  daemonTerminationEvent;
00176     dbThread httpServerThread;
00177     HTTPapi* httpServer;
00178     bool     httpServerRunning;
00179     char_t*  databasePath;
00180     char*    queryHistory[MAX_HISTORY_SIZE];
00181     unsigned historyUsed;
00182     unsigned historyCurr;
00183 
00184     static void thread_proc httpServerThreadProc(void* arg);
00185 
00186     void deleteColumns(dbFieldDescriptor* columns);
00187     
00188     void httpServerLoop();
00189 
00190     void startHttpServer(char_t const* address);
00191     void stopHttpServer(char_t const* address);
00192 
00193     void handleError(dbErrorClass error, char const* msg = NULL,  int arg = 0);
00194 
00195     void warning(char const* msg);
00196     void error(char const* msg);
00197 
00198     int  get();
00199     void unget(int ch);
00200     int  scan();
00201     bool parse();
00202 
00203     bool expect(char const* expected, int token);
00204 
00205     void recovery();
00206     void profile();
00207 
00208     bool isValidOid(oid_t oid);
00209 
00210     void dumpRecord(byte* record, dbFieldDescriptor* first);
00211     static int calculateRecordSize(dbList* list, int offs,
00212                                    dbFieldDescriptor* first);
00213     int  initializeRecordFields(dbList* node, byte* dst, int offs,
00214                                       dbFieldDescriptor* first);
00215     bool insertRecord(dbList* list, dbTableDescriptor* desc);
00216     bool readCondition();
00217     int  readExpression();
00218     int  readValues(dbList** chain);
00219     bool updateFields(dbAnyCursor* cursor, dbUpdateElement* elems);
00220     bool updateTable(bool create);
00221     int  parseType(char_t*& reftableName, char_t*& inverseRefName);
00222     int  updateRecords(dbTableDescriptor* desc, dbList *fields, dbList *values, dbAnyCursor &cursor, byte *buf);
00223 
00224     dbFieldDescriptor* readFieldName();
00225 
00227     bool parseExportTables(dbArray<char*>/*OUT*/ &tables, SelectionMethod /*OUT*/ &method);
00228 
00229   public:
00230     void run(int argc, char* argv[]);
00231     void selectionPage(WWWconnection& con);
00232     void queryPage(WWWconnection& con);
00233     void defaultPage(WWWconnection& con);
00234 
00235     dbSubSql(dbAccessType type = dbAllAccess, size_t poolSize = 0);
00236     virtual~dbSubSql();
00237 };
00238 
00239 END_GIGABASE_NAMESPACE
00240 
00241 
00242 #endif

Generated on Thu Feb 14 21:46:04 2008 for GigaBASE by doxygen1.2.18