水个SQL

This commit is contained in:
Mili 2023-01-30 23:04:54 +08:00
parent 47cbdd756a
commit c97f08ff0e
6 changed files with 113 additions and 55 deletions

View File

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Milimoe.FunGame.Core.Interface.Base; using Milimoe.FunGame.Core.Interface.Base;
using Milimoe.FunGame.Core.Library.Common.Network; using Milimoe.FunGame.Core.Library.Common.Network;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Service;
namespace Milimoe.FunGame.Core.Api.Data namespace Milimoe.FunGame.Core.Api.Data
{ {
@ -14,31 +15,41 @@ namespace Milimoe.FunGame.Core.Api.Data
{ {
public string Script { get; set; } = ""; public string Script { get; set; } = "";
public EntityType EntityType { get; private set; } = EntityType.Empty; public EntityType EntityType { get; }
public object Entity { get; private set; } = General.EntityInstance; public object Entity { get; } = General.EntityInstance;
public SQLResult Result { get; private set; } = SQLResult.Success; public SQLResult Result { get; }
public SQLServerInfo ServerInfo { get; private set; } = new SQLServerInfo(); public SQLServerInfo ServerInfo { get; }
public int UpdateRows { get; private set; } = 0; public int UpdateRows { get; }
public SQLHelper Instance { get; private set; } = new SQLHelper();
public static SQLHelper GetHelper(EntityType type) public static SQLHelper GetHelper(EntityType type)
{ {
return new SQLHelper(type); return new SQLHelper(type);
} }
private SQLHelper(EntityType type) private SQLHelper(EntityType type = EntityType.Empty, SQLServerInfo? info = null, SQLResult result = SQLResult.Success, int rows = 0)
{ {
this.EntityType = type; this.EntityType = type;
if (info == null) this.ServerInfo = SQLServerInfo.Create();
else this.ServerInfo = info;
this.Result = result;
this.UpdateRows = rows;
} }
private SQLHelper() public SQLResult Execute()
{ {
switch (EntityType)
{
case EntityType.NotEntity:
SQLManager SQLManager = new(this);
return SQLManager.Execute(Script);
default:
break;
}
return Result;
} }
} }
} }

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Interface.Base
{
internal abstract class BaseSQLService
{
internal abstract SQLResult Execute();
internal abstract SQLResult Execute(StringBuilder sql);
internal abstract SQLResult Execute(string sql);
internal abstract int Update(StringBuilder sql, ref SQLResult result);
internal abstract int Remove(StringBuilder sql, ref SQLResult result);
internal abstract int Add(StringBuilder sql, ref SQLResult result);
internal abstract int Update(string sql, ref SQLResult result);
internal abstract int Remove(string sql, ref SQLResult result);
internal abstract int Add(string sql, ref SQLResult result);
internal abstract object Query(EntityType type, StringBuilder sql);
internal abstract T Query<T>(StringBuilder sql);
internal abstract object Query(EntityType type, string sql);
internal abstract T Query<T>(string sql);
}
}

View File

@ -1,26 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Interface.Base
{
internal interface ISQLService
{
internal SQLResult Execute();
internal SQLResult Execute(StringBuilder sql);
internal SQLResult Execute(string sql);
internal int Update(StringBuilder sql, ref SQLResult result);
internal int Remove(StringBuilder sql, ref SQLResult result);
internal int Add(StringBuilder sql, ref SQLResult result);
internal int Update(string sql, ref SQLResult result);
internal int Remove(string sql, ref SQLResult result);
internal int Add(string sql, ref SQLResult result);
internal object Query(EntityType type, StringBuilder sql);
internal T Query<T>(StringBuilder sql);
internal object Query(EntityType type, string sql);
internal T Query<T>(string sql);
}
}

View File

@ -1,13 +1,51 @@
using System; using Milimoe.FunGame.Core.Entity;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace Milimoe.FunGame.Core.Library.Common.Network namespace Milimoe.FunGame.Core.Library.Common.Network
{ {
public class SQLServerInfo public class SQLServerInfo
{ {
public string SQLServerName { get; } = "";
public string SQLServerIP { get; } = "";
public string SQLServerPort { get; } = "";
public string SQLServerUser { get; } = "";
public string SQLServerPassword { get; } = "";
internal SQLServerInfo(InfoBuilder builder)
{
SQLServerName = builder.SQLServerName;
SQLServerIP = builder.SQLServerIP;
SQLServerPort = builder.SQLServerPort;
SQLServerUser = builder.SQLServerUser;
SQLServerPassword = builder.SQLServerPassword;
}
public static SQLServerInfo Create(string name = "", string ip = "", string port = "", string user = "", string password = "")
{
return new SQLServerInfo(new InfoBuilder(name, ip, port, user, password));
}
internal class InfoBuilder
{
internal string SQLServerName { get; } = "";
internal string SQLServerIP { get; } = "";
internal string SQLServerPort { get; } = "";
internal string SQLServerUser { get; } = "";
internal string SQLServerPassword { get; } = "";
internal InfoBuilder(string name, string ip, string port, string user, string password)
{
SQLServerName = name;
SQLServerIP = ip;
SQLServerPort = port;
SQLServerUser = user;
SQLServerPassword = password;
}
}
} }
} }

View File

@ -131,7 +131,8 @@ namespace Milimoe.FunGame.Core.Library.Constant
PassiveSkill, PassiveSkill,
GameStatistics, GameStatistics,
Character, Character,
CharacterStatistics CharacterStatistics,
NotEntity
} }
public enum TimeType public enum TimeType

View File

@ -1,77 +1,85 @@
using Milimoe.FunGame.Core.Interface.Base; using System;
using Milimoe.FunGame.Core.Library.Constant;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Milimoe.FunGame.Core.Api.Data;
using Milimoe.FunGame.Core.Interface.Base;
using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Core.Service namespace Milimoe.FunGame.Core.Service
{ {
internal class SQLManager : ISQLService internal class SQLManager : BaseSQLService
{ {
int ISQLService.Add(StringBuilder sql, ref SQLResult result) internal SQLHelper SQLHelper { get; }
internal SQLManager(SQLHelper SQLHelper)
{
this.SQLHelper = SQLHelper;
}
internal override int Add(StringBuilder sql, ref SQLResult result)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
int ISQLService.Add(string sql, ref SQLResult result) internal override int Add(string sql, ref SQLResult result)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
SQLResult ISQLService.Execute() internal override SQLResult Execute()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
SQLResult ISQLService.Execute(StringBuilder sql) internal override SQLResult Execute(StringBuilder sql)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
SQLResult ISQLService.Execute(string sql) internal override SQLResult Execute(string sql)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
object ISQLService.Query(EntityType type, StringBuilder sql) internal override object Query(EntityType type, StringBuilder sql)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
T ISQLService.Query<T>(StringBuilder sql) internal override T Query<T>(StringBuilder sql)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
object ISQLService.Query(EntityType type, string sql) internal override object Query(EntityType type, string sql)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
T ISQLService.Query<T>(string sql) internal override T Query<T>(string sql)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
int ISQLService.Remove(StringBuilder sql, ref SQLResult result) internal override int Remove(StringBuilder sql, ref SQLResult result)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
int ISQLService.Remove(string sql, ref SQLResult result) internal override int Remove(string sql, ref SQLResult result)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
int ISQLService.Update(StringBuilder sql, ref SQLResult result) internal override int Update(StringBuilder sql, ref SQLResult result)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
int ISQLService.Update(string sql, ref SQLResult result) internal override int Update(string sql, ref SQLResult result)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }