Fixed ClassAction not being public
Moved SqlSerialise to Function
This commit is contained in:
parent
0f38c92bbe
commit
8de75728e0
@ -5,7 +5,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace eu.railduction.netcore.dll.Database_Attribute_System
|
namespace eu.railduction.netcore.dll.Database_Attribute_System
|
||||||
{
|
{
|
||||||
class ClassAction
|
public class ClassAction
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fills an given dbObject with given data<para/>
|
/// Fills an given dbObject with given data<para/>
|
||||||
|
@ -131,33 +131,9 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|||||||
if (i % 2 == 0) query += paramz[i]; // Every 'even' count will just add
|
if (i % 2 == 0) query += paramz[i]; // Every 'even' count will just add
|
||||||
else // Every 'uneven' count will handle param as passed variable
|
else // Every 'uneven' count will handle param as passed variable
|
||||||
{
|
{
|
||||||
string paramString = "";
|
string paramString = Function.SqlSerialise(paramz[i]);
|
||||||
if (paramz[i] == null) // Handle null
|
if(paramString == null) // Unknown type in params
|
||||||
{
|
throw new Exception($"Error in query-builder. Type '{paramz[i].GetType().ToString()}' cannot be serialised!");
|
||||||
paramString = "null";
|
|
||||||
}
|
|
||||||
else if (paramz[i].GetType() == typeof(string)) // Handle strings
|
|
||||||
{
|
|
||||||
paramString = "'" + Function.SqlEscape((string)paramz[i]) + "'"; // wrap in sql-brackets and escape sql, if any
|
|
||||||
}
|
|
||||||
else if (paramz[i].GetType() == typeof(byte) || paramz[i].GetType() == typeof(int) || paramz[i].GetType() == typeof(float) || paramz[i].GetType() == typeof(double)) // Handle int, float & double
|
|
||||||
{
|
|
||||||
paramString = paramz[i].ToString().Replace(",", "."); // just format to string and form comma to sql-comma
|
|
||||||
}
|
|
||||||
else if (paramz[i].GetType() == typeof(DateTime)) // Handle DateTime
|
|
||||||
{
|
|
||||||
DateTime dateTime = (DateTime)paramz[i];
|
|
||||||
paramString = "'" + Function.SqlSerialise(dateTime) + "'"; // wrap in sql-brackets and convert to sql-datetime
|
|
||||||
}
|
|
||||||
else if (paramz[i].GetType() == typeof(Guid)) // Handle DateTime
|
|
||||||
{
|
|
||||||
string guid = ((Guid)paramz[i]).ToString(); // Get Guid as string
|
|
||||||
paramString = "'" + guid + "'"; // wrap in sql-brackets
|
|
||||||
}
|
|
||||||
else // Unknown type in params
|
|
||||||
{
|
|
||||||
throw new Exception($"Error in query-builder: Type '{paramz[i].GetType().ToString()}' cannot be used!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add formed param to query
|
// Add formed param to query
|
||||||
query += paramString;
|
query += paramString;
|
||||||
|
@ -103,5 +103,36 @@ namespace eu.railduction.netcore.dll.Database_Attribute_System
|
|||||||
|
|
||||||
return tableName;
|
return tableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string SqlSerialise(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null) // Handle null
|
||||||
|
{
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
else if (obj.GetType() == typeof(string)) // Handle strings
|
||||||
|
{
|
||||||
|
return "'" + SqlEscape((string)obj) + "'"; // wrap in sql-brackets and escape sql, if any
|
||||||
|
}
|
||||||
|
else if (obj.GetType() == typeof(byte) || obj.GetType() == typeof(int) || obj.GetType() == typeof(float) || obj.GetType() == typeof(double)) // Handle int, float & double
|
||||||
|
{
|
||||||
|
return obj.ToString().Replace(",", "."); // just format to string and form comma to sql-comma
|
||||||
|
}
|
||||||
|
else if (obj.GetType() == typeof(DateTime)) // Handle DateTime
|
||||||
|
{
|
||||||
|
DateTime dateTime = (DateTime)obj;
|
||||||
|
return "'" + SqlSerialise(dateTime) + "'"; // wrap in sql-brackets and convert to sql-datetime
|
||||||
|
}
|
||||||
|
else if (obj.GetType() == typeof(Guid)) // Handle DateTime
|
||||||
|
{
|
||||||
|
string guid = ((Guid)obj).ToString(); // Get Guid as string
|
||||||
|
return "'" + guid + "'"; // wrap in sql-brackets
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user