mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 14:03:07 +01:00
Postfix for #6897, thanks to Adriano & Dmitry
This commit is contained in:
parent
852230aaa4
commit
422aa7aca8
@ -6391,6 +6391,8 @@ static bool printUser(const char* dbName)
|
||||
case fb_info_sqlrole:
|
||||
len = gds__vax_integer(p, 2);
|
||||
role.assign(p + 2, len);
|
||||
if (role == "NONE")
|
||||
role.erase();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -6401,19 +6403,108 @@ static bool printUser(const char* dbName)
|
||||
p += (2 + len);
|
||||
}
|
||||
|
||||
if (login.hasData() || role.hasData())
|
||||
{
|
||||
bool wasOut = dbName && dbName[0];
|
||||
if (wasOut)
|
||||
isqlGlob.printf("Database: %s", dbName);
|
||||
|
||||
if (login.hasData())
|
||||
{
|
||||
isqlGlob.printf("%sUser: %s", wasOut ? ", " : "", login.c_str());
|
||||
wasOut = true;
|
||||
}
|
||||
|
||||
if (role.hasData())
|
||||
{
|
||||
isqlGlob.printf("%sRole: %s", wasOut ? ", " : "", role.c_str());
|
||||
wasOut = true;
|
||||
}
|
||||
|
||||
if (wasOut)
|
||||
isqlGlob.printf("%s", NEWLINE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// fallback to SQL way to do job
|
||||
|
||||
if (!frontendTransaction())
|
||||
return false;
|
||||
|
||||
class FbTransCommit
|
||||
{
|
||||
public:
|
||||
~FbTransCommit()
|
||||
{
|
||||
if (DB && fbTrans)
|
||||
{
|
||||
fbTrans->rollback(fbStatus);
|
||||
if (succeeded())
|
||||
fbTrans = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
FbTransCommit fbTransCommit;
|
||||
|
||||
const char* sql = "SELECT CURRENT_USER, CURRENT_ROLE FROM RDB$DATABASE";
|
||||
|
||||
Firebird::RefPtr<Firebird::IStatement> st(Firebird::REF_NO_INCR,
|
||||
DB->prepare(fbStatus, fbTrans, 0, sql, 3, Firebird::IStatement::PREPARE_PREFETCH_METADATA));
|
||||
if (failed())
|
||||
return false;
|
||||
Firebird::RefPtr<Firebird::IMessageMetadata> m(Firebird::REF_NO_INCR,
|
||||
st->getOutputMetadata(fbStatus));
|
||||
if (failed())
|
||||
return false;
|
||||
unsigned bs = m->getMessageLength(fbStatus);
|
||||
if (failed())
|
||||
return false;
|
||||
Firebird::UCharBuffer outBuf;
|
||||
UCHAR* buf = outBuf.getBuffer(bs);
|
||||
st->execute(fbStatus, fbTrans, NULL, NULL, m, buf);
|
||||
if (failed())
|
||||
return false;
|
||||
|
||||
struct FieldInfo
|
||||
{
|
||||
const char* text;
|
||||
const char* skip;
|
||||
};
|
||||
FieldInfo fieldInfo[2] = {
|
||||
{"User", NULL},
|
||||
{"Role", "NONE"}
|
||||
};
|
||||
|
||||
bool wasOut = dbName && dbName[0];
|
||||
if (wasOut)
|
||||
isqlGlob.printf("Database: %s", dbName);
|
||||
|
||||
if (login.hasData())
|
||||
for (unsigned i = 0; i < FB_NELEM(fieldInfo); ++i)
|
||||
{
|
||||
isqlGlob.printf("%sUser: %s", wasOut ? ", " : "", login.c_str());
|
||||
wasOut = true;
|
||||
}
|
||||
IsqlVar v;
|
||||
if (ISQL_fill_var(&v, m, i, buf) == ps_ERR)
|
||||
return false;
|
||||
if (*v.nullInd)
|
||||
continue;
|
||||
|
||||
if (role.hasData() && role != "NONE")
|
||||
{
|
||||
isqlGlob.printf("%sRole: %s", wasOut ? ", " : "", role.c_str());
|
||||
Firebird::string txt;
|
||||
switch(v.type & ~1)
|
||||
{
|
||||
case SQL_TEXT:
|
||||
txt.assign(v.value.asChar, v.length);
|
||||
break;
|
||||
case SQL_VARYING:
|
||||
txt.assign(v.value.asVary->vary_string, v.value.asVary->vary_length);
|
||||
break;
|
||||
}
|
||||
|
||||
txt.trim();
|
||||
|
||||
if (fieldInfo[i].skip && txt == fieldInfo[i].skip)
|
||||
continue;
|
||||
|
||||
isqlGlob.printf("%s%s: %s", wasOut ? ", " : "", fieldInfo[i].text, txt.c_str());
|
||||
wasOut = true;
|
||||
}
|
||||
|
||||
|
@ -911,11 +911,9 @@ void INF_database_info(thread_db* tdbb,
|
||||
|
||||
case fb_info_username:
|
||||
{
|
||||
MetaName user;
|
||||
MetaString user;
|
||||
if (att->att_user)
|
||||
user = att->att_user->getUserName();
|
||||
if (user.isEmpty())
|
||||
user = "<* unknown *>";
|
||||
if (!(info = INF_put_item(item, user.length(), user.c_str(), info, end)))
|
||||
return;
|
||||
}
|
||||
@ -923,11 +921,9 @@ void INF_database_info(thread_db* tdbb,
|
||||
|
||||
case fb_info_sqlrole:
|
||||
{
|
||||
MetaName role;
|
||||
MetaString role;
|
||||
if (att->att_user)
|
||||
role = att->att_user->getSqlRole();
|
||||
if (role.isEmpty())
|
||||
role = "<* unknown *>";
|
||||
if (!(info = INF_put_item(item, role.length(), role.c_str(), info, end)))
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user