Skip to content

Commit

Permalink
Merge pull request #666 from mjsalerno/fix-postgres
Browse files Browse the repository at this point in the history
Fix postgres
  • Loading branch information
alborrajo authored Dec 23, 2024
2 parents 4ae8eed + 5acc1b6 commit 0baa6fe
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE "ddon_clan_param"
(
"clan_id" INTEGER PRIMARY KEY NOT NULL,
"clan_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"clan_level" INTEGER NOT NULL,
"member_num" INTEGER NOT NULL,
"master_id" INTEGER NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ CREATE TABLE "ddon_system_mail_attachment" (
"attachment_id" INTEGER NOT NULL,
"message_id" INTEGER NOT NULL,
"attachment_type" INTEGER NOT NULL,
"is_received" INTEGER NOT NULL DEFAULT 0,
"is_received" BOOLEAN NOT NULL DEFAULT FALSE,
"param0" VARCHAR(256) NOT NULL DEFAULT "",
"param1" INTEGER NOT NULL DEFAULT 0,
"param2" INTEGER NOT NULL DEFAULT 0,
"param3" INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY("attachment_id" AUTOINCREMENT),
FOREIGN KEY("message_id") REFERENCES "ddon_system_mail"("message_id") ON DELETE CASCADE
);
);
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ CREATE TABLE "ddon_system_mail_attachment" (
"message_id" INTEGER NOT NULL,
"attachment_id" INTEGER NOT NULL,
"attachment_type" INTEGER NOT NULL,
"is_received" INTEGER NOT NULL DEFAULT 0,
"is_received" BOOLEAN NOT NULL DEFAULT FALSE,
"param0" VARCHAR(256) NOT NULL DEFAULT "",
"param1" INTEGER NOT NULL DEFAULT 0,
"param2" INTEGER NOT NULL DEFAULT 0,
"param3" INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY("message_id") REFERENCES "ddon_system_mail"("message_id") ON DELETE CASCADE
);
);
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ CREATE TABLE IF NOT EXISTS "ddon_system_mail_attachment"
"attachment_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"message_id" INTEGER NOT NULL,
"attachment_type" INTEGER NOT NULL,
"is_received" INTEGER NOT NULL DEFAULT 0,
"is_received" BOOLEAN NOT NULL DEFAULT FALSE,
"param0" VARCHAR(256) NOT NULL DEFAULT '',
"param1" INTEGER NOT NULL DEFAULT 0,
"param2" INTEGER NOT NULL DEFAULT 0,
Expand Down Expand Up @@ -715,7 +715,7 @@ CREATE TABLE IF NOT EXISTS "ddon_bbm_content_treasure"

CREATE TABLE IF NOT EXISTS "ddon_clan_param"
(
"clan_id" INTEGER PRIMARY KEY NOT NULL,
"clan_id" INTEGER PRIMARY KEY AUTOINCREMENT,
"clan_level" INTEGER NOT NULL,
"member_num" INTEGER NOT NULL,
"master_id" INTEGER NOT NULL,
Expand Down
5 changes: 5 additions & 0 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ public void AddParameter(DbCommand command, string name, float value)
{
base.AddParameter((TCom)command, name, value);
}

public void AddParameter(DbCommand command, string name, ulong value)
{
base.AddParameter((TCom)command, name, value);
}

public void AddParameter(DbCommand command, string name, byte value)
{
Expand Down
11 changes: 8 additions & 3 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbBazaarExhibition.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using Arrowgene.Ddon.Shared.Model;
Expand All @@ -24,12 +25,12 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,
private static readonly string SqlSelectActiveBazaarExhibitionsByItemIdExcludingOwn = $"SELECT \"bazaar_id\", {BuildQueryField(BazaarExhibitionFields)} FROM \"{BazaarExhibitionTableName}\" " +
$"WHERE \"item_id\" = @item_id " +
$"AND \"state\" = {(byte)BazaarExhibitionState.OnSale} " +
$"AND \"expire\" > DATETIME(\"now\") " +
$"AND \"expire\" > @now " +
$"AND \"character_id\" <> @excluded_character_id " +
$"ORDER BY price ASC;";

private static readonly string SqlDeleteBazaarExhibitionByBazaarId = $"DELETE FROM \"{BazaarExhibitionTableName}\" WHERE \"bazaar_id\"=@bazaar_id;";
private static readonly string SqlDeleteBazaarExhibitionOutdated = $"DELETE FROM \"{BazaarExhibitionTableName}\" WHERE \"state\"={(byte)BazaarExhibitionState.Idle} AND \"expire\" < DATETIME(\"now\");";
private static readonly string SqlDeleteBazaarExhibitionOutdated = $"DELETE FROM \"{BazaarExhibitionTableName}\" WHERE \"state\"={(byte)BazaarExhibitionState.Idle} AND \"expire\" < @now;";


private static readonly string SqlUpdateBazaarExhibitionByBazaarId = $"UPDATE \"{BazaarExhibitionTableName}\" SET {BuildQueryUpdate(BazaarExhibitionFields)} WHERE \"bazaar_id\"=@bazaar_id";
Expand Down Expand Up @@ -95,7 +96,10 @@ public int DeleteBazaarExhibitionsOutdated()

public int DeleteBazaarExhibitionsOutdated(TCon conn)
{
int rowsAffected = ExecuteNonQuery(conn, SqlDeleteBazaarExhibitionOutdated, command => {});
int rowsAffected = ExecuteNonQuery(conn, SqlDeleteBazaarExhibitionOutdated, command =>
{
AddParameter(command, "@now", DateTimeOffset.UtcNow.UtcDateTime);
});
return rowsAffected;
}

Expand Down Expand Up @@ -167,6 +171,7 @@ public List<BazaarExhibition> SelectActiveBazaarExhibitionsByItemIdExcludingOwn(
{
AddParameter(command, "@item_id", itemId);
AddParameter(command, "@excluded_character_id", excludedCharacterId);
AddParameter(command, "@now", DateTimeOffset.UtcNow.UtcDateTime);
}, reader =>
{
while (reader.Read())
Expand Down
10 changes: 6 additions & 4 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,
private static readonly string SqlSelectCharacterArisenProfile = $"SELECT {BuildQueryField(CDataArisenProfileFields)} FROM \"ddon_character_arisen_profile\" WHERE \"character_id\" = @character_id;";
private const string SqlDeleteCharacterArisenProfile = "DELETE FROM \"ddon_character_arisen_profile\" WHERE \"character_id\"=@character_id;";

private readonly string SqlReplaceCharacterBinaryData = $"REPLACE INTO \"ddon_binary_data\" ({BuildQueryField(CharacterBinaryDataFields)}) VALUES ({BuildQueryInsert(CharacterBinaryDataFields)});";
private readonly string SqlInsertCharacterBinaryData = $"INSERT INTO \"ddon_binary_data\" ({BuildQueryField(CharacterBinaryDataFields)}) VALUES ({BuildQueryInsert(CharacterBinaryDataFields)});";
private readonly string SqlUpdateCharacterBinaryData = $"UPDATE \"ddon_binary_data\" SET {BuildQueryUpdate(CharacterBinaryDataFields)} WHERE \"character_id\" = @character_id;";
private static readonly string SqlSelectCharacterBinaryData = $"SELECT {BuildQueryField(CharacterBinaryDataFields)} FROM \"ddon_binary_data\" WHERE \"character_id\" = @character_id;";

public bool CreateCharacter(Character character)
Expand All @@ -106,7 +107,7 @@ public bool CreateCharacter(Character character)
ExecuteNonQuery(conn, SqlInsertStatusInfo, command => { AddParameter(command, character); });
ExecuteNonQuery(conn, SqlInsertCharacterMatchingProfile, command => { AddParameter(command, character); });
ExecuteNonQuery(conn, SqlInsertCharacterArisenProfile, command => { AddParameter(command, character); });
ExecuteNonQuery(conn, SqlReplaceCharacterBinaryData, command => { AddParameter(command, character);});
ExecuteNonQuery(conn, SqlInsertCharacterBinaryData, command => { AddParameter(command, character);});

CreateItems(conn, character);

Expand Down Expand Up @@ -325,7 +326,8 @@ private void QueryCharacterData(TCon conn, Character character)
item.PlusValue = GetByte(reader2, "plus_value");
item.EquipPoints = GetUInt32(reader2, "equip_points");

ExecuteReader(conn, SqlSelectAllCrestData,
using TCon connection = OpenNewConnection();
ExecuteReader(connection, SqlSelectAllCrestData,
command4 => {
AddParameter(command4, "character_common_id", character.CommonId);
AddParameter(command4, "item_uid", item.UId);
Expand Down Expand Up @@ -755,7 +757,7 @@ public bool UpdateCharacterBinaryData(uint characterId, byte[] data)

public bool UpdateCharacterBinaryData(TCon conn, uint characterId, byte[] data)
{
int rowsAffected = ExecuteNonQuery(conn, SqlReplaceCharacterBinaryData, command =>
int rowsAffected = ExecuteNonQuery(conn, SqlUpdateCharacterBinaryData, command =>
{
AddParameter(command, "@character_id", characterId);
AddParameter(command, "@binary_data", data);
Expand Down
5 changes: 3 additions & 2 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacterCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private void QueryCharacterCommonData(DbConnection conn, CharacterCommon common)
item.Color = GetByte(reader2, "color");
item.PlusValue = GetByte(reader2, "plus_value");
item.EquipPoints = GetUInt32(reader2, "equip_points");
ExecuteReader(connection, SqlSelectAllCrestData,
using TCon connection2 = OpenNewConnection();
ExecuteReader(connection2, SqlSelectAllCrestData,
command3 => {
AddParameter(command3, "character_common_id", common.CommonId);
AddParameter(command3, "item_uid", item.UId);
Expand All @@ -151,7 +152,7 @@ private void QueryCharacterCommonData(DbConnection conn, CharacterCommon common)
var result = ReadCrestData(reader4);
item.EquipElementParamList.Add(result.ToCDataEquipElementParam());
}
});
});

common.EquipmentTemplate.SetEquipItem(item, job, equipType, equipSlot);
}
Expand Down
55 changes: 39 additions & 16 deletions Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbContactList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,45 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,

private static readonly string SqlUpdateContactByCharIds = $"UPDATE \"{ContactListTableName}\" SET \"status\"=@status, \"type\"=@type, \"requester_favorite\"=@requester_favorite, \"requested_favorite\"=@requested_favorite WHERE \"requester_character_id\"=@requester_character_id and \"requested_character_id\"=@requested_character_id;";

private static readonly string SqlSelectFullContactsByCharacterId = @"SELECT ""ddon_contact_list"".*,
""ddon_character"".""first_name"", ""ddon_character"".""last_name"",
""ddon_character_job_data"".""job"", ""ddon_character_job_data"".""lv"",
""ddon_character_matching_profile"".""comment"",
CASE WHEN CASE WHEN ""ddon_contact_list"".""requester_character_id"" = @character_id THEN ""ddon_contact_list"".""requested_character_id"" ELSE ""ddon_contact_list"".""requester_character_id"" END NOT IN (SELECT ""character_id"" FROM ""ddon_clan_membership"") THEN """"
ELSE (SELECT ""ddon_clan_param"".""name"" as ""clan_name"" FROM ""ddon_clan_param"" INNER JOIN ""ddon_clan_membership"" ON ""ddon_clan_membership"".""clan_id"" = ""ddon_clan_param"".""clan_id"" WHERE ""ddon_clan_membership"".""character_id"" = CASE WHEN ""ddon_contact_list"".""requester_character_id"" = @character_id THEN ""ddon_contact_list"".""requested_character_id"" ELSE ""ddon_contact_list"".""requester_character_id"" END)
END AS ""clan_name"",
CASE WHEN ""ddon_contact_list"".""requester_character_id"" = @character_id THEN ""ddon_contact_list"".""requested_character_id""
ELSE ""ddon_contact_list"".""requester_character_id""
END AS ""other_id""
FROM ""ddon_contact_list""
INNER JOIN ""ddon_character"" ON ""ddon_character"".""character_id"" = ""other_id""
INNER JOIN ""ddon_character_common"" ON ""ddon_character_common"".""character_common_id"" = ""ddon_character"".""character_common_id""
INNER JOIN ""ddon_character_job_data"" ON ""ddon_character_job_data"".""character_common_id"" = ""ddon_character"".""character_common_id"" AND ""ddon_character_job_data"".""job"" = ""ddon_character_common"".""job""
INNER JOIN ""ddon_character_matching_profile"" ON ""ddon_character_matching_profile"".""character_id"" = ""other_id""
WHERE ""requested_character_id"" = @character_id OR ""requester_character_id"" = @character_id;";
private static readonly string SqlSelectFullContactsByCharacterId = @"SELECT
cl.*,
c.first_name,
c.last_name,
j.job,
j.lv,
mp.comment,
CASE
WHEN cl.requester_character_id = @character_id THEN
(SELECT cp.name FROM ddon_clan_param cp
INNER JOIN ddon_clan_membership cm ON cm.clan_id = cp.clan_id
WHERE cm.character_id = cl.requested_character_id)
ELSE
(SELECT cp.name FROM ddon_clan_param cp
INNER JOIN ddon_clan_membership cm ON cm.clan_id = cp.clan_id
WHERE cm.character_id = cl.requester_character_id)
END AS clan_name,
CASE
WHEN cl.requester_character_id = @character_id THEN
cl.requested_character_id
ELSE
cl.requester_character_id
END AS other_id
FROM
ddon_contact_list cl
INNER JOIN ddon_character c ON c.character_id =
CASE
WHEN cl.requester_character_id = @character_id THEN cl.requested_character_id
ELSE cl.requester_character_id
END
INNER JOIN ddon_character_common cc ON cc.character_common_id = c.character_common_id
INNER JOIN ddon_character_job_data j ON j.character_common_id = cc.character_common_id AND j.job = cc.job
INNER JOIN ddon_character_matching_profile mp ON mp.character_id =
CASE
WHEN cl.requester_character_id = @character_id THEN cl.requested_character_id
ELSE cl.requester_character_id
END
WHERE
cl.requested_character_id = @character_id OR cl.requester_character_id = @character_id;";

public int InsertContact(uint requestingCharacterId, uint requestedCharacterId, ContactListStatus status, ContactListType type, bool requesterFavorite, bool requestedFavorite)
{
Expand Down
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public abstract partial class DdonSqlDb<TCon, TCom, TReader> : SqlDb<TCon, TCom,
private const string SqlSelectOfficialPawns =
@"SELECT * FROM ddon_pawn WHERE is_official_pawn=1;";
private const string SqlSelectAllPlayerPawns =
@"SELECT * FROM ddon_pawn WHERE is_official_pawn=0 LIMIT @limit;";
@"SELECT * FROM ddon_pawn WHERE is_official_pawn=false LIMIT @limit;";
private const string SqlSelectPawnOwnerId =
$"SELECT * FROM ddon_pawn WHERE \"pawn_id\" = @pawn_id;";
private const string SqlSelectRegisteredPawns =
Expand Down
5 changes: 5 additions & 0 deletions Arrowgene.Ddon.Database/Sql/SqlDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ public void AddParameter(TCom command, string name, float value)
{
AddParameter(command, name, value, DbType.Double);
}

public void AddParameter(TCom command, string name, ulong value)
{
AddParameter(command, name, (long)value, DbType.Int64);
}

public void AddParameter(TCom command, string name, byte value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override S2CPawnGetNoraPawnListRes Handle(GameClient client, C2SPawnGetNo
// client.Send(GameFull.Dump_118);
var result = new S2CPawnGetNoraPawnListRes();

List<uint> pawnIds = Server.Database.SelectAllPlayerPawns(uint.MaxValue);
List<uint> pawnIds = Server.Database.SelectAllPlayerPawns(int.MaxValue);
result.NoraPawnList = pawnIds.OrderBy(x => Random.Shared.Next()).Take(100).Select(x => new CDataRegisterdPawnList() { PawnId = x }).ToList();
return result;
}
Expand Down

0 comments on commit 0baa6fe

Please sign in to comment.