Fix database error when searching with discriminator
This commit is contained in:
parent
1773fd2fc2
commit
4a5e07ba89
1 changed files with 8 additions and 4 deletions
|
@ -166,6 +166,9 @@ namespace Noikoio.RegexBot.EntityCache
|
||||||
disc = null;
|
disc = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip leading @ from name, if any
|
||||||
|
if (name.Length > 0 && name[0] == '@') name = name.Substring(1);
|
||||||
|
|
||||||
// Local cache search
|
// Local cache search
|
||||||
var lresult = LocalQueryAsync(c, guild, name, disc);
|
var lresult = LocalQueryAsync(c, guild, name, disc);
|
||||||
if (lresult.Count() != 0) return lresult;
|
if (lresult.Count() != 0) return lresult;
|
||||||
|
@ -211,15 +214,16 @@ namespace Noikoio.RegexBot.EntityCache
|
||||||
{
|
{
|
||||||
using (var c = db.CreateCommand())
|
using (var c = db.CreateCommand())
|
||||||
{
|
{
|
||||||
c.CommandText = $"SELECT {QueryColumns} FROM {SqlHelper.TableUser} WHERE "
|
c.CommandText = $"SELECT {QueryColumns} FROM {SqlHelper.TableUser} WHERE"
|
||||||
+ "( lower(username) = lower(@NameSearch) OR lower(nickname) = lower(@NameSearch) ) "
|
+ " ( lower(username) = lower(@NameSearch) OR lower(nickname) = lower(@NameSearch) )";
|
||||||
+ "ORDER BY cache_date desc, username";
|
|
||||||
c.Parameters.Add("@NameSearch", NpgsqlTypes.NpgsqlDbType.Text).Value = name;
|
|
||||||
if (disc != null)
|
if (disc != null)
|
||||||
{
|
{
|
||||||
c.CommandText += " AND discriminator = @DiscSearch";
|
c.CommandText += " AND discriminator = @DiscSearch";
|
||||||
c.Parameters.Add("@DiscSearch", NpgsqlTypes.NpgsqlDbType.Text).Value = disc;
|
c.Parameters.Add("@DiscSearch", NpgsqlTypes.NpgsqlDbType.Text).Value = disc;
|
||||||
}
|
}
|
||||||
|
c.CommandText += " ORDER BY cache_date desc, username";
|
||||||
|
c.Parameters.Add("@NameSearch", NpgsqlTypes.NpgsqlDbType.Text).Value = name;
|
||||||
|
|
||||||
c.Prepare();
|
c.Prepare();
|
||||||
|
|
||||||
using (var r = await c.ExecuteReaderAsync())
|
using (var r = await c.ExecuteReaderAsync())
|
||||||
|
|
Loading…
Reference in a new issue