So i was using old Query function with returning result dictionary<string,string>, but with latest oxide update it not working anymore. Why old functions was removed at all and replaced with "QueryAsync"? Its not very good to use in case when i want return result in function because now it forces to use callback everywhere and all my code is broken. Also i'm not really know how to use Action<List<Dictionary<string, object>>> at all.
New MySQL query syntax (C#)
Discussion in 'Rust Development' started by AlexALX_[rus-ua], Aug 13, 2015.
-
The old sync functions were removed because they blocked the server ticking. Which is a real issue on slow or highly used connection to the mysql server.
I've updated the examples here:
http://oxidemod.org/extensions/mysql-extension.901/
It should not be too hard to update to the new api. -
Ok, thank you for link, got what i needed, but still need bit rewrite my code because didn't expected do it async at all.
-
A similar problem. Changed, but not working.
Code:[Oxide] 4:17 AM [Warning] Already open connection (server=localhost;port=3306;database=base;user id=login;password=pass;pooling=False;characterset=utf8), using existing instead...
Code:function PLUGIN:cmdPassword(player,cmd,args) local array = {} if (args.Length == 0) then rust.SendChatMessage(player, "Pass", "Write password") else self.mysqldb = mysql.OpenDb = mysql.OpenDb("localhost", 3306, "base", "login", "pass", self.Plugin, false) local sql = mysql.NewSql() sql:Append("UPDATE `db_users` SET `password`='"..args[0].."' WHERE `steam_id`="..rust.UserIDFromPlayer(player)) local query = mysql.Insert(sql,self.mysqldb) rust.SendChatMessage(player, "Pass", "Password changed") end end
-
Should actually work. Have you checked if the password is updated in db?
Insert has no return, if you need the result you will have to use the callback.
The warning occurs because you are opening/creating the mysql connection with every function call. You just need to do it once. Like open in OnServerInitialized and close in Unload. -
[DOUBLEPOST=1439519163][/DOUBLEPOST]I apologize to the 10 lines written twice
= mysql.OpenDb
[DOUBLEPOST=1439519401][/DOUBLEPOST]Not workAttached Files:
-
-
There is problem on oxide side, now all my plugins also stop work and just don't run query at all. Don't know why, no any errors or anything that can explain why it not work.
Even this simple plugin don't retry anything, but login and password correct.
Code:using Oxide.Core; using Oxide.Ext.MySql; using Oxide.Ext.MySql.Libraries;namespace Oxide.Plugins { [Info("test", "AlexALX", "0.0.1")] public class Donat : RustPlugin { private Connection db; private Ext.MySql.Libraries.MySql mysql = Interface.Oxide.GetLibrary<Ext.MySql.Libraries.MySql>("MySql"); void Loaded() { db = mysql.OpenDb("localhost", 3306, "test", "test", "123", this); var sql = mysql.NewSql().Append("UPDATE `db_users` SET `onl`='1'"); mysql.Update(sql,db); var sql = mysql.NewSql().Append("SELECT * FROM `db_users`"); mysql.Query(sql,db,data => { Puts(data.ToString()); }); } } }
[DOUBLEPOST=1439526412][/DOUBLEPOST]Wait found this
Code:6:52 AM [Error] MySql handle raised an exception (NullReferenceException: Object reference not set to an instance of an object) 6:52 AM [Debug] at Oxide.Ext.MySql.Libraries.MySql+MySqlQuery.Handle () [0x00000] in <filename unknown>:0
[DOUBLEPOST=1439526756][/DOUBLEPOST]After server restart it start work again, so it seems like error what i found is actually some problem in mysql library or so, don't know. -
Wulf Community Admin
Some fixes were made to the MySQL lib today, so that may help as well once they're available in builds.
https://github.com/Nogrod/Oxide-2/commit/f3fd6d9dd2feace4389dc2065a34403eb4797999 -
-
Wulf Community Admin
-
-
Wulf Community Admin
-
-
Wulf Community Admin
-
[DOUBLEPOST=1439656050][/DOUBLEPOST]Code:[Oxide] 7:25 PM [Error] MySql handle raised an exception (NullReferenceException: Object reference not set to an instance of an object) [Oxide] 7:25 PM [Debug] at Oxide.Ext.MySql.Libraries.MySql+MySqlQuery.Handle () [0x00000] in <filename unknown>:0
[DOUBLEPOST=1439663583,1439654890][/DOUBLEPOST]do something, please -
can you provide a full example plugin where this error occurs? so far i was not able to reproduce your issue...
-
-
I am having issues pulling a query(not sure if its my lack of experience) but I am able to insert into the table. Here is the query I am trying to pull
Code:[ChatCommand("mysql")] private void mysqlCmd(BasePlayer player, string command) { _SteamID = player.userID.ToString(); _SteamName = player.displayName; var sql = Ext.MySql.Sql.Builder.Append(@" CREATE TABLE IF NOT EXISTS player_info ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, SteamID VARCHAR(80), SteamName VARCHAR(100) );"); // sql.Append(InsertData, _SteamID, _SteamName); // _mySql.Update(sql, _mySqlConnection); sql.Append(SelectData, _SteamName); _mySql.Query(sql, _mySqlConnection, list => { if (list == null) return; var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(" id\tdata\t\tdata_other"); foreach (var entry in list) { sb.AppendFormat(" {0}\t{1}\t{2}", entry["steam"], entry["SteamName"], entry["data_other"]); sb.AppendLine(); } Puts(sb.ToString()); }); }
Code:[Oxide] 7:44 AM [Info] [Rust Life] id data data_other
error I am now getting
Code:[Oxide] 8:07 AM [Error] MySql command callback raised an exception (KeyNotFoundException: The given key was not present in the dictionary.) [Oxide] 8:07 AM [Debug] at System.Collections.Generic.Dictionary`2[System.String,System.Object].get_Item (System.String key) [0x00000] in <filename unknown>:0 at Oxide.Plugins.RustLife.<mysqlCmd>m__0 (System.Collections.Generic.List`1 list) [0x00000] in <filename unknown>:0 at Oxide.Ext.MySql.Libraries.MySql+MySqlQuery+<Handle>c__AnonStorey0.<>m__0 () [0x00000] in <filename unknown>:0
Last edited by a moderator: Aug 16, 2015