00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __SUBSQL_H__
00012 #define __SUBSQL_H__
00013
00014 enum SubSqlTokens {
00015 tkn_array = tkn_last_token,
00016 tkn_autoincrement,
00017 tkn_backup,
00018 tkn_bool,
00019 tkn_commit,
00020 tkn_compactify,
00021 tkn_create,
00022 tkn_delete,
00023 tkn_describe,
00024 tkn_drop,
00025 tkn_exit,
00026 tkn_hash,
00027 tkn_help,
00028 tkn_index,
00029 tkn_int1,
00030 tkn_int2,
00031 tkn_int4,
00032 tkn_int8,
00033 tkn_of,
00034 tkn_on,
00035 tkn_open,
00036 tkn_real4,
00037 tkn_real8,
00038 tkn_reference,
00039 tkn_rollback,
00040 tkn_server,
00041 tkn_set,
00042 tkn_stop,
00043 tkn_semi,
00044 tkn_show,
00045 tkn_to,
00046 tkn_update,
00047 tkn_values
00048 };
00049
00050
00051
00052 class dbList {
00053 public:
00054 enum NodeType {
00055 nInteger,
00056 nBool,
00057 nReal,
00058 nString,
00059 nTuple,
00060 nAutoinc,
00061 nIdentifier
00062 };
00063
00064 dbList* next;
00065 int type;
00066 union {
00067 bool bval;
00068 db_int8 ival;
00069 real8 fval;
00070 char* sval;
00071 struct {
00072 int nComponents;
00073 dbList* components;
00074 } aggregate;
00075 };
00076
00077 ~dbList() {
00078 if (type == nTuple) {
00079 delete aggregate.components;
00080 } else if (type == nString || type == nIdentifier) {
00081 delete[] sval;
00082 }
00083 }
00084
00085 dbList(int type) {
00086 this->type = type;
00087 next = NULL;
00088 }
00089 };
00090
00091
00092 struct tableField {
00093 char* name;
00094 char* refTableName;
00095 int type;
00096
00097 tableField() { name = refTableName = NULL; }
00098 ~tableField() { delete[] name; delete[] refTableName; }
00099 };
00100
00101 class dbUpdateElement {
00102 public:
00103 dbUpdateElement* next;
00104 dbFieldDescriptor* field;
00105 dbExprNode* value;
00106 char* strValue;
00107
00108 dbUpdateElement() {
00109 next = NULL;
00110 strValue = NULL;
00111 }
00112 ~dbUpdateElement() {
00113 delete[] strValue;
00114 }
00115 };
00116
00117 class dbSubSql : public dbDatabase {
00118 private:
00119 int pos;
00120 int line;
00121 int tknPos;
00122 char* buf;
00123 int buflen;
00124 FILE* in;
00125 bool opened;
00126 db_int8 ival;
00127 real8 fval;
00128 char* name;
00129
00130 static char* prompt;
00131
00132 dbTableDescriptor* droppedTables;
00133 dbTableDescriptor* existedTables;
00134
00135 dbQuery query;
00136 dbCompiler compiler;
00137
00138 void handleError(dbErrorClass error, char const* msg = NULL, int arg = 0);
00139
00140 void error(char const* msg);
00141
00142 int get();
00143 void unget(int ch);
00144 int scan();
00145 bool parse();
00146
00147 bool expect(char* expected, int token);
00148
00149 void recovery();
00150
00151 bool isValidOid(oid_t oid);
00152
00153 static void dumpRecord(byte* record, dbFieldDescriptor* first);
00154 static int calculateRecordSize(dbList* list, int offs,
00155 dbFieldDescriptor* first);
00156 int initializeRecordFields(dbList* node, byte* dst, int offs,
00157 dbFieldDescriptor* first);
00158 bool insertRecord(dbList* list, dbTableDescriptor* desc);
00159 bool readCondition();
00160 int readExpression();
00161 int readValues(dbList** chain);
00162 bool updateFields(dbAnyCursor* cursor, dbUpdateElement* elems);
00163 bool createTable();
00164 int parseType();
00165 int updateRecords(dbTableDescriptor* desc, dbList *fields, dbList *values, dbAnyCursor &cursor, byte *buf);
00166 dbFieldDescriptor* readFieldName();
00167 public:
00168 void run(int argc, char* argv[]);
00169
00170 dbSubSql(dbAccessType accessType);
00171 virtual~dbSubSql();
00172 };
00173
00174
00175 #endif