diff --git a/uppsrc/Sql/IntroSch.cpp b/uppsrc/Sql/IntroSch.cpp index 4ad39ea7e..cd9b7a32d 100644 --- a/uppsrc/Sql/IntroSch.cpp +++ b/uppsrc/Sql/IntroSch.cpp @@ -19,14 +19,18 @@ ArrayMap& sSchTableInfo() return x; } +static bool sColumn; + void SchDbInfoTable(const char *table) { - sSchTableInfo().GetAdd(table).is_table = true; + sSchTableInfo().Add(table).is_table = true; + sColumn = false; } void SchDbInfoType(const char *table) { - sSchTableInfo().GetAdd(table).is_table = false; + sSchTableInfo().Add(table).is_table = false; + sColumn = false; } void SchDbInfoColumn(const char *name) @@ -37,6 +41,7 @@ void SchDbInfoColumn(const char *name) f.ref_column.Add(); if(IsNull(f.primary_key)) f.primary_key = name; + sColumn = true; } void SchDbInfoVar(void (*fn)(), const char *name) diff --git a/uppsrc/Sql/SqlCode.cpp b/uppsrc/Sql/SqlCode.cpp index c9138a97e..db2b94daa 100644 --- a/uppsrc/Sql/SqlCode.cpp +++ b/uppsrc/Sql/SqlCode.cpp @@ -53,21 +53,6 @@ String SqlId::Quoted() const return id.ToString(); } -static SqlId *sLastSqlId; - -SqlId::SqlId() { sLastSqlId = this; } -SqlId::SqlId(const char *s) : id(s) { sLastSqlId = this; } -SqlId::SqlId(const String& s) : id(s) { sLastSqlId = this; } -SqlId::SqlId(const Id& id) : id(id) { sLastSqlId = this; } - -void SqlId::RenameLast(const char *s) -{ - if(sLastSqlId) { - SqlId *h = sLastSqlId; - *h = s; - } -} - void SqlCompile(const char *&s, StringBuffer *r, byte dialect, Vector *split) { char quote = dialect == MY_SQL ? '`' : '\"'; diff --git a/uppsrc/Sql/SqlSchema.cpp b/uppsrc/Sql/SqlSchema.cpp index 25c91e2e8..965da4a3c 100644 --- a/uppsrc/Sql/SqlSchema.cpp +++ b/uppsrc/Sql/SqlSchema.cpp @@ -219,4 +219,29 @@ void operator*(SqlSchema& schema, const SqlInsert& insert) { << ";\n"; } +VectorMap& sSqlRename() +{ + static VectorMap x; + return x; } + +const char *RegSqlName__; + +void SqlRename__(const char *name) +{ + static auto& rename = sSqlRename(); + if(RegSqlName__) + rename.Add(RegSqlName__, name); + RegSqlName__ = NULL; +} + +const char *SqlResolveId__(const char *id) +{ + static auto& rename = sSqlRename(); + int q; + if(rename.GetCount() && (q = rename.Find(id)) >= 0) + return rename[q]; + return id; // cannot be conditional expression as we are returning const char * ! +} + +}; \ No newline at end of file diff --git a/uppsrc/Sql/SqlSchema.h b/uppsrc/Sql/SqlSchema.h index abc0fd34e..d4a9f797b 100644 --- a/uppsrc/Sql/SqlSchema.h +++ b/uppsrc/Sql/SqlSchema.h @@ -225,3 +225,15 @@ struct S_type { S_type(const ValueMap& m); }; #endif + +// support for SQL_RENAME + +extern const char *RegSqlName__; + +struct RegSqlId__ { + RegSqlId__(const char *name) { RegSqlName__ = name; } +}; + +void SqlRename__(const char *name); + +const char *SqlResolveId__(const char *id); diff --git a/uppsrc/Sql/Sqlexp.h b/uppsrc/Sql/Sqlexp.h index d6f7708b5..a1a639d0c 100644 --- a/uppsrc/Sql/Sqlexp.h +++ b/uppsrc/Sql/Sqlexp.h @@ -140,7 +140,7 @@ public: SqlId operator()(SqlId p) const; SqlId operator()(const S_info& table) const; - + //$-SqlId operator()(SqlId p, SqlId p1, ...); #define E__PutSqlId(I) PutOf(x, p##I) #define E__SqlId(I) const SqlId& p##I @@ -156,12 +156,10 @@ __Expand(E__Of) #undef E__PutSqlId #undef E__SqlId //$+ - SqlId(); - SqlId(const char *s); - SqlId(const String& s); - SqlId(const Id& id); - - static void RenameLast(const char *s); // to support SQL_RENAME command + SqlId() {} + SqlId(const char *s) : id(s) {} + SqlId(const String& s) : id(s) {} + SqlId(const Id& id) : id(id) {} }; typedef SqlId SqlCol; // Deprecated diff --git a/uppsrc/Sql/sch_header.h b/uppsrc/Sql/sch_header.h index 675437ae6..e03b6ab6c 100644 --- a/uppsrc/Sql/sch_header.h +++ b/uppsrc/Sql/sch_header.h @@ -8,7 +8,7 @@ private: \ static const S_info *info; \ \ public: \ - static const char TableName[]; \ + static String TableName; \ static const SqlSet& ColumnSet() { return GetInfo().set; } \ static SqlSet ColumnSet(const String& prefix) { return GetInfo().GetSet(prefix); } \ static SqlSet Of(SqlId table) { return GetInfo().GetOf(table); } \ @@ -64,6 +64,8 @@ static SqlId colid_##name; #define END_TYPE }; +#define SQL_NAME(x) + #include SCHEMADIALECT #undef CODETYPE @@ -72,7 +74,8 @@ static SqlId colid_##name; // SqlId -#define DOID(x) extern SqlId ADD_SCHEMA_PREFIX_CPP(x); -//#define DOID(x) extern SqlId x; +#define DOID(x) extern SqlId ADD_SCHEMA_PREFIX_CPP(x); + +#define SQL_NAME(x) #include SCHEMADIALECT diff --git a/uppsrc/Sql/sch_model.h b/uppsrc/Sql/sch_model.h index d2f7aecd6..3d4b23998 100644 --- a/uppsrc/Sql/sch_model.h +++ b/uppsrc/Sql/sch_model.h @@ -160,11 +160,13 @@ #endif #ifndef SQL_NAME -#define SQL_NAME(id) +#define SQL_NAME(x) #endif #include MODEL +#undef SQL_NAME + #undef __NIL #undef STAMP @@ -200,4 +202,3 @@ #undef SCHEMA #undef CONFIG #undef UPGRADE -#undef SQL_NAME diff --git a/uppsrc/Sql/sch_schema.h b/uppsrc/Sql/sch_schema.h index 4a525cad5..e8ff52b0d 100644 --- a/uppsrc/Sql/sch_schema.h +++ b/uppsrc/Sql/sch_schema.h @@ -1,9 +1,8 @@ // SCHEMA -#define VAR(type, x) schema.Var(SCHEMA_##type, #x); -#define COLUMN(type, ctype, name, width, prec) schema.Column(type, #name); -#define COLUMN_ARRAY(type, ctype, name, width, prec, items) schema.ColumnArray(type, #name, items); -#define SQL_NAME(name) schema.SqlName(name); +#define VAR(type, x) schema.Var(SCHEMA_##type, SqlResolveId__(#x)); +#define COLUMN(type, ctype, name, width, prec) schema.Column(type, SqlResolveId__(#name)); +#define COLUMN_ARRAY(type, ctype, name, width, prec, items) schema.ColumnArray(type, SqlResolveId__(#name), items); #define INLINE_ATTRIBUTE(x) schema.InlineAttribute(x); #define ATTRIBUTE(x, d) schema.Attribute(x, d); #define TABLE_SUFFIX(s) schema.TableSuffix(s); @@ -37,7 +36,7 @@ TYPE_II(x, b1, b2) SCHEMA_##b3(schema); // TABLE #define TABLE(x)\ -void TABLE_##x(SqlSchema& schema) { schema.Table(#x); SCHEMA_##x(schema); schema.EndTable(); } +void TABLE_##x(SqlSchema& schema) { schema.Table(SqlResolveId__(#x)); SCHEMA_##x(schema); schema.EndTable(); } #define TABLE_I(x, b) TABLE(x) #define TABLE_II(x, b1, b2) TABLE(x) diff --git a/uppsrc/Sql/sch_source.h b/uppsrc/Sql/sch_source.h index 8d3c5a5aa..4842f41f9 100644 --- a/uppsrc/Sql/sch_source.h +++ b/uppsrc/Sql/sch_source.h @@ -1,8 +1,14 @@ +// SqlId renaming table + +#define DOID(x) RegSqlId__ x##_rgs_(#x); +#define SQL_NAME(x) INITBLOCK { SqlRename__(x); } + +#include SCHEMADIALECT + // SqlId -#define DOID(x) SqlId ADD_SCHEMA_PREFIX_CPP(x)(#x); -#define SQL_NAME(x) INITBLOCK { SqlId::RenameLast(x); } -#include SCHEMADIALECT +#define DOID(x) SqlId ADD_SCHEMA_PREFIX_CPP(x)(SqlResolveId__(#x)); +//#define DOID(x) SqlId x(#x); #include SCHEMADIALECT @@ -50,10 +56,10 @@ void S_##x::Clear() { S_##b1::Clear(); S_##b2::Clear(); S_##b3::Clear(); // TableName, FieldLayout and GetInfo #define TYPE(x) \ -const char S_##x::TableName[] = #x; \ +String S_##x::TableName = SqlResolveId__(#x); \ \ void S_##x::FieldLayout(FieldOperator& fo) {\ - fo.Table(#x);\ + fo.Table(SqlResolveId__(#x));\ FieldLayoutRaw(fo);\ } \ \ @@ -72,47 +78,34 @@ const S_info& S_##x::GetInfo() {\ #include SCHEMADIALECT -// FieldLayoutRawFn - needed because of SqlId scope, which is used because of SQL_NAME - -#define TYPE(x) \ -void FieldLayout_##x(S_##x& s, FieldOperator& fo, const String& prefix) { - -#define COLUMN(type, ctype, name, width, prec) fo(~ADD_SCHEMA_PREFIX_CPP(name), s.ADD_SCHEMA_PREFIX_CPP(name)), fo.Width(width); -#define COLUMN_ARRAY(type, ctype, name, width, prec, items) \ -{ \ - for(int i = 0; i < items; i++)\ - fo(Format("%s%s%d", ~prefix, ~ADD_SCHEMA_PREFIX_CPP(name), i), s.ADD_SCHEMA_PREFIX_CPP(name)[i]), fo.Width(width); \ -} - -#define VAR(type, x) s.x.FieldLayoutRaw(fo, prefix + #x + "$"); - -#define END_TYPE } - -#include SCHEMADIALECT - // FieldLayoutRaw #define TYPE(x) \ -void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\ - FieldLayout_##x(*this, fo, prefix); +void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) { #define TYPE_I(x, b) \ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\ - S_##b::FieldLayoutRaw(fo, prefix);\ - FieldLayout_##x(*this, fo, prefix); + S_##b::FieldLayoutRaw(fo, prefix); #define TYPE_II(x, b1, b2) \ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\ S_##b1::FieldLayoutRaw(fo, prefix);\ - S_##b2::FieldLayoutRaw(fo, prefix);\ - FieldLayout_##x(*this, fo, prefix); + S_##b2::FieldLayoutRaw(fo, prefix); #define TYPE_III(x, b1, b2, b3) \ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\ S_##b1::FieldLayoutRaw(fo, prefix);\ S_##b2::FieldLayoutRaw(fo, prefix);\ - S_##b3::FieldLayoutRaw(fo, prefix);\ - FieldLayout_##x(*this, fo, prefix); + S_##b3::FieldLayoutRaw(fo, prefix); + +#define COLUMN(type, ctype, name, width, prec) fo(prefix + SqlResolveId__(#name), ADD_SCHEMA_PREFIX_CPP(name)), fo.Width(width); +#define COLUMN_ARRAY(type, ctype, name, width, prec, items) \ +{ \ + for(int i = 0; i < items; i++)\ + fo(Format("%s%s%d", ~prefix, SqlResolveId__(#name), i), ADD_SCHEMA_PREFIX_CPP(name)[i]), fo.Width(width); \ +} + +#define VAR(type, x) x.FieldLayoutRaw(fo, prefix + #x + "$"); #define END_TYPE } @@ -124,14 +117,14 @@ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\ #define TYPE_I(x, b) void SchDbInfo##x() { SchDbInfo##b(); #define TYPE_II(x, b1, b2) void SchDbInfo##x() { SchDbInfo##b1(); SchDbInfo##b2(); #define TYPE_III(x, b1, b2, b3) void SchDbInfo##x() { SchDbInfo##b1(); SchDbInfo##b2(); SchDbInfo##b3(); -#define COLUMN(type, ctype, name, width, prec) SchDbInfoColumn(~ADD_SCHEMA_PREFIX_CPP(name)); -#define VAR(type, name) SchDbInfoVar(SchDbInfo##type, ~ADD_SCHEMA_PREFIX_CPP(name)); -#define REFERENCES(table) SchDbInfoReferences(#table); -#define REFERENCES_CASCADE(table) SchDbInfoReferences(#table); -#define REFERENCES_(table, column) SchDbInfoReferences(#table, ~ADD_SCHEMA_PREFIX_CPP(name)); -#define REFERENCES_CASCADE_(table, column) SchDbInfoReferences(#table, ~ADD_SCHEMA_PREFIX_CPP(name)); +#define COLUMN(type, ctype, name, width, prec) SchDbInfoColumn(SqlResolveId__(#name)); +#define VAR(type, name) SchDbInfoVar(SchDbInfo##type, SqlResolveId__(#name)); +#define REFERENCES(table) SchDbInfoReferences(SqlResolveId__(#table)); +#define REFERENCES_CASCADE(table) SchDbInfoReferences(SqlResolveId__(#table)); +#define REFERENCES_(table, column) SchDbInfoReferences(SqlResolveId__(#table), SqlResolveId__(#column)); +#define REFERENCES_CASCADE_(table, column) SchDbInfoReferences(SqlResolveId__(#table), SqlResolveId__(#column)); #define PRIMARY_KEY SchDbInfoPrimaryKey(); -#define COLUMN_ARRAY(type, ctype, name, width, prec, items) SchDbInfoColumnArray(~ADD_SCHEMA_PREFIX_CPP(name), items); +#define COLUMN_ARRAY(type, ctype, name, width, prec, items) SchDbInfoColumnArray(SqlResolveId__(#name), items); #define END_TYPE } #include SCHEMADIALECT @@ -143,7 +136,7 @@ void S_##x::FieldLayoutRaw(FieldOperator& fo, const String& prefix) {\ #define TYPE_III(x, b1, b2, b3) TYPE(x) #define TABLE(x) struct SINS_##x##_ { SINS_##x##_(); } SINS_##x##__; SINS_##x##_::SINS_##x##_() {\ - SchDbInfoTable(~ADD_SCHEMA_PREFIX_CPP(x)); SchDbInfo##x(); + SchDbInfoTable(SqlResolveId__(#x)); SchDbInfo##x(); #define TABLE_I(x, b) TABLE(x) #define TABLE_II(x, b1, b2) TABLE(x) #define TABLE_III(x, b1, b2, b3) TABLE(x) diff --git a/uppsrc/Sql/src.tpp/sch_en-us.tpp b/uppsrc/Sql/src.tpp/sch_en-us.tpp index 7c377c6ef..1432de5f5 100644 --- a/uppsrc/Sql/src.tpp/sch_en-us.tpp +++ b/uppsrc/Sql/src.tpp/sch_en-us.tpp @@ -42,7 +42,7 @@ is not using any SQL engine array capabilities but rather inserts array size count of items with special names to emulate the fixed array.]&] [s0;3 &] -[s0; [3 List of .sch file `"keywords`"]&] +[s0; [3 List of .sch file keywords:]&] [s0;3 &] [ {{5007:4993^ [s0; [* TABLE(][*/ table][* )]] :: [s0; Defines a new table. This creates S`_ structures to map SQL diff --git a/uppsrc/ide/Errors.cpp b/uppsrc/ide/Errors.cpp index 2b3668baa..60ae428fa 100644 --- a/uppsrc/ide/Errors.cpp +++ b/uppsrc/ide/Errors.cpp @@ -84,7 +84,7 @@ bool Ide::FindLineError(const String& ln, FindLineErrorCache& cache, ErrorInfo& const char *ms = p.GetPtr(); if(ln.Find(": warning") >= 0) f.kind = 2; - else if(ln.Find(": error") >= 0) + else if(ln.Find(": error") >= 0 || ln.Find(": fatal error") >= 0) f.kind = 1; else f.kind = 3;