void DoubleLinkedList<T>::InsertBefore(const T & put, const T & find) { LLNode<T> * travel = _head; while (travel != nullptr && travel->_data != find) { travel = travel->_next; } if(travel) { if(travel == _head) { Prepend(put); } else if(travel == _tail) { LLNode<T> * nn = new LLNode<T>(put); nn->_next = _tail; nn->_prev = _tail->_prev; _tail->_prev->_next = nn; _tail->_prev = nn; } else { LLNode<T> * nn = new LLNode<T>(put); nn->_prev = travel->_prev; nn->_next = travel; travel->_prev->_next = nn; travel->_prev = nn; } } else throw "Data not found within list"; }
EXPORT_C void RMBufPacketBase::CopyPackedL(RMBufChain& aPacket) /** Copy an entire packed packet, complete with info header @param aPacket the packet */ { __ASSERT_DEBUG(iInfo==NULL, MBufExtPanic(EMbExtPanic_PacketHeader)); __ASSERT_ALWAYS(!aPacket.IsEmpty(), MBufExtPanic(EMbExtPanic_PacketHeaderEmpty)); __ASSERT_ALWAYS(aPacket.First()->Type()==EMBufHeader, MBufExtPanic(EMbExtPanic_PacketHeader)); RMBuf* m = aPacket.Remove(); // // The following assumes that aPacket.CopyL would actually leave before it makes any change // to aPacket at all. Inspection of CopyL reveals that this is the case. // TRAPD(err, aPacket.CopyL(*this)); // // In case CopyL failed, we'd need to restore aPacket, so we'd call Prepend. // In case it succedded, we'd still need to call Prepend so that the info block remains the same. // Hence we call aPacket.Prepend irrespective of aPacket.CopyL failure. // aPacket.Prepend(m); User::LeaveIfError(err); RMBufPktInfo* info = (RMBufPktInfo*)((RMBufPktInfo*)(m->Ptr()))->CopyL(); Prepend(info->MBuf()); }
ON_BOOL32 ON_PolyEdgeCurve::Insert( int segment_index, ON_PolyEdgeSegment* new_segment ) { DestroyRuntimeCache(); ON_BOOL32 rc = false; if ( segment_index > 0 ) { //m_is_closed_helper = 0; rc = ON_PolyCurve::Insert(segment_index,new_segment); if ( rc ) { int i; for ( i = segment_index; i < Count(); i++ ) { ON_PolyEdgeSegment* seg = SegmentCurve(i); ON_Interval d = SegmentDomain(i); seg->SetDomain(d[0],d[1]); } } } else if ( segment_index == 0 ) rc = Prepend(new_segment); return rc; }
bool JSONValue::Insert(int offset, JSONValue *val) { bool ret = true; std::list<JSONValue *>::iterator iter; int i; if (offset < 0 || offset >= (int) m_elements.size()) { ret = false; goto out; } if (offset == 0) { Prepend(val); } else if (offset == (int) m_elements.size() - 1) { Append(val); } else { for (i = 0,iter = m_elements.begin(); iter != m_elements.end(); ++iter,i++) { if (i == offset) { break; } } } m_elements.insert(iter, val); out: return ret; }
// In DB2 trigger, column can be assigned without NEW correlation name void SqlParser::Db2TriggerCorrelatedName(Token *var) { if(var == NULL) return; bool exists = false; // Do not convert if the target name already set if(var->t_len > 0) return; if((_spl_new_correlation_name == NULL && Token::Compare(var, "NEW.", L"NEW.", 0, 4) == true) || (Token::Compare(var, _spl_new_correlation_name, 3) == true && Token::Compare(var, ".", L".", 3, 1) == true)) exists = true; if(exists) return; // In Oracle correlation name must be specified if(_target == SQL_ORACLE) { PrependNoFormat(var, ":", L":", 1); if(_spl_new_correlation_name != NULL) PrependCopy(var, _spl_new_correlation_name); else Prepend(var, "NEW", L"NEW", 3); PrependNoFormat(var, ".", L".", 1); } }
EXPORT_C void RMBufPacketBase::Pack() /** Combine info header with data ready for queueing */ { __ASSERT_ALWAYS(iInfo!=NULL, MBufExtPanic(EMbExtPanic_PacketHeader)); Prepend(iInfo->MBuf()); iInfo = NULL; }
Ptr<LispObject> getQualifiedName(Ptr<LispObject> pEnv) { typeCheck(pEnv, Type::Environment); auto name = ezStringBuilder(); while(true) { name.Prepend(symbol::getValue(getName(pEnv)).GetData()); pEnv = getParent(pEnv); if(isNil(pEnv)) { break; } name.Prepend('/'); } return str::create(name.GetData(), name.GetElementCount()); }
void DoubleLinkedList<T>::Append(T data) { if(_tail != nullptr) { _tail->_next = new LLNode<T>(data); _tail->_next->_prev = _tail; _tail = _tail->_next; } else { Prepend(data); } }
void ReopenEditorListView::Prepend(const wxArrayString& colValues, Logger::level lv) { if (!m_pListControl) return; if (colValues.GetCount() == 0 || colValues.GetCount() > mTitles.GetCount()) return; m_pListControl->Freeze(); Prepend(colValues[0], lv); for (size_t i = 1; i < colValues.GetCount(); ++i) m_pListControl->SetItem(0, i, colValues[i]); m_pListControl->Thaw(); }
/* * freeProcEntryAndReturnReset -- free proc entry in PGPROC or AuxiliaryProcs array, * and return the postmasterResetRequired value. * * To avoid holding a lock on PGPROC structure, we use compare_and_swap to put * PGPROC entry back to the free list. */ bool freeProcEntryAndReturnReset(int pid) { Assert(ProcGlobal != NULL); bool resetRequired = true; PGPROC *procs = ProcGlobal->procs; /* Return PGPROC structure to freelist */ for (int i = 0; i < MaxBackends; i++) { PGPROC *myProc = &procs[i]; if (myProc->pid == pid) { resetRequired = myProc->postmasterResetRequired; myProc->postmasterResetRequired = true; Prepend(myProc); if (gp_debug_pgproc) { elog(LOG, "moving PGPROC entry to freelist: pid=%d (resetRequired=%d)", pid, resetRequired); elog(LOG, "freeing PGPROC entry for pid %d, freeProcs (prev offset, new offset): (%ld, %ld)", pid, myProc->links.next, MAKE_OFFSET(myProc)); } return resetRequired; } } bool found = false; resetRequired = freeAuxiliaryProcEntryAndReturnReset(pid, &found); if (found) return resetRequired; if (gp_debug_pgproc) { elog(LOG, "proc entry not found: pid=%d", pid); } return resetRequired; }
// Prepend the token with the specified value Token* SqlParser::Prepend(Token *token, const char *str, const wchar_t *wstr, int len, Token *format) { if(token == NULL) return NULL; Token *prepend = new Token(); // Define how to format the token if(format == NULL) *prepend = *token; else *prepend = *format; prepend->prev = NULL; prepend->next = NULL; prepend->t_str = NULL; prepend->t_wstr = NULL; prepend->t_len = 0; prepend->flags = TOKEN_INSERTED; Token::Change(prepend, str, wstr, len); Prepend(token, prepend); // If token ends with newline, add the same number of spaces after prepended token if(str != NULL && str[len - 1] == '\n') { Token *prev = token->prev; // Skip previously appended tokens while(prev != NULL && prev->flags & TOKEN_INSERTED) prev = prev->prev; // Copy all blanks and tabs before appended token after new line while(prev != NULL && (prev->Compare(' ', L' ') == true || prev->Compare('\t', L'\t') == true)) { AppendCopy(prepend, prev); prev = prev->prev; } } return prepend; }
void wxGISToolBarMenu::Update(void) { //cleare contents for (size_t i = 0; i < m_delitems.size(); ++i) { Destroy(m_delitems[i]); } m_delitems.clear(); wxGISCommandBarPtrArray CommandBars = m_pApp->GetCommandBars(); for(size_t i = 0; i < CommandBars.GetCount(); ++i) { wxGISCommandBar* pCmdBar = CommandBars[i]; if(pCmdBar->GetType() == enumGISCBToolbar) { wxWindow* pWnd = dynamic_cast<wxWindow*>(pCmdBar); bool bIsShown = pWnd->IsShown(); //TODO: sort!!! wxMenuItem* pItem = Prepend(ID_TOOLBARCMD + i, pCmdBar->GetCaption(), wxT(""), wxITEM_CHECK); pItem->Check(bIsShown); m_delitems.push_back(pItem); } } m_delitems.push_back(AppendSeparator()); wxGISCommand* pCmd = m_pApp->GetCommand(wxT("wxGISCommonCmd"), enumGISCommonCmdCustomize); if (NULL != pCmd) { m_delitems.push_back(Append(pCmd->GetId(), pCmd->GetCaption(), pCmd->GetTooltip(), (wxItemKind)pCmd->GetKind())); } pCmd = m_pApp->GetCommand(wxT("wxGISCommonCmd"), enumGISCommonCmdFitToolbars); if (NULL != pCmd) { m_delitems.push_back(Append(pCmd->GetId(), pCmd->GetCaption(), pCmd->GetTooltip(), (wxItemKind)pCmd->GetKind())); } pCmd = m_pApp->GetCommand(wxT("wxGISCommonCmd"), enumGISCommonCmdOptimizeToolbars); if (NULL != pCmd) { m_delitems.push_back(Append(pCmd->GetId(), pCmd->GetCaption(), pCmd->GetTooltip(), (wxItemKind)pCmd->GetKind())); } }
// Prepend the token without formatting Token* SqlParser::PrependNoFormat(Token *token, const char *str, const wchar_t *wstr, int len) { if(token == NULL) return NULL; Token *prepend = new Token(); // Initalize source values in the token *prepend = *token; prepend->prev = NULL; prepend->next = NULL; prepend->t_str = Str::GetCopy(str, len); prepend->t_wstr = NULL; prepend->t_len = len; Prepend(token, prepend); return prepend; }
// Parser high-level token void SqlParser::Parse(Token *token, int scope, int *result_sets) { bool exists = false; // If application scope is set, start from an application statement if(_source_app != 0) { _level = LEVEL_APP; if(_source_app == APP_COBOL && _cobol != NULL) exists = _cobol->ParseStatement(token); _level = LEVEL_SQL; } if(exists == true) return; if(ParseStatement(token, scope, result_sets) == true) return; if(ParseSystemProcedure(NULL, token) == true) return; exists = ParseExpression(token); // Standalone function call if(exists == true && token->type == TOKEN_FUNCTION && token->t_type != TOKEN_STATEMENT && scope == SQL_SCOPE_PROC) { // Netezza requires explicit CALL keyword if(_target == SQL_NETEZZA) { Prepend(token, "CALL ", L"CALL ", 5); } } }
// Convert row-level trigger using inserted and deleted system tables void SqlParser::SqlServerConvertRowLevelTrigger(Token *table, Token *when, Token *insert, Token *update, Token *delete_, Token *end) { if(table == NULL || when == NULL) return; TokenStr old_cols; TokenStr old_vars; Token *decl_end = _spl_last_declare; // Skip statement delimiter if(decl_end != NULL && Token::Compare(decl_end->next, ';', L';') == true) decl_end = decl_end->next; int num = 0; size_t old_prefix_len = 4; // Skip old. in column name references (old already prefixed with @ in target) if(_spl_old_correlation_name != NULL) old_prefix_len = _spl_old_correlation_name->len + 1 + 1; // Generate declaration for referenced OLD columns for(ListwItem *i = _spl_tr_old_columns.GetFirst(); i != NULL; i = i->next) { Token *var = (Token*)i->value; if(num == 0) Append(decl_end, "\n", L"\n", 1); else { old_cols.Append(", ", L", ", 2); old_vars.Append(", ", L", ", 2); } Append(decl_end, "\nDECLARE ", L"\nDECLARE ", 9, _declare_format); AppendCopy(decl_end, var); Append(decl_end, " ", L" ", 1); // Define the data type of the variable TokenStr type; GuessType(var, type); AppendNoFormat(decl_end, &type); Append(decl_end, ";", L";", 1); old_cols.Append(var, old_prefix_len, var->len - old_prefix_len + 1); old_vars.Append(var); num++; } // Declare deleted cursor if(delete_ != NULL) { Append(decl_end, "\nDECLARE ", L"\nDECLARE ", 9, _declare_format); AppendNoFormat(decl_end, "deleted_cur ", L"deleted_cur ", 12); Append(decl_end, "CURSOR FOR SELECT ", L"CURSOR FOR SELECT ", 18, _declare_format); AppendNoFormat(decl_end, &old_cols); Append(decl_end, " FROM ", L" FROM ", 6, _declare_format); AppendNoFormat(decl_end, "deleted;", L"deleted;", 8); } if(delete_ != NULL) Append(decl_end, "\n\nOPEN deleted_cur;", L"\n\nOPEN deleted_cur;", 19); Append(decl_end, "\nWHILE 1=0 BEGIN", L"\nWHILE 1=0 BEGIN", 16); if(delete_ != NULL) { Append(decl_end, "\nFETCH deleted_cur INTO ", L"\nFETCH deleted_cur INTO ", 24); AppendNoFormat(decl_end, &old_vars); Append(decl_end, ";", L";", 1); } Append(decl_end, "\nIF @@FETCH_STATUS <> 0 BREAK;", L"\nIF @@FETCH_STATUS <> 0 BREAK;", 30); // Terminate the cursor loop Token *end_loop = Prepend(end, "END\n", L"END\n", 4); if(delete_ != NULL) { Append(end_loop, "CLOSE deleted_cur;", L"CLOSE deleted_cur;", 18); Append(end_loop, "\nDEALLOCATE deleted_cur;", L"\nDEALLOCATE deleted_cur;", 24); } // Perform DELETE in INSTEAD OF trigger if(delete_ != NULL && insert == NULL && update == NULL) { Append(end_loop, "\nDELETE FROM ", L"\nDELETE FROM ", 13); AppendCopy(end_loop, table); Append(end_loop, " WHERE (", L" WHERE (", 8); AppendNoFormat(end_loop, &old_cols); Append(end_loop, ") IN (SELECT ", L") IN (SELECT ", 13); AppendNoFormat(end_loop, &old_cols); Append(end_loop, " FROM deleted);\n", L" FROM deleted);\n", 16); } }
// DB2 identity options in GENERATED ALWAYS or BY DEFAULT AS IDENTITY bool SqlParser::ParseDb2GeneratedClause(Token *create, Token *table_name, Token *column, Token *generated, Token **id_col, Token **id_start, Token **id_inc, bool *id_default) { if(generated == NULL) return false; Token *always = GetNextWordToken("ALWAYS", L"ALWAYS", 6); Token *by = NULL; Token *default_ = NULL; if(always == NULL) { by = GetNextWordToken("BY", L"BY", 2); default_ = GetNextWordToken("DEFAULT", L"DEFAULT", 7); if(id_default != NULL) *id_default = true; } else { if(id_default != NULL) *id_default = false; } Token *as = GetNextWordToken("AS", L"AS", 2); Token *identity = GetNextWordToken("IDENTITY", L"IDENTITY", 8); // Identity parameters are optional Token *open = GetNextCharToken('(', L'('); Token *close = NULL; Token *start_with = NULL; Token *increment_by = NULL; while(true) { bool exists = false; if(open == NULL) break; Token *option = GetNextToken(); if(option == NULL) break; // START WITH if(option->Compare("START", L"START", 5) == true) { /*Token *with */ (void) GetNextWordToken("WITH", L"WITH", 4); start_with = GetNextNumberToken(); exists = true; continue; } else // INCREMENT BY if(option->Compare("INCREMENT", L"INCREMENT", 9) == true) { /*Token *by */ (void) GetNextWordToken("BY", L"BY", 2); increment_by = GetNextNumberToken(); exists = true; continue; } else // MINVALUE if(option->Compare("MINVALUE", L"MINVALUE", 8) == true) { /*Token *value */ (void) GetNextNumberToken(); exists = true; continue; } else // MAXVALUE if(option->Compare("MAXVALUE", L"MAXVALUE", 8) == true) { /*Token *value */ (void) GetNextNumberToken(); exists = true; continue; } else // NO CYCLE and NO ORDER if(option->Compare("NO", L"NO", 2) == true) { /*Token *attr */ (void) GetNextToken(); exists = true; continue; } else // CACHE if(option->Compare("CACHE", L"CACHE", 5) == true) { /*Token *value */ (void) GetNextNumberToken(); exists = true; continue; } else // CYCLE if(option->Compare("CYCLE", L"CYCLE", 5) == true) { exists = true; continue; } else // Looks like comma is optional if(option->Compare(',', L',') == true) { exists = true; continue; } PushBack(option); break; } if(open != NULL) close = GetNextCharToken(')', L')'); // IDENTITY(start, inc) in SQL Server if(_target == SQL_SQL_SERVER) { Token::Change(generated, "IDENTITY(", L"IDENTITY(", 9); AppendCopy(generated, start_with); if(increment_by != NULL) { Append(generated, ", ", L", ", 2); AppendCopy(generated, increment_by); } Append(generated, ")", L")", 1); if(always != NULL) Token::Remove(always, close); else Token::Remove(by, close); } else // Use a sequence and DEFAULT nextval for PostgreSQL and Greenplum if(_target == SQL_POSTGRESQL || _target == SQL_GREENPLUM) { TokenStr seq_name(table_name); AppendIdentifier(seq_name, "_seq", L"_seq", 4); // Generate CREATE SEQUENCE before CREATE TABLE Prepend(create, "CREATE SEQUENCE ", L"CREATE SEQUENCE ", 16); PrependNoFormat(create, &seq_name); if(start_with != NULL) { Prepend(create, " START WITH ", L" START WITH ", 12); PrependCopy(create, start_with); } if(increment_by != NULL) { Prepend(create, " INCREMENT BY ", L" INCREMENT BY ", 14); PrependCopy(create, increment_by); } Prepend(create, ";\n\n", L";\n\n", 3); // Generate DEFAULT nextval('tablename_seq') clause Token::Change(generated, "DEFAULT ", L"DEFAULT ", 8); Append(generated, "nextval ('", L"nextval ('", 10); AppendNoFormat(generated, &seq_name); Append(generated, "')", L"')", 2); if(always != NULL) Token::Remove(always, close); else Token::Remove(by, close); } else // Remove for other databases if(_target != SQL_DB2) { Token::Remove(generated); Token::Remove(always); Token::Remove(by, default_); Token::Remove(as, identity); Token::Remove(open, close); } if(id_col != NULL) *id_col = column; if(id_start != NULL) *id_start = start_with; if(id_inc != NULL) *id_inc = increment_by; return true; }
// Various SET options such as SET CURRENT SCHEMA bool SqlParser::ParseDb2SetOptions(Token *set) { bool exists = false; if(set == NULL) return false; // CURRENT is optional (SET SCHEMA is allowed) Token *current = GetNextWordToken("CURRENT", L"CURRENT", 7); Token *option = GetNextToken(); if(option == NULL) { PushBack(current); return false; } // SET [CURRENT] PATH = list if(option->Compare("PATH", L"PATH", 4) == true) { // Optional = /*Token *equal */ (void) GetNextCharToken('=', L'='); // Comma-separated list of values while(true) { // Schema name /*Token *name */ (void) GetNextToken(); Token *comma = GetNextCharToken(',', L','); if(comma == NULL) break; } // Remove the statement in Oracle if(_target == SQL_ORACLE) Token::Remove(set, Nvl(GetNextCharToken(';', L';'), GetLastToken())); exists = true; } else // SET [CURRENT] SCHEMA = name if(option->Compare("SCHEMA", L"SCHEMA", 6) == true) { // Optional = Token *equal = GetNextCharToken('=', L'='); // Schema name /*Token *name */ (void) GetNextToken(); // ALTER SESSION SET CURRENT_SCHEMA = name in Oracle if(_target == SQL_ORACLE) { Prepend(set, "ALTER SESSION ", L"ALTER SESSION ", 14); Token::Remove(current); Token::Change(option, "CURRENT_SCHEMA", L"CURRENT_SCHEMA", 14); if(equal == NULL) AppendNoFormat(option, " =", L" =", 2); } exists = true; } // Not a SET option else { PushBack(option); PushBack(current); } return exists; }
void GString::PadLeft(int nCnt, char ch /* = ' ' */) { if (nCnt > _len) Prepend(nCnt - _len, ch); }
BString& BString::PrependChars(const BString& string, int32 charCount) { return Prepend(string, UTF8CountBytes(string.String(), charCount)); }