void Tokenizer::TokenizeByDelimiter(bool enclosed, const TokenRange& range) { // Each group occasionally has a different delimiter, which is why we can't // analyze the whole filename in one go. const char_t delimiter = GetDelimiter(range); // TODO: Better handle groups with multiple delimiters if (!ValidateDelimiter(delimiter, enclosed, range)) { AddToken(kUnknown, enclosed, range); return; } TokenRange new_range(range.offset, 0); for (size_t offset = range.offset; offset < range.offset + range.size; offset++) { const char_t character = filename_.at(offset); if (character == delimiter) { // Add new unknown token if (new_range.offset < offset) { new_range.size = offset - new_range.offset; AddToken(kUnknown, enclosed, new_range); } // Add delimiter AddToken(kDelimiter, enclosed, TokenRange(offset, 1)); new_range.offset = offset + 1; } else if (offset == range.offset + range.size - 1) { // Add last unknown token new_range.size = offset - new_range.offset + 1; AddToken(kUnknown, enclosed, new_range); } } }
wxString pgType::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Type: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- DROP TYPE ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE TYPE ") + GetQuotedFullIdentifier(); if (GetTypeClass() == TYPE_COMPOSITE) { sql += wxT(" AS\n ("); sql += GetQuotedTypesList(); } else if (GetTypeClass() == TYPE_ENUM) { sql += wxT(" AS ENUM\n ("); sql += GetQuotedLabelList(); } else { sql += wxT("\n (INPUT=") + qtIdent(GetInputFunction()) + wxT(", OUTPUT=") + qtIdent(GetOutputFunction()); AppendIfFilled(sql, wxT(", DEFAULT="), qtDbString(GetDefault())); if (!GetElement().IsNull()) { sql += wxT(",\n ELEMENT=") + GetElement() + wxT(", DELIMITER='") + GetDelimiter() + wxT("'"); } sql += wxT(",\n INTERNALLENGTH=") + NumToStr(GetInternalLength()) + wxT(", ALIGNMENT=" + GetAlignment() + wxT(", STORAGE=") + GetStorage()); if (GetConnection()->BackendMinimumVersion(8, 3)) { if (GetTypmodinFunction() != wxEmptyString && GetTypmodoutFunction() != wxEmptyString) { sql += wxT(",\n TYPMOD_IN=") + GetTypmodinFunction() + wxT(", TYPMOD_OUT=") + GetTypmodoutFunction(); } else if (GetTypmodinFunction() != wxEmptyString) sql += wxT(",\n TYPMOD_IN=") + GetTypmodinFunction(); else if (GetTypmodoutFunction() != wxEmptyString) sql += wxT(",\n TYPMOD_OUT=") + GetTypmodoutFunction(); } if (GetConnection()->BackendMinimumVersion(9, 1) && GetCollatable()) { sql += wxT(",\n COLLATABLE=true"); } } sql += wxT(");\n") + GetOwnerSql(8, 0) + GetCommentSql(); if (GetConnection()->BackendMinimumVersion(9, 1)) sql += GetSeqLabelsSql(); } return sql; }
UnicodeString TStrings::GetCommaText() const { wchar_t LOldDelimiter = GetDelimiter(); wchar_t LOldQuoteChar = GetQuoteChar(); FDelimiter = L','; FQuoteChar = L'"'; UnicodeString Result; SCOPE_EXIT { FDelimiter = LOldDelimiter; FQuoteChar = LOldQuoteChar; }; Result = GetDelimitedText(); return Result; }
void TStrings::SetDelimitedText(const UnicodeString & Value) { BeginUpdate(); SCOPE_EXIT { EndUpdate(); }; Clear(); rde::vector<UnicodeString> Lines; UnicodeString Delimiter(UnicodeString(GetDelimiter()) + L'\n'); tokenize(Value, Lines, Delimiter, true); for (size_t Index = 0; Index < Lines.size(); Index++) { Add(Lines[Index]); } }
UnicodeString TStrings::GetCommaText() const { wchar_t LOldDelimiter = GetDelimiter(); wchar_t LOldQuoteChar = GetQuoteChar(); FDelimiter = L','; FQuoteChar = L'"'; UnicodeString Result; auto cleanup = finally([&]() { FDelimiter = LOldDelimiter; FQuoteChar = LOldQuoteChar; }); { Result = GetDelimitedText(); } return Result; }
void TStrings::SetDelimitedText(const UnicodeString & Value) { BeginUpdate(); SCOPE_EXIT { EndUpdate(); }; { Clear(); rde::vector<std::wstring> Lines; std::wstring delim = std::wstring(1, GetDelimiter()); delim.append(1, L'\n'); std::wstring StrValue = Value.c_str(); tokenize(StrValue, Lines, delim, true); for (size_t I = 0; I < Lines.size(); I++) { Add(Lines[I]); } } }
UnicodeString TStrings::GetDelimitedText() const { UnicodeString Result; intptr_t Count = GetCount(); if ((Count == 1) && GetString(0).IsEmpty()) { Result = GetQuoteChar() + GetQuoteChar(); } else { for (intptr_t I = 0; I < GetCount(); I++) { UnicodeString line = GetString(I); Result += GetQuoteChar() + line + GetQuoteChar() + GetDelimiter(); } if (Result.Length() > 0) Result.SetLength(Result.Length() - 1); } return Result; }
void pgType::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { wxString query; wxString collation; if (!expandedKids) { expandedKids = true; if (GetTypeClass() == TYPE_COMPOSITE) { query = wxT("SELECT attname, format_type(t.oid,NULL) AS typname, attndims, atttypmod, nsp.nspname,\n") wxT(" (SELECT COUNT(1) from pg_type t2 WHERE t2.typname=t.typname) > 1 AS isdup"); if (GetConnection()->BackendMinimumVersion(9, 1)) query += wxT(",\n collname, nspc.nspname as collnspname"); query += wxT("\n FROM pg_attribute att\n") wxT(" JOIN pg_type t ON t.oid=atttypid\n") wxT(" JOIN pg_namespace nsp ON t.typnamespace=nsp.oid\n") wxT(" LEFT OUTER JOIN pg_type b ON t.typelem=b.oid\n"); if (GetConnection()->BackendMinimumVersion(9, 1)) query += wxT(" LEFT OUTER JOIN pg_collation c ON att.attcollation=c.oid\n") wxT(" LEFT OUTER JOIN pg_namespace nspc ON c.collnamespace=nspc.oid\n"); query += wxT(" WHERE att.attrelid=") + NumToStr(relOid) + wxT("\n") wxT(" ORDER by attnum"); pgSet *set = ExecuteSet(query); if (set) { int anzvar = 0; while (!set->Eof()) { wxString element; if (anzvar++) { typesList += wxT(", "); quotedTypesList += wxT(",\n "); } typesList += set->GetVal(wxT("attname")) + wxT(" "); typesArray.Add(set->GetVal(wxT("attname"))); quotedTypesList += qtIdent(set->GetVal(wxT("attname"))) + wxT(" "); pgDatatype dt(set->GetVal(wxT("nspname")), set->GetVal(wxT("typname")), set->GetBool(wxT("isdup")), set->GetLong(wxT("attndims")) > 0, set->GetLong(wxT("atttypmod"))); wxString nspname = set->GetVal(wxT("nspname")); typesList += dt.GetSchemaPrefix(GetDatabase()) + dt.FullName(); typesArray.Add(dt.GetSchemaPrefix(GetDatabase()) + dt.FullName()); quotedTypesList += dt.GetQuotedSchemaPrefix(GetDatabase()) + dt.QuotedFullName(); if (GetConnection()->BackendMinimumVersion(9, 1)) { if (set->GetVal(wxT("collname")).IsEmpty() || (set->GetVal(wxT("collname")) == wxT("default") && set->GetVal(wxT("collnspname")) == wxT("pg_catalog"))) collation = wxEmptyString; else { collation = qtIdent(set->GetVal(wxT("collnspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname"))); quotedTypesList += wxT(" COLLATE ") + collation; } collationsArray.Add(collation); } typesArray.Add(collation); set->MoveNext(); } delete set; } } else if (GetTypeClass() == TYPE_ENUM) { query = wxT("SELECT enumlabel\n") wxT(" FROM pg_enum\n") wxT(" WHERE enumtypid=") + GetOidStr() + wxT("\n"); if (GetConnection()->BackendMinimumVersion(9, 1)) query += wxT(" ORDER by enumsortorder"); else query += wxT(" ORDER by oid"); pgSet *set = ExecuteSet(query); if (set) { int anzvar = 0; while (!set->Eof()) { wxString element; if (anzvar++) { labelList += wxT(", "); quotedLabelList += wxT(",\n "); } labelList += set->GetVal(wxT("enumlabel")); labelArray.Add(set->GetVal(wxT("enumlabel"))); quotedLabelList += GetDatabase()->connection()->qtDbString(set->GetVal(wxT("enumlabel"))); set->MoveNext(); } delete set; } } } if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("OID"), GetOid()); properties->AppendItem(_("Owner"), GetOwner()); properties->AppendItem(_("Alias"), GetAlias()); if (GetTypeClass() == TYPE_COMPOSITE) { properties->AppendItem(_("Members"), GetTypesList()); } if (GetTypeClass() == TYPE_ENUM) { properties->AppendItem(_("Labels"), GetLabelList()); } else { properties->AppendItem(_("Alignment"), GetAlignment()); properties->AppendItem(_("Internal length"), GetInternalLength()); properties->AppendItem(_("Default"), GetDefault()); properties->AppendItem(_("Passed by Value?"), BoolToYesNo(GetPassedByValue())); if (!GetElement().IsEmpty()) { properties->AppendItem(_("Element"), GetElement()); properties->AppendItem(_("Delimiter"), GetDelimiter()); } properties->AppendItem(_("Input function"), GetInputFunction()); properties->AppendItem(_("Output function"), GetOutputFunction()); if (GetConnection()->BackendMinimumVersion(7, 4)) { properties->AppendItem(_("Receive function"), GetReceiveFunction()); properties->AppendItem(_("Send function"), GetSendFunction()); } if (GetConnection()->BackendMinimumVersion(8, 3)) { if (GetTypmodinFunction().Length() > 0) properties->AppendItem(_("Typmod in function"), GetTypmodinFunction()); if (GetTypmodoutFunction().Length() > 0) properties->AppendItem(_("Typmod out function"), GetTypmodoutFunction()); } properties->AppendItem(_("Storage"), GetStorage()); if (GetConnection()->BackendMinimumVersion(9, 1)) properties->AppendItem(_("Collatable?"), BoolToYesNo(GetCollatable())); } properties->AppendYesNoItem(_("System type?"), GetSystemObject()); properties->AppendItem(_("Comment"), firstLineOnly(GetComment())); if (!GetLabels().IsEmpty()) { wxArrayString seclabels = GetProviderLabelArray(); if (seclabels.GetCount() > 0) { for (unsigned int index = 0 ; index < seclabels.GetCount() - 1 ; index += 2) { properties->AppendItem(seclabels.Item(index), seclabels.Item(index + 1)); } } } } }
wxString pgType::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Type: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- DROP TYPE ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE TYPE ") + GetQuotedFullIdentifier(); if (GetTypeClass() == TYPE_COMPOSITE) { sql += wxT(" AS\n ("); sql += GetQuotedTypesList(); } else if (GetTypeClass() == TYPE_ENUM) { sql += wxT(" AS ENUM\n ("); sql += GetQuotedLabelList(); } else if (GetTypeClass() == TYPE_RANGE) { sql += wxT(" AS RANGE\n (") wxT("SUBTYPE=") + rngsubtypestr; if (!rngsubopcstr.IsEmpty()) sql += wxT(",\n SUBTYPE_OPCLASS=") + rngsubopcstr; if (!rngcollationstr.IsEmpty()) sql += wxT(",\n COLLATION=") + rngcollationstr; if (!rngcanonical.IsEmpty()) sql += wxT(",\n CANONICAL=") + rngcanonical; if (!rngsubdiff.IsEmpty()) sql += wxT(",\n SUBTYPE_DIFF=") + rngsubdiff; } else { sql += wxT("\n (INPUT=") + qtIdent(GetInputFunction()) + wxT(",\n OUTPUT=") + qtIdent(GetOutputFunction()); if (GetConnection()->BackendMinimumVersion(7, 4)) { if (!GetReceiveFunction().IsEmpty()) { sql += wxT(",\n RECEIVE=") + GetReceiveFunction(); } if (!GetSendFunction().IsEmpty()) { sql += wxT(",\n SEND=") + GetSendFunction(); } } if (GetConnection()->BackendMinimumVersion(8, 3)) { if (!GetTypmodinFunction().IsEmpty()) sql += wxT(",\n TYPMOD_IN=") + GetTypmodinFunction(); if (!GetTypmodoutFunction().IsEmpty()) sql += wxT(",\n TYPMOD_OUT=") + GetTypmodoutFunction(); if (GetAnalyzeFunction() != wxEmptyString) sql += wxT(",\n ANALYZE=") + GetAnalyzeFunction(); } if (GetConnection()->BackendMinimumVersion(8, 4)) { sql += wxT(",\n CATEGORY=") + qtDbString(GetCategory()); if (GetPrefered()) sql += wxT(",\n PREFERRED=true"); } if (GetPassedByValue()) sql += wxT(",\n PASSEDBYVALUE"); AppendIfFilled(sql, wxT(", DEFAULT="), qtDbString(GetDefault())); if (!GetElement().IsNull()) { sql += wxT(",\n ELEMENT=") + GetElement() + wxT(", DELIMITER='") + GetDelimiter() + wxT("'"); } sql += wxT(",\n INTERNALLENGTH=") + NumToStr(GetInternalLength()) + wxT(", ALIGNMENT=" + GetAlignment() + wxT(", STORAGE=") + GetStorage()); if (GetConnection()->BackendMinimumVersion(9, 1) && GetCollatable()) { sql += wxT(",\n COLLATABLE=true"); } if (GetConnection()->BackendMinimumVersion(9, 1) && GetCollatable()) { sql += wxT(",\n COLLATABLE=true"); } } sql += wxT(");\n") + GetOwnerSql(8, 0) + GetCommentSql(); if (GetConnection()->BackendMinimumVersion(9, 1)) sql += GetSeqLabelsSql(); } return sql; }