From fe55626fcf7c1fda244db5e0c4f91ad7d0704c64 Mon Sep 17 00:00:00 2001 From: onefang Date: Thu, 22 Aug 2019 15:46:57 +1000 Subject: Function for MYSQL joins. --- OpenSim/Data/MySQL/MySQLRaw.cs | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MySQL/MySQLRaw.cs b/OpenSim/Data/MySQL/MySQLRaw.cs index e8f80aa..bb8c96c 100644 --- a/OpenSim/Data/MySQL/MySQLRaw.cs +++ b/OpenSim/Data/MySQL/MySQLRaw.cs @@ -40,6 +40,57 @@ namespace OpenSim.Data.MySQL return result; } + public List< Hashtable > Join(string table, string select, string join, string wher, string order) + { + if ("" == select) + select = "*"; + string query = "SELECT " + select + " FROM " + table; + if ("" != join) + query = query + " " + join; + if ("" != wher) + query = query + " WHERE " + wher; + if ("" != order) + query = query + " ORDER BY " + order; + + using (MySqlConnection dbcon = new MySqlConnection(m_connectString)) + { + dbcon.Open(); + MySqlCommand cmd = new MySqlCommand(query, dbcon); + MySqlDataReader rdr = cmd.ExecuteReader(); + List names = new List(); + DataTable schema = rdr.GetSchemaTable(); + List< Hashtable > list = new List< Hashtable >(); + + foreach (DataRow row in schema.Rows) + { + string tbl = ""; + string nm = ""; + string tp = ""; + foreach (DataColumn col in schema.Columns) + { + if ("BaseTableName" == col.ColumnName) tbl = row[col].ToString(); + if ("ColumnName" == col.ColumnName) nm = row[col].ToString(); + if ("DataType" == col.ColumnName) tp = row[col].ToString(); + } + names.Add(nm); + } + + while (rdr.Read()) + { + Hashtable r = new Hashtable(); + foreach (string name in names) + { + r[name] = rdr[name]; + } + list.Add(r); + } + + rdr.Close(); + dbcon.Close(); + return list; + } + } + public List< Hashtable > Select(string table, string select, string wher, string order) { if ("" == select) -- cgit v1.1