Skip to content

Commit

Permalink
implement SELECT DATABASE()
Browse files Browse the repository at this point in the history
That is fake statement, always returns single-row 'Manticore'.

That fixes #3536
  • Loading branch information
klirichek committed May 24, 2023
1 parent aa4fad0 commit a0735ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/searchd.cpp
Expand Up @@ -16597,11 +16597,22 @@ bool ClientSession_c::Execute ( Str_t sQuery, RowBuffer_i & tOut )
tCrashQuery.m_dQuery = { (const BYTE*) sQuery.first, sQuery.second };

// ad-hoc, make generalized select()
if ( StrEq ( sQuery.first, "select DATABASE(), USER() limit 1" ) )
if ( StrEqN ( sQuery.first, "select DATABASE()" ) )
{
// result set header packet
tOut.HeadOfStrings ( { "DATABASE()" } );
tOut.PutString ( g_sDbName );
tOut.Commit();
tOut.Eof ( false );
return true;
}

// notice order! if sQuery is 'select DATABASE()' it will match this condition, but it is already processed by ad-hoc above
if ( StrEqN ( sQuery, "select DATABASE(), USER() limit 1" ) )
{
// result set header packet
tOut.HeadTuplet ( "DATABASE()", "USER()" );
tOut.DataTuplet ( g_sDbName.cstr(), tSess.GetVip () ? "VIP" : "Usual" );
tOut.DataTuplet ( g_sDbName.cstr(), tSess.GetVip() ? "VIP" : "Usual" );
tOut.Eof ( false );
return true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/std/string_impl.h
Expand Up @@ -39,6 +39,13 @@ inline bool StrEq ( Str_t l, const char * r )
return strncmp ( l.first, r, l.second ) == 0;
}

inline bool StrEqN ( Str_t l, const char* r )
{
if ( IsEmpty ( l ) || !r )
return ( ( !r && IsEmpty ( l ) ) || ( IsEmpty ( l ) && !*r ) );
return strncasecmp ( l.first, r, l.second ) == 0;
}

inline Str_t FromStr ( const CSphString& sString ) noexcept
{
return { sString.cstr(), (int)sString.Length() };
Expand Down

0 comments on commit a0735ff

Please sign in to comment.