From d34567b176c274d0067473bb31a9c080c48aa607 Mon Sep 17 00:00:00 2001 From: Mike Salerno Date: Sun, 17 Nov 2024 13:07:47 -0500 Subject: [PATCH 1/4] WIP: fixing postgres --- Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs | 5 +++++ .../Sql/Core/DdonSqlDbBazaarExhibition.cs | 11 ++++++++--- .../Sql/Core/DdonSqlDbCharacter.cs | 10 ++++++---- .../Sql/Core/DdonSqlDbCharacterCommon.cs | 5 +++-- Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs | 2 +- Arrowgene.Ddon.Database/Sql/SqlDb.cs | 5 +++++ .../Handler/PawnGetNoraPawnListHandler.cs | 2 +- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs index 278061d1d..dd8268fe6 100644 --- a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs +++ b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDb.cs @@ -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) { diff --git a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbBazaarExhibition.cs b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbBazaarExhibition.cs index ef50987ea..9ae4ee90f 100644 --- a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbBazaarExhibition.cs +++ b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbBazaarExhibition.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Data.Common; using Arrowgene.Ddon.Shared.Model; @@ -24,12 +25,12 @@ public abstract partial class DdonSqlDb : SqlDb 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"; @@ -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; } @@ -167,6 +171,7 @@ public List SelectActiveBazaarExhibitionsByItemIdExcludingOwn( { AddParameter(command, "@item_id", itemId); AddParameter(command, "@excluded_character_id", excludedCharacterId); + AddParameter(command, "@now", DateTimeOffset.UtcNow.UtcDateTime); }, reader => { while (reader.Read()) diff --git a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacter.cs b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacter.cs index ed73286b6..58f30bf66 100644 --- a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacter.cs +++ b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacter.cs @@ -82,7 +82,8 @@ public abstract partial class DdonSqlDb : SqlDb { 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); @@ -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); @@ -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); diff --git a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacterCommon.cs b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacterCommon.cs index d083dc9e6..df6a92572 100644 --- a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacterCommon.cs +++ b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbCharacterCommon.cs @@ -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); @@ -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); } diff --git a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs index 174a92dbf..0a2af21a5 100644 --- a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs +++ b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbPawn.cs @@ -75,7 +75,7 @@ public abstract partial class DdonSqlDb : SqlDb pawnIds = Server.Database.SelectAllPlayerPawns(uint.MaxValue); + List 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; } From fd053eb280df0e070eb0c5c2f953f337560937b3 Mon Sep 17 00:00:00 2001 From: Mike Salerno Date: Sun, 17 Nov 2024 16:22:54 -0500 Subject: [PATCH 2/4] redo giant community list case sql --- .../Sql/Core/DdonSqlDbContactList.cs | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbContactList.cs b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbContactList.cs index b31a91b2f..ac991d01a 100644 --- a/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbContactList.cs +++ b/Arrowgene.Ddon.Database/Sql/Core/DdonSqlDbContactList.cs @@ -34,22 +34,45 @@ public abstract partial class DdonSqlDb : SqlDb Date: Mon, 18 Nov 2024 09:49:39 -0500 Subject: [PATCH 3/4] make clan_id an autoincrement column --- .../Files/Database/Script/clan_migration.sql | 2 +- Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Arrowgene.Ddon.Database/Files/Database/Script/clan_migration.sql b/Arrowgene.Ddon.Database/Files/Database/Script/clan_migration.sql index 607b792b4..b98054317 100644 --- a/Arrowgene.Ddon.Database/Files/Database/Script/clan_migration.sql +++ b/Arrowgene.Ddon.Database/Files/Database/Script/clan_migration.sql @@ -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, diff --git a/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql b/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql index 1a898d2bb..565206abc 100644 --- a/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql +++ b/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql @@ -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, From 5acc1b621e6dcadec050b49b0f2c32880abb7666 Mon Sep 17 00:00:00 2001 From: Mike Salerno Date: Wed, 27 Nov 2024 22:28:19 -0500 Subject: [PATCH 4/4] fix data type of boolean column so postgres works --- .../Files/Database/Script/equip_migration_sqlite.sql | 4 ++-- .../Files/Database/Script/migration_mail_sqlite.sql | 4 ++-- .../Files/Database/Script/schema_sqlite.sql | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Arrowgene.Ddon.Database/Files/Database/Script/equip_migration_sqlite.sql b/Arrowgene.Ddon.Database/Files/Database/Script/equip_migration_sqlite.sql index d1731a82e..35d2bf3e7 100644 --- a/Arrowgene.Ddon.Database/Files/Database/Script/equip_migration_sqlite.sql +++ b/Arrowgene.Ddon.Database/Files/Database/Script/equip_migration_sqlite.sql @@ -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 -); \ No newline at end of file +); diff --git a/Arrowgene.Ddon.Database/Files/Database/Script/migration_mail_sqlite.sql b/Arrowgene.Ddon.Database/Files/Database/Script/migration_mail_sqlite.sql index 54bd51836..52da82d1e 100644 --- a/Arrowgene.Ddon.Database/Files/Database/Script/migration_mail_sqlite.sql +++ b/Arrowgene.Ddon.Database/Files/Database/Script/migration_mail_sqlite.sql @@ -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 -); \ No newline at end of file +); diff --git a/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql b/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql index 565206abc..d4d4b79be 100644 --- a/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql +++ b/Arrowgene.Ddon.Database/Files/Database/Script/schema_sqlite.sql @@ -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,