|
From: <ale...@us...> - 2014-07-31 11:43:42
|
Revision: 59944
http://sourceforge.net/p/firebird/code/59944
Author: alexpeshkoff
Date: 2014-07-31 11:43:38 +0000 (Thu, 31 Jul 2014)
Log Message:
-----------
Fixed CORE-4505: Use of named cursor fails if statement was not executed. Should also fix CORE-4489, but I cannot check.
Modified Paths:
--------------
firebird/trunk/examples/interfaces/04.print_table.cpp
firebird/trunk/src/auth/SecureRemotePassword/manage/SrpManagement.cpp
firebird/trunk/src/dsql/dsql.cpp
firebird/trunk/src/include/firebird/Provider.h
firebird/trunk/src/jrd/EngineInterface.h
firebird/trunk/src/jrd/Mapping.cpp
firebird/trunk/src/jrd/jrd.cpp
firebird/trunk/src/remote/client/interface.cpp
firebird/trunk/src/remote/server/server.cpp
firebird/trunk/src/yvalve/YObjects.h
firebird/trunk/src/yvalve/why.cpp
Modified: firebird/trunk/examples/interfaces/04.print_table.cpp
===================================================================
--- firebird/trunk/examples/interfaces/04.print_table.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/examples/interfaces/04.print_table.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -93,7 +93,7 @@
"or RDB$VIEW_SOURCE is not null";
// Do not use IStatement - just ask attachment to open cursor
- curs = att->openCursor(st, tra, 0, sql, 3, NULL, NULL, NULL);
+ curs = att->openCursor(st, tra, 0, sql, 3, NULL, NULL, NULL, NULL);
check(st, "openCursor");
meta = curs->getMetadata(st);
Modified: firebird/trunk/src/auth/SecureRemotePassword/manage/SrpManagement.cpp
===================================================================
--- firebird/trunk/src/auth/SecureRemotePassword/manage/SrpManagement.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/auth/SecureRemotePassword/manage/SrpManagement.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -150,7 +150,7 @@
Message out;
Field<Varying> grantor(out, MAX_SQL_IDENTIFIER_SIZE);
Firebird::IResultSet* curs = att->openCursor(&s, tra, selGrantor.length(),
- selGrantor.c_str(), SQL_DIALECT_V6, NULL, NULL, out.getMetadata());
+ selGrantor.c_str(), SQL_DIALECT_V6, NULL, NULL, out.getMetadata(), NULL);
check(&s);
bool hasGrant = curs->fetchNext(&s, out.getBuffer());
Modified: firebird/trunk/src/dsql/dsql.cpp
===================================================================
--- firebird/trunk/src/dsql/dsql.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/dsql/dsql.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -426,7 +426,7 @@
const size_t MAX_CURSOR_LENGTH = 132 - 1;
string cursor = name;
- if (cursor.hasData() && cursor[0] == '\"')
+ if (cursor[0] == '\"')
{
// Quoted cursor names eh? Strip'em.
// Note that "" will be replaced with ".
@@ -477,13 +477,16 @@
// If there already is a cursor and its name isn't the same, ditto.
// We already know there is no cursor by this name in the hash table
- if (req_cursor.isEmpty())
+ if (req_cursor.isEmpty() || !(req_flags & dsql_req::FLAG_OPENED_CURSOR))
{
+ if (req_cursor.hasData())
+ req_dbb->dbb_cursors.remove(req_cursor);
req_cursor = cursor;
req_dbb->dbb_cursors.put(cursor, this);
}
else
{
+ fb_assert(!symbol);
ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-502) <<
Arg::Gds(isc_dsql_decl_err) <<
Arg::Gds(isc_dsql_cursor_redefined) << req_cursor);
Modified: firebird/trunk/src/include/firebird/Provider.h
===================================================================
--- firebird/trunk/src/include/firebird/Provider.h 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/include/firebird/Provider.h 2014-07-31 11:43:38 UTC (rev 59944)
@@ -141,7 +141,6 @@
virtual FB_BOOLEAN FB_CARG isEof(IStatus* status) = 0;
virtual FB_BOOLEAN FB_CARG isBof(IStatus* status) = 0;
virtual IMessageMetadata* FB_CARG getMetadata(IStatus* status) = 0;
- virtual void FB_CARG setCursorName(IStatus* status, const char* name) = 0;
virtual void FB_CARG close(IStatus* status) = 0;
// This item is for ISC API emulation only
@@ -149,7 +148,7 @@
// Please do not use it!
virtual void FB_CARG setDelayedOutputFormat(IStatus* status, IMessageMetadata* format) = 0;
};
-#define FB_RESULTSET_VERSION (FB_REFCOUNTED_VERSION + 12)
+#define FB_RESULTSET_VERSION (FB_REFCOUNTED_VERSION + 11)
class IStatement : public IRefCounted
{
@@ -186,10 +185,11 @@
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata, void* outBuffer) = 0;
virtual IResultSet* FB_CARG openCursor(IStatus* status, ITransaction* transaction,
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata) = 0;
+ virtual void FB_CARG setCursorName(IStatus* status, const char* name) = 0;
virtual void FB_CARG free(IStatus* status) = 0;
virtual unsigned FB_CARG getFlags(IStatus* status) = 0;
};
-#define FB_STATEMENT_VERSION (FB_REFCOUNTED_VERSION + 10)
+#define FB_STATEMENT_VERSION (FB_REFCOUNTED_VERSION + 11)
class IRequest : public IRefCounted
{
@@ -253,7 +253,8 @@
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata, void* outBuffer) = 0;
virtual IResultSet* FB_CARG openCursor(IStatus* status, ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned dialect,
- IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata) = 0;
+ IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata,
+ const char* cursorName) = 0;
virtual IEvents* FB_CARG queEvents(IStatus* status, IEventCallback* callback,
unsigned int length, const unsigned char* events) = 0;
virtual void FB_CARG cancelOperation(IStatus* status, int option) = 0;
Modified: firebird/trunk/src/jrd/EngineInterface.h
===================================================================
--- firebird/trunk/src/jrd/EngineInterface.h 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/jrd/EngineInterface.h 2014-07-31 11:43:38 UTC (rev 59944)
@@ -146,7 +146,6 @@
virtual FB_BOOLEAN FB_CARG isEof(Firebird::IStatus* status);
virtual FB_BOOLEAN FB_CARG isBof(Firebird::IStatus* status);
virtual Firebird::IMessageMetadata* FB_CARG getMetadata(Firebird::IStatus* status);
- virtual void FB_CARG setCursorName(Firebird::IStatus* status, const char* name);
virtual void FB_CARG close(Firebird::IStatus* status);
virtual void FB_CARG setDelayedOutputFormat(Firebird::IStatus* status, Firebird::IMessageMetadata* format);
@@ -190,6 +189,7 @@
virtual JResultSet* FB_CARG openCursor(Firebird::IStatus* status,
Firebird::ITransaction* transaction, Firebird::IMessageMetadata* inMetadata, void* inBuffer,
Firebird::IMessageMetadata* outMetadata);
+ virtual void FB_CARG setCursorName(Firebird::IStatus* status, const char* name);
virtual unsigned FB_CARG getFlags(Firebird::IStatus* status);
public:
@@ -331,7 +331,7 @@
virtual Firebird::IResultSet* FB_CARG openCursor(Firebird::IStatus* status,
Firebird::ITransaction* transaction, unsigned int stmtLength, const char* sqlStmt,
unsigned int dialect, Firebird::IMessageMetadata* inMetadata, void* inBuffer,
- Firebird::IMessageMetadata* outMetadata);
+ Firebird::IMessageMetadata* outMetadata, const char* cursorName);
virtual JEvents* FB_CARG queEvents(Firebird::IStatus* status, Firebird::IEventCallback* callback,
unsigned int length, const unsigned char* events);
virtual void FB_CARG cancelOperation(Firebird::IStatus* status, int option);
Modified: firebird/trunk/src/jrd/Mapping.cpp
===================================================================
--- firebird/trunk/src/jrd/Mapping.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/jrd/Mapping.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -278,7 +278,7 @@
"SELECT RDB$MAP_USING, RDB$MAP_PLUGIN, RDB$MAP_DB, RDB$MAP_FROM_TYPE, "
" RDB$MAP_FROM, RDB$MAP_TO_TYPE, RDB$MAP_TO "
"FROM RDB$AUTH_MAPPING",
- 3, NULL, NULL, mMap.getMetadata());
+ 3, NULL, NULL, mMap.getMetadata(), NULL);
if (!st.isSuccess())
{
if (fb_utils::containsErrorCode(st.get(), isc_dsql_relation_err))
@@ -1190,7 +1190,7 @@
"SELECT RDB$MAP_NAME, RDB$MAP_USING, RDB$MAP_PLUGIN, RDB$MAP_DB, "
" RDB$MAP_FROM_TYPE, RDB$MAP_FROM, RDB$MAP_TO_TYPE, RDB$MAP_TO "
"FROM RDB$AUTH_MAPPING",
- 3, NULL, NULL, mMap.getMetadata());
+ 3, NULL, NULL, mMap.getMetadata(), NULL);
if (!st.isSuccess())
{
if (!fb_utils::containsErrorCode(st.get(), isc_dsql_relation_err))
Modified: firebird/trunk/src/jrd/jrd.cpp
===================================================================
--- firebird/trunk/src/jrd/jrd.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/jrd/jrd.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -4474,7 +4474,8 @@
IResultSet* JAttachment::openCursor(IStatus* user_status, ITransaction* apiTra,
unsigned int length, const char* string, unsigned int dialect,
- IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata)
+ IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata,
+ const char* cursorName)
{
IStatement* tmpStatement = prepare(user_status, apiTra, length, string, dialect,
(outMetadata ? 0 : IStatement::PREPARE_PREFETCH_OUTPUT_PARAMETERS));
@@ -4483,6 +4484,16 @@
return NULL;
}
+ if (cursorName)
+ {
+ tmpStatement->setCursorName(user_status, cursorName);
+ if (!user_status->isSuccess())
+ {
+ tmpStatement->release();
+ return NULL;
+ }
+ }
+
IResultSet* rs = tmpStatement->openCursor(user_status, apiTra,
inMetadata, inBuffer, outMetadata);
@@ -5035,7 +5046,7 @@
}
-void JResultSet::setCursorName(IStatus* user_status, const char* cursor)
+void JStatement::setCursorName(IStatus* user_status, const char* cursor)
{
try
{
@@ -5044,9 +5055,7 @@
try
{
- dsql_req* req = getStatement()->getHandle();
- fb_assert(req);
- req->setCursor(tdbb, cursor);
+ getHandle()->setCursor(tdbb, cursor);
}
catch (const Exception& ex)
{
Modified: firebird/trunk/src/remote/client/interface.cpp
===================================================================
--- firebird/trunk/src/remote/client/interface.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/remote/client/interface.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -253,7 +253,6 @@
virtual FB_BOOLEAN FB_CARG isEof(IStatus* status);
virtual FB_BOOLEAN FB_CARG isBof(IStatus* status);
virtual IMessageMetadata* FB_CARG getMetadata(IStatus* status);
- virtual void FB_CARG setCursorName(IStatus* status, const char* name);
virtual void FB_CARG close(IStatus* status);
virtual void FB_CARG setDelayedOutputFormat(IStatus* status, IMessageMetadata* format);
@@ -308,6 +307,7 @@
IMessageMetadata* outMetadata, void* outBuffer);
virtual ResultSet* FB_CARG openCursor(IStatus* status, ITransaction* tra,
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outFormat);
+ virtual void FB_CARG setCursorName(IStatus* status, const char* name);
virtual void FB_CARG free(IStatus* status);
virtual unsigned FB_CARG getFlags(IStatus* status);
@@ -475,7 +475,8 @@
IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata, void* outBuffer);
virtual Firebird::IResultSet* FB_CARG openCursor(IStatus* status, ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned dialect,
- IMessageMetadata* inMetadata, void* inBuffer, Firebird::IMessageMetadata* outMetadata);
+ IMessageMetadata* inMetadata, void* inBuffer, Firebird::IMessageMetadata* outMetadata,
+ const char* cursorName);
virtual Firebird::IEvents* FB_CARG queEvents(IStatus* status, Firebird::IEventCallback* callback,
unsigned int length, const unsigned char* events);
virtual void FB_CARG cancelOperation(IStatus* status, int option);
@@ -1986,7 +1987,8 @@
IResultSet* FB_CARG Attachment::openCursor(IStatus* status, ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned dialect,
- IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata)
+ IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata,
+ const char* cursorName)
{
Statement* stmt = prepare(status, transaction, stmtLength, sqlStmt, dialect,
(outMetadata ? 0 : IStatement::PREPARE_PREFETCH_OUTPUT_PARAMETERS));
@@ -2002,6 +2004,17 @@
return NULL;
}
+ if (cursorName)
+ {
+ stmt->setCursorName(status, cursorName);
+ if (!status->isSuccess())
+ {
+ rc->release();
+ stmt->release();
+ return NULL;
+ }
+ }
+
rc->tmpStatement = true;
return rc;
}
@@ -3070,7 +3083,7 @@
}
-void ResultSet::setCursorName(IStatus* status, const char* cursor)
+void Statement::setCursorName(IStatus* status, const char* cursor)
{
/*****************************************
*
@@ -3101,16 +3114,9 @@
// Check and validate handles, etc.
- if (!stmt)
- {
- (Arg::Gds(isc_dsql_cursor_err) << Arg::Gds(isc_bad_req_handle)).raise();
- }
- Rsr* statement = stmt->getStatement();
+ Rsr* statement = getStatement();
CHECK_HANDLE(statement, isc_bad_req_handle);
-
Rdb* rdb = statement->rsr_rdb;
- CHECK_HANDLE(rdb, isc_bad_db_handle);
-
rem_port* port = rdb->rdb_port;
RefMutexGuard portGuard(*port->port_sync, FB_FUNCTION);
Modified: firebird/trunk/src/remote/server/server.cpp
===================================================================
--- firebird/trunk/src/remote/server/server.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/remote/server/server.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -2898,7 +2898,6 @@
return this->send_response(sendL, 0, 0, &status_vector, true);
}
statement->rsr_cursor = NULL;
- statement->rsr_cursor_name = "";
fb_assert(statement->rsr_rtr);
FB_SIZE_T pos;
if (!statement->rsr_rtr->rtr_cursors.find(statement, pos))
@@ -3230,14 +3229,6 @@
{
transaction->rtr_cursors.add(statement);
statement->rsr_delayed_format = !out_blr_length;
-
- if (statement->rsr_cursor_name.hasData())
- {
- statement->rsr_cursor->setCursorName(&status_vector, statement->rsr_cursor_name.c_str());
-
- if (status_vector.isSuccess())
- statement->rsr_cursor_name = "";
- }
}
}
else
@@ -4051,6 +4042,13 @@
if (!status_vector.isSuccess())
return this->send_response(sendL, 0, 0, &status_vector, false);
+ if (statement->rsr_cursor_name.hasData())
+ {
+ statement->rsr_iface->setCursorName(&status_vector, statement->rsr_cursor_name.c_str());
+ if (!status_vector.isSuccess())
+ return this->send_response(sendL, 0, 0, &status_vector, false);
+ }
+
LocalStatus s2;
statement->rsr_iface->getInfo(&s2, infoLength, info, prepareL->p_sqlst_buffer_length, buffer);
if (!s2.isSuccess())
@@ -4999,7 +4997,6 @@
Rsr* const statement = transaction->rtr_cursors.pop();
fb_assert(statement->rsr_cursor);
statement->rsr_cursor = NULL;
- statement->rsr_cursor_name = "";
}
for (Rtr** p = &rdb->rdb_transactions; *p; p = &(*p)->rtr_next)
@@ -5405,20 +5402,18 @@
getHandle(statement, sqlcur->p_sqlcur_statement);
-
- if (statement->rsr_cursor)
- statement->rsr_cursor->setCursorName(&status_vector, name);
- else
+ if (port_protocol < PROTOCOL_VERSION13 && statement->rsr_cursor_name.hasData() &&
+ statement->rsr_cursor_name != name)
{
- if (statement->rsr_cursor_name.hasData() && statement->rsr_cursor_name != name)
- {
- status_vector.set((Arg::Gds(isc_dsql_decl_err) <<
- Arg::Gds(isc_dsql_cursor_redefined) << statement->rsr_cursor_name).value());
- }
- else
- statement->rsr_cursor_name = name;
+ status_vector.set((Arg::Gds(isc_dsql_decl_err) <<
+ Arg::Gds(isc_dsql_cursor_redefined) << statement->rsr_cursor_name).value());
}
+ else
+ statement->rsr_cursor_name = name;
+ if (statement->rsr_iface)
+ statement->rsr_iface->setCursorName(&status_vector, name);
+
return this->send_response(sendL, 0, 0, &status_vector, false);
}
Modified: firebird/trunk/src/yvalve/YObjects.h
===================================================================
--- firebird/trunk/src/yvalve/YObjects.h 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/yvalve/YObjects.h 2014-07-31 11:43:38 UTC (rev 59944)
@@ -310,7 +310,6 @@
virtual FB_BOOLEAN FB_CARG isEof(Firebird::IStatus* status);
virtual FB_BOOLEAN FB_CARG isBof(Firebird::IStatus* status);
virtual Firebird::IMessageMetadata* FB_CARG getMetadata(Firebird::IStatus* status);
- virtual void FB_CARG setCursorName(Firebird::IStatus* status, const char* name);
virtual void FB_CARG close(Firebird::IStatus* status);
virtual void FB_CARG setDelayedOutputFormat(Firebird::IStatus* status, Firebird::IMessageMetadata* format);
@@ -358,6 +357,7 @@
Firebird::IMessageMetadata* outMetadata, void* outBuffer);
virtual Firebird::IResultSet* FB_CARG openCursor(Firebird::IStatus* status, Firebird::ITransaction* transaction,
Firebird::IMessageMetadata* inMetadata, void* inBuffer, Firebird::IMessageMetadata* outMetadata);
+ virtual void FB_CARG setCursorName(Firebird::IStatus* status, const char* name);
virtual void FB_CARG free(Firebird::IStatus* status);
virtual unsigned FB_CARG getFlags(Firebird::IStatus* status);
@@ -433,7 +433,8 @@
Firebird::IMessageMetadata* outMetadata, void* outBuffer);
virtual Firebird::IResultSet* FB_CARG openCursor(Firebird::IStatus* status, Firebird::ITransaction* transaction,
unsigned int stmtLength, const char* sqlStmt, unsigned int dialect,
- Firebird::IMessageMetadata* inMetadata, void* inBuffer, Firebird::IMessageMetadata* outMetadata);
+ Firebird::IMessageMetadata* inMetadata, void* inBuffer, Firebird::IMessageMetadata* outMetadata,
+ const char* cursorName);
virtual YEvents* FB_CARG queEvents(Firebird::IStatus* status, Firebird::IEventCallback* callback,
unsigned int length, const unsigned char* eventsData);
virtual void FB_CARG cancelOperation(Firebird::IStatus* status, int option);
Modified: firebird/trunk/src/yvalve/why.cpp
===================================================================
--- firebird/trunk/src/yvalve/why.cpp 2014-07-31 09:08:27 UTC (rev 59943)
+++ firebird/trunk/src/yvalve/why.cpp 2014-07-31 11:43:38 UTC (rev 59944)
@@ -1370,14 +1370,6 @@
fb_assert(statement->cursor);
- if (cursorName.hasData())
- {
- statement->cursor->setCursorName(status, cursorName.c_str());
-
- if (status->isSuccess())
- cursorName = "";
- }
-
delayedFormat = (outMetadata == DELAYED_OUT_FORMAT);
}
@@ -1408,7 +1400,6 @@
Arg::StatusVector(status->get()).raise();
statement = NULL;
- cursorName = "";
}
}
@@ -2345,13 +2336,6 @@
}
fb_assert(statement->statement->cursor);
-
- if (statement->cursorName.hasData())
- {
- statement->statement->cursor->setCursorName(&status, statement->cursorName.c_str());
- if (status.isSuccess())
- statement->cursorName = "";
- }
}
else
{
@@ -2798,18 +2782,15 @@
{
RefPtr<IscStatement> statement(translateHandle(statements, stmtHandle));
- if (statement->statement && statement->statement->cursor)
- statement->statement->cursor->setCursorName(&status, cursorName);
- else
+ if (statement->cursorName.hasData() && statement->cursorName != cursorName)
{
- if (statement->cursorName.hasData() && statement->cursorName != cursorName)
- {
- (Arg::Gds(isc_dsql_decl_err) <<
- Arg::Gds(isc_dsql_cursor_redefined) << statement->cursorName).raise();
- }
+ (Arg::Gds(isc_dsql_decl_err) <<
+ Arg::Gds(isc_dsql_cursor_redefined) << statement->cursorName).raise();
+ }
- statement->cursorName = cursorName;
- }
+ statement->cursorName = cursorName;
+ if (statement->statement)
+ statement->statement->setCursorName(&status, cursorName);
}
catch (const Exception& e)
{
@@ -4444,11 +4425,11 @@
destroy2(dstrFlags);
}
-void YResultSet::setCursorName(IStatus* status, const char* name)
+void YStatement::setCursorName(IStatus* status, const char* name)
{
try
{
- YEntry<YResultSet> entry(status, this);
+ YEntry<YStatement> entry(status, this);
entry.next()->setCursorName(status, name);
}
@@ -5173,7 +5154,8 @@
IResultSet* YAttachment::openCursor(IStatus* status, ITransaction* transaction,
unsigned int length, const char* string, unsigned int dialect,
- IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata)
+ IMessageMetadata* inMetadata, void* inBuffer, IMessageMetadata* outMetadata,
+ const char* cursorName)
{
IResultSet* rs = NULL;
try
@@ -5185,7 +5167,7 @@
getNextTransaction(status, transaction, trans);
rs = entry.next()->openCursor(status, trans, length, string, dialect,
- inMetadata, inBuffer, outMetadata);
+ inMetadata, inBuffer, outMetadata, cursorName);
if (!status->isSuccess())
{
return NULL;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|