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