SQL/* создаём таблицу */CREATE TABLE ENTITIES( ID Integer NOT NULL, PARENT_ID Integer, SINGULAR_NAME D_NAME NOT NULL, PLURAL_NAME D_NAME, CONSTRAINT PK_ENTITIES PRIMARY KEY (ID));/* создаём для неё генератор искусственного ПК */CREATE GENERATOR GEN_ENTITIES; /* Создаем тригер для вставки в таблицу искусственного ПК */SET TERM ^ ;CREATE TRIGGER T_ENTITIES_ID FOR ENTITIES ACTIVEBEFORE INSERT POSITION 0AS BEGIN IF (NEW.ID IS NULL) THEN NEW.ID = GEN_ID(GEN_ENTITIES, 1); END^SET TERM ; ^SET TERM ^ ;
INSERT INTO SYS$ACTIONS(ID,CAPTION) VALUES(NULL,'CAPTION') RETURNING ID
while(q.next()) qDebug() << "Value: " << q.value(0);
bool QFBResultPrivate::isSelect(){ bool iss = false; try { iss = (iSt->Type() == IBPP::stSelect) || ((iSt->Type() == IBPP::stExecProcedure) && (iSt->Columns()>0)); } catch (IBPP::Exception& e) { setError("Unable get type of statement", e, QSqlError::StatementError); } return iss;}
bool mIsSingleResult; bool mIsSingleResultDone;
bool StatementImpl::Fetch(){ if((mIsSingleResult) && (!mIsSingleResultDone)) { IBS status; int code = (*gds.Call()->m_dsql_fetch)(status.Self(), &mHandle, 1, mOutRow->Self()); if (status.Errors()) { Close(); throw SQLExceptionImpl(status, "Statement::Fetch", _("isc_dsql_fetch failed.")); } mIsSingleResultDone = true; return true; } else if ((mIsSingleResultDone) && (mIsSingleResult)) { CursorFree(); mIsSingleResult = false; mIsSingleResultDone = false; CursorFree(); return false; } if (! mResultSetAvailable) throw LogicExceptionImpl("Statement::Fetch", _("No statement has been executed or no result set available.")); IBS status; int code = (*gds.Call()->m_dsql_fetch)(status.Self(), &mHandle, 1, mOutRow->Self()); if (code == 100) // This special code means "no more rows" { mResultSetAvailable = false; // Oddly enough, fetching rows up to the last one seems to open // an 'implicit' cursor that needs to be closed. mCursorOpened = true; CursorFree(); // Free the explicit or implicit cursor/result-set return false; } if (status.Errors()) { Close(); throw SQLExceptionImpl(status, "Statement::Fetch", _("isc_dsql_fetch failed.")); } return true;}
void StatementImpl::Execute(const std::string& sql){ if (! sql.empty()) Prepare(sql); if (mHandle == 0) throw LogicExceptionImpl("Statement::Execute", _("No statement has been prepared.")); // Check that a value has been set for each input parameter if (mInRow != 0 && mInRow->MissingValues()) throw LogicExceptionImpl("Statement::Execute", _("All parameters must be specified.")); CursorFree(); // Free a previous 'cursor' if any IBS status; if (mType == IBPP::stSelect) { // Could return a result set (none, single or multi rows) (*gds.Call()->m_dsql_execute)(status.Self(), mTransaction->GetHandlePtr(), &mHandle, 1, mInRow == 0 ? 0 : mInRow->Self()); if (status.Errors()) { //Close(); Commented because Execute error should not free the statement std::string context = "Statement::Execute( "; context.append(mSql).append(" )"); throw SQLExceptionImpl(status, context.c_str(), _("isc_dsql_execute failed")); } if (mOutRow != 0) { mResultSetAvailable = true; mCursorOpened = true; mIsSingleResult = false; mIsSingleResultDone = false; } } else if((mType == IBPP::stExecProcedure) && (mOutRow->Columns() != 0)) { (*gds.Call()->m_dsql_execute)(status.Self(), mTransaction->GetHandlePtr(), &mHandle, 1, mInRow == 0 ? 0 : mInRow->Self()); if (status.Errors()) { //Close(); Commented because Execute error should not free the statement std::string context = "Statement::Execute( "; context.append(mSql).append(" )"); throw SQLExceptionImpl(status, context.c_str(), _("isc_dsql_execute failed")); } if (mOutRow != 0) { mIsSingleResult = true; mIsSingleResultDone = false; } } else { // Should return at most a single row (*gds.Call()->m_dsql_execute2)(status.Self(), mTransaction->GetHandlePtr(), &mHandle, 1, mInRow == 0 ? 0 : mInRow->Self(), mOutRow == 0 ? 0 : mOutRow->Self()); if (status.Errors()) { //Close(); Commented because Execute error should not free the statement std::string context = "Statement::Execute( "; context.append(mSql).append(" )"); throw SQLExceptionImpl(status, context.c_str(), _("isc_dsql_execute2 failed")); } }}