Replies: 1 comment
-
When PetaPoco sends a query to the db, it sends a string with parameter placeholders and an array of parameter objects. You can reference these right after a query with If you want to construct a text representation of the query from these two, you can use a method to do the placeholder replacement yourself. Here's something quick and dirty that covers many cases. (No warranty provided.) public string GetFullQueryText(IDatabase db)
{
string result = db.LastSQL;
var args = db.LastArgs;
for (int i = 0; i < args.Count(); ++i)
{
var thisArg = args[i];
var placeholder = $"@{i}";
string value;
if (thisArg == null)
value = "null";
else if (IsNumeric(thisArg))
value = thisArg.ToString();
else if (thisArg is DateTime)
value = $"'{thisArg:s}'";
else
value = $"'{thisArg}'";
result = result.Replace(placeholder, value);
}
return result;
}
public static bool IsNumeric(object obj)
{
return obj is byte || obj is sbyte ||
obj is short || obj is ushort ||
obj is int || obj is uint ||
obj is long || obj is ulong ||
obj is float || obj is double ||
obj is decimal;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For my work it is quite common to have queries with more than 10 parameters and when trying to debug, I have to take the query generated from petapoco, paste it in SSMS and then start adding parameters manually.
While debugging, I could not find anywhere a field or a property on the object that could show the final SQL query, including the parameters supplied to it.
If this functionality exists, please point me in the right direction, if it doesn't, I think it would be very helpful and a time saving feature for all devs.
Beta Was this translation helpful? Give feedback.
All reactions