I'm trying to follow the example code and print out some rows from the database I created but it keeps throwing a DBNull error.
void Init()
{
string host = (string)Config["Host"];
int port = (int)Config["Port"];
string databaseName = (string)Config["DatabaseName"];
string username = (string)Config["Username"];
string password = (string)Config["Password"];
string test = ($"{host} {port} {databaseName} {username} {password}");
Puts(test);
sqlConnection = sqlLibrary.OpenDb(host, port, databaseName, username, password, this);
string sqlQuery = "SELECT * FROM Player";
Sql selectCommand = Oxide.Core.Database.Sql.Builder.Append(sqlQuery);
Puts("Running Query");
sqlLibrary.Query(selectCommand, sqlConnection, list =>
{
if (list == null)
{
return; // Empty result or no records found
}
StringBuilder newString = new StringBuilder();
newString.AppendLine(" SteamID");
// Iterate through resulting records
foreach (Dictionary<string, object> entry in list)
{
newString.AppendFormat(" {0}\n", entry["SteamID"]);
}
Puts(newString.ToString());
});
}That is the code i'm testing, I used an insert to make sure it is connecting to the database and it connected and inserted data properly the only columns on table are idPlayer and SteamID I've tried a multitude of different select statements which work when I run them via sql workbench but throw this error if I try to query via my oxide plugin
(16:13:34) | MySql handle raised an exception in 'CactiTracker v0.0.1' plugin (InvalidCastException: Object cannot be cast from DBNull to other types.)
at System.DBNull.System.IConvertible.ToInt32 (System.IFormatProvider provider) [0x0000a] in <fb001e01371b4adca20013e0ac763896>:0
at System.Convert.ToInt32 (System.Object value, System.IFormatProvider provider) [0x00003] in <fb001e01371b4adca20013e0ac763896>:0
at MySql.Data.MySqlClient.Driver.LoadCharacterSets (MySql.Data.MySqlClient.MySqlConnection connection) [0x00079] in <8d7380b3d3cf4bd8be324c584f371b44>:0
at MySql.Data.MySqlClient.Driver.Configure (MySql.Data.MySqlClient.MySqlConnection connection) [0x00060] in <8d7380b3d3cf4bd8be324c584f371b44>:0
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00198] in <8d7380b3d3cf4bd8be324c584f371b44>:0
at Oxide.Core.MySql.Libraries.MySql+MySqlQuery.Handle () [0x00059] in <6e6f659265ef431ea12ea404a5e9a54c>:0