refactor(db/pgsql): Revert SQL queries, lower column casing for PGSQL
Reverts SQL query identifier escaping to simplify queries and improves overall readability by using lowercase column names. Enhances maintainability and alignment with database conventions by adopting a uniform casing scheme across all SQL operations. Removes unnecessary complexity in query construction, streamlining the database operations performed within the application.
This commit is contained in:
parent
4c13084eb3
commit
9c473e35a6
8 changed files with 79 additions and 111 deletions
|
|
@ -20,7 +20,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Npgsql;
|
||||
|
|
@ -43,14 +42,15 @@ namespace TShockAPI.DB
|
|||
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
|
||||
public static int Query(this IDbConnection olddb, string query, params object[] args)
|
||||
{
|
||||
using IDbConnection db = olddb.CloneEx();
|
||||
using var db = olddb.CloneEx();
|
||||
db.Open();
|
||||
using IDbCommand com = db.CreateCommand();
|
||||
|
||||
using var com = db.CreateCommand();
|
||||
com.CommandText = query;
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
com.AddParameter("@" + i, args[i] ?? DBNull.Value);
|
||||
com.AddParameter($"@{i}", args[i] ?? DBNull.Value);
|
||||
}
|
||||
|
||||
return com.ExecuteNonQuery();
|
||||
|
|
@ -272,18 +272,6 @@ namespace TShockAPI.DB
|
|||
|
||||
return (T)reader.GetValue(column);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Escapes an identifier for use in a SQL query.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier to escape, typically a table or column name.</param>
|
||||
/// <returns>The escaped identifier.</returns>
|
||||
[Pure]
|
||||
public static string EscapeSqlId(this string id, IDbConnection db) => db.GetSqlType() switch
|
||||
{
|
||||
SqlType.Postgres => $"\"{id}\"", // The main PITA and culprit
|
||||
_ => id // Default case for agnostic SQL
|
||||
};
|
||||
}
|
||||
|
||||
public enum SqlType
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue