• Main Page
  • Classes
  • Files
  • File List

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 USE_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_rename,
00058     tkn_rollback,
00059     tkn_server,
00060     tkn_set,
00061     tkn_stop,
00062     tkn_semi,
00063     tkn_show,
00064     tkn_to,
00065     tkn_update,
00066     tkn_values,
00067     tkn_version,
00068     tkn_include,
00069     tkn_exclude,
00070 };
00071 
00072 struct tableField {
00073     char_t* name;
00074     char_t* refTableName;
00075     char_t* inverseRefName;
00076     int     type;
00077 
00078     tableField() { name = refTableName = inverseRefName = NULL; }
00079     ~tableField() { delete[] name; delete[] refTableName; delete[] inverseRefName; }
00080 };
00081 
00082 
00083 class dbList {
00084   public:
00085     enum NodeType {
00086         nInteger,
00087         nBool,
00088         nReal,
00089         nString,
00090         nTuple,
00091         nAutoinc
00092     };
00093 
00094     dbList* next;
00095     int type;
00096     union {
00097         bool    bval;
00098         db_int8 ival;
00099         real8   fval;
00100         char_t* sval;
00101         struct {
00102             int     nComponents;
00103             dbList* components;
00104         } aggregate;
00105     };
00106 
00107     ~dbList() {
00108         if (type == nTuple) {
00109             dbList* list = aggregate.components;
00110             while (list != NULL) { 
00111                 dbList* tail = list->next;
00112                 delete list;
00113                 list = tail;
00114             }
00115         } else if (type == nString) {
00116             delete[] sval;
00117         }
00118     }
00119 
00120     dbList(int type) {
00121         this->type = type;
00122         next = NULL;
00123     }
00124 };
00125 
00126 class dbUpdateElement { 
00127   public:
00128     dbUpdateElement*   next;
00129     dbFieldDescriptor* field;
00130     dbExprNode*        value;
00131     char_t*            strValue;
00132 
00133     dbUpdateElement() { 
00134         next = NULL;
00135         strValue = NULL;
00136         value = NULL;
00137     }
00138     ~dbUpdateElement() { 
00139         delete[] strValue;
00140         delete value;
00141     }
00142 };
00143 
00144 
00145 #define MAX_HISTORY_SIZE 16
00146 
00147 class dbSubSql : public dbDatabase {
00148   private:
00149     int     pos;
00150     int     line;
00151     int     tknPos;
00152     char_t* buf;
00153     int     buflen;
00154     FILE*   in;
00155     bool    opened;
00156     db_int8 ival;
00157     real8   fval;
00158     char_t* name;
00159 
00160     dbTableDescriptor* metatable;
00161     static char const* prompt;
00162 
00163     dbTableDescriptor* droppedTables;
00164     dbTableDescriptor* existedTables;
00165 
00166     dbQuery query;
00167     dbCompiler compiler;
00168 
00169     int      ungetToken;
00170     bool     autocommit;
00171 
00172     bool     dotIsPartOfIdentifier;
00173 
00174     char_t*  dateFormat;
00175 
00176     dbEvent  daemonTerminationEvent;
00177     dbThread httpServerThread;
00178     HTTPapi* httpServer;
00179     bool     httpServerRunning;
00180     char_t*  databasePath;
00181     char*    queryHistory[MAX_HISTORY_SIZE];
00182     unsigned historyUsed;
00183     unsigned historyCurr;
00184 
00185     static void thread_proc httpServerThreadProc(void* arg);
00186 
00187     void deleteColumns(dbFieldDescriptor* columns);
00188     
00189     void httpServerLoop();
00190 
00191     void startHttpServer(char_t const* address);
00192     void stopHttpServer(char_t const* address);
00193 
00194     void handleError(dbErrorClass error, char const* msg = NULL,  int arg = 0);
00195 
00196     void warning(char const* msg);
00197     void error(char const* msg);
00198 
00199     int  get();
00200     void unget(int ch);
00201     int  scan();
00202     bool parse();
00203 
00204     bool expect(char const* expected, int token);
00205 
00206     void recovery();
00207     void profile();
00208 
00209     bool isValidOid(oid_t oid);
00210 
00211     void dumpRecord(byte* record, dbFieldDescriptor* first);
00212     static int calculateRecordSize(dbList* list, int offs,
00213                                    dbFieldDescriptor* first);
00214     int  initializeRecordFields(dbList* node, byte* dst, int offs,
00215                                       dbFieldDescriptor* first);
00216     bool insertRecord(dbList* list, dbTableDescriptor* desc);
00217     bool readCondition();
00218     int  readExpression();
00219     int  readValues(dbList** chain);
00220     bool updateFields(dbAnyCursor* cursor, dbUpdateElement* elems);
00221     bool updateTable(bool create);
00222     int  parseType(char_t*& reftableName, char_t*& inverseRefName);
00223     int  updateRecords(dbTableDescriptor* desc, dbList *fields, dbList *values, dbAnyCursor &cursor, byte *buf);
00224 
00225     dbFieldDescriptor* readFieldName(int terminator = tkn_semi);
00226 
00228     bool parseExportTables(dbArray<char_t*>/*OUT*/ &tables, SelectionMethod /*OUT*/ &method);
00229 
00230   public:
00231     void run(int argc, char* argv[]);
00232     void selectionPage(WWWconnection& con);
00233     void queryPage(WWWconnection& con);
00234     void defaultPage(WWWconnection& con);
00235 
00236     dbSubSql(dbAccessType type = dbAllAccess, size_t poolSize = 0);
00237     virtual~dbSubSql();
00238 };
00239 
00240 #endif

Generated on Mon Aug 23 2010 00:04:01 for GigaBASE by  doxygen 1.7.1