Skip to content

Commit 0f430b4

Browse files
committed
On behalf of alexpeshkoff after sourceforge crash - Postfix for CORE-4811: display in ISQL database, user and role as server sees them
1 parent 3fc04a9 commit 0f430b4

File tree

1 file changed

+86
-18
lines changed

1 file changed

+86
-18
lines changed

src/isql/isql.epp

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5893,6 +5893,74 @@ static bool isyesno(const TEXT* buffer)
58935893
}
58945894

58955895

5896+
static bool printUser11()
5897+
{
5898+
if (!frontendTransaction())
5899+
return false;
5900+
5901+
const char* sql = "SELECT MON$ATTACHMENT_NAME, MON$USER, MON$ROLE "
5902+
"FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION";
5903+
5904+
Firebird::RefPtr<Firebird::IStatement> st(Firebird::REF_NO_INCR,
5905+
DB->prepare(fbStatus, fbTrans, 0, sql, 3, Firebird::IStatement::PREPARE_PREFETCH_METADATA));
5906+
if (failed())
5907+
return false;
5908+
Firebird::RefPtr<Firebird::IMessageMetadata> m(Firebird::REF_NO_INCR,
5909+
st->getOutputMetadata(fbStatus));
5910+
if (failed())
5911+
return false;
5912+
unsigned bs = m->getMessageLength(fbStatus);
5913+
if (failed())
5914+
return false;
5915+
Firebird::UCharBuffer outBuf;
5916+
UCHAR* buf = outBuf.getBuffer(bs);
5917+
st->execute(fbStatus, fbTrans, NULL, NULL, m, buf);
5918+
if (failed())
5919+
return false;
5920+
5921+
struct FieldInfo
5922+
{
5923+
const char* text;
5924+
const char* skip;
5925+
};
5926+
FieldInfo fieldInfo[3] = {
5927+
{"Database", NULL},
5928+
{"User", NULL},
5929+
{"Role", "NONE"}
5930+
};
5931+
5932+
bool wasOut = false;
5933+
for (unsigned i = 0; i < FB_NELEM(fieldInfo); ++i)
5934+
{
5935+
IsqlVar v;
5936+
if (ISQL_fill_var(&v, m, i, buf) == ps_ERR)
5937+
return false;
5938+
if (*v.nullInd)
5939+
continue;
5940+
5941+
Firebird::string txt;
5942+
switch(v.type & ~1)
5943+
{
5944+
case SQL_TEXT:
5945+
txt.assign(v.value.asChar, v.length);
5946+
break;
5947+
case SQL_VARYING:
5948+
txt.assign(v.value.asVary->vary_string, v.value.asVary->vary_length);
5949+
break;
5950+
}
5951+
txt.trim();
5952+
if (fieldInfo[i].skip && txt == fieldInfo[i].skip)
5953+
continue;
5954+
5955+
isqlGlob.printf("%s%s: %s", wasOut ? ", " : "", fieldInfo[i].text, txt.c_str());
5956+
wasOut = true;
5957+
}
5958+
if (wasOut)
5959+
isqlGlob.printf("%s", NEWLINE);
5960+
return true;
5961+
}
5962+
5963+
58965964
static processing_state newdb(TEXT* dbname,
58975965
const TEXT* usr,
58985966
const TEXT* psw,
@@ -6053,10 +6121,27 @@ static processing_state newdb(TEXT* dbname,
60536121
}
60546122
}
60556123

6124+
// CVC: We do not require those pesky transactions for -x or -a options.
6125+
// Metadata extraction works exclusively with default transaction gds__trans.
6126+
6127+
if (start_user_trans)
6128+
{
6129+
// Start the user transaction and default transaction
6130+
6131+
if (!M__trans)
6132+
{
6133+
M_Transaction();
6134+
if (D__trans)
6135+
commit_trans(&D__trans);
6136+
if (setValues.Autocommit)
6137+
D_Transaction();
6138+
}
6139+
}
6140+
60566141
// CVC: Do not put the user and pw used to extract metadata in a script!
60576142
// Only acknowledge user connection parameters in interactive logins.
60586143

6059-
if (Interactive)
6144+
if (Interactive && !printUser11())
60606145
{
60616146
if (local_usr[0] != '\0')
60626147
{
@@ -6080,23 +6165,6 @@ static processing_state newdb(TEXT* dbname,
60806165
}
60816166
}
60826167

6083-
// CVC: We do not require those pesky transactions for -x or -a options.
6084-
// Metadata extraction works exclusively with default transaction gds__trans.
6085-
6086-
if (start_user_trans)
6087-
{
6088-
// Start the user transaction and default transaction
6089-
6090-
if (!M__trans)
6091-
{
6092-
M_Transaction();
6093-
if (D__trans)
6094-
commit_trans(&D__trans);
6095-
if (setValues.Autocommit)
6096-
D_Transaction();
6097-
}
6098-
}
6099-
61006168
global_Stmt = NULL;
61016169

61026170
return SKIP;

0 commit comments

Comments
 (0)