From 56fe4c24b8c67ec3b6a5a897c35ab19507bd1077 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Apr 2010 17:45:00 +0100 Subject: rename SQLiteNG to SQLite and SQLite to SQLiteLegacy this seems the least evil way forward since mono 2.6 and later will see increasing usage, and this only works with what was SQLiteNG MAC USERS WILL NEED TO CHANGE REFERENCES TO "OpenSim.Data.SQLite.dll" to "OpenSim.Data.SQLiteLegacy.dll" in OpenSim.ini and config-include/StandaloneCommon.ini (if using standalone) See the OpenSim.ini.example and StandaloneCommon.ini.example files for more details This commit also temporarily changes unsigned ParentEstateID values in the OpenSim.Data.Tests to signed temporarily, since the new plugin enforces creation of signed fields in the database (which is what the SQL actually specifies). And change data columns in sqlite is a pita. --- OpenSim/Data/SQLite/SQLiteAssetData.cs | 4 +- OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | 257 ++++++++++++++++++++++ OpenSim/Data/SQLite/SQLiteEstateData.cs | 101 +++++++-- OpenSim/Data/SQLite/SQLiteFramework.cs | 29 ++- OpenSim/Data/SQLite/SQLiteFriendsData.cs | 70 ++++++ OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | 26 ++- OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 25 ++- OpenSim/Data/SQLite/SQLiteRegionData.cs | 259 ++++++++++++++--------- OpenSim/Data/SQLite/SQLiteUserAccountData.cs | 81 +++++++ OpenSim/Data/SQLite/SQLiteUtils.cs | 2 +- OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 6 +- 11 files changed, 732 insertions(+), 128 deletions(-) create mode 100644 OpenSim/Data/SQLite/SQLiteAuthenticationData.cs create mode 100644 OpenSim/Data/SQLite/SQLiteFriendsData.cs create mode 100644 OpenSim/Data/SQLite/SQLiteUserAccountData.cs (limited to 'OpenSim/Data/SQLite') diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index c52f60b..373c903 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs @@ -30,7 +30,7 @@ using System.Data; using System.Reflection; using System.Collections.Generic; using log4net; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using OpenMetaverse; using OpenSim.Framework; @@ -339,4 +339,4 @@ namespace OpenSim.Data.SQLite #endregion } -} \ No newline at end of file +} diff --git a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs new file mode 100644 index 0000000..086ac0a --- /dev/null +++ b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs @@ -0,0 +1,257 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using OpenMetaverse; +using OpenSim.Framework; +using Mono.Data.Sqlite; + +namespace OpenSim.Data.SQLite +{ + public class SQLiteAuthenticationData : SQLiteFramework, IAuthenticationData + { + private string m_Realm; + private List m_ColumnNames; + private int m_LastExpire; + private string m_connectionString; + + protected static SqliteConnection m_Connection; + private static bool m_initialized = false; + + public SQLiteAuthenticationData(string connectionString, string realm) + : base(connectionString) + { + m_Realm = realm; + m_connectionString = connectionString; + + if (!m_initialized) + { + m_Connection = new SqliteConnection(connectionString); + m_Connection.Open(); + + Migration m = new Migration(m_Connection, GetType().Assembly, "AuthStore"); + m.Update(); + + m_initialized = true; + } + } + + public AuthenticationData Get(UUID principalID) + { + AuthenticationData ret = new AuthenticationData(); + ret.Data = new Dictionary(); + + SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = :PrincipalID"); + cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); + + IDataReader result = ExecuteReader(cmd, m_Connection); + + try + { + if (result.Read()) + { + ret.PrincipalID = principalID; + + if (m_ColumnNames == null) + { + m_ColumnNames = new List(); + + DataTable schemaTable = result.GetSchemaTable(); + foreach (DataRow row in schemaTable.Rows) + m_ColumnNames.Add(row["ColumnName"].ToString()); + } + + foreach (string s in m_ColumnNames) + { + if (s == "UUID") + continue; + + ret.Data[s] = result[s].ToString(); + } + + return ret; + } + else + { + return null; + } + } + catch + { + } + finally + { + //CloseCommand(cmd); + } + + return null; + } + + public bool Store(AuthenticationData data) + { + if (data.Data.ContainsKey("UUID")) + data.Data.Remove("UUID"); + + string[] fields = new List(data.Data.Keys).ToArray(); + string[] values = new string[data.Data.Count]; + int i = 0; + foreach (object o in data.Data.Values) + values[i++] = o.ToString(); + + SqliteCommand cmd = new SqliteCommand(); + + if (Get(data.PrincipalID) != null) + { + + + string update = "update `" + m_Realm + "` set "; + bool first = true; + foreach (string field in fields) + { + if (!first) + update += ", "; + update += "`" + field + "` = :" + field; + cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); + + first = false; + } + + update += " where UUID = :UUID"; + cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); + + cmd.CommandText = update; + try + { + if (ExecuteNonQuery(cmd, m_Connection) < 1) + { + //CloseCommand(cmd); + return false; + } + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + //CloseCommand(cmd); + return false; + } + } + + else + { + string insert = "insert into `" + m_Realm + "` (`UUID`, `" + + String.Join("`, `", fields) + + "`) values (:UUID, :" + String.Join(", :", fields) + ")"; + + cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); + foreach (string field in fields) + cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); + + cmd.CommandText = insert; + + try + { + if (ExecuteNonQuery(cmd, m_Connection) < 1) + { + //CloseCommand(cmd); + return false; + } + } + catch (Exception e) + { + Console.WriteLine(e.ToString()); + //CloseCommand(cmd); + return false; + } + } + + //CloseCommand(cmd); + + return true; + } + + public bool SetDataItem(UUID principalID, string item, string value) + { + SqliteCommand cmd = new SqliteCommand("update `" + m_Realm + + "` set `" + item + "` = " + value + " where UUID = '" + principalID.ToString() + "'"); + + if (ExecuteNonQuery(cmd, m_Connection) > 0) + return true; + + return false; + } + + public bool SetToken(UUID principalID, string token, int lifetime) + { + if (System.Environment.TickCount - m_LastExpire > 30000) + DoExpire(); + + SqliteCommand cmd = new SqliteCommand("insert into tokens (UUID, token, validity) values ('" + principalID.ToString() + + "', '" + token + "', datetime('now', 'localtime', '+" + lifetime.ToString() + " minutes'))"); + + if (ExecuteNonQuery(cmd, m_Connection) > 0) + { + cmd.Dispose(); + return true; + } + + cmd.Dispose(); + return false; + } + + public bool CheckToken(UUID principalID, string token, int lifetime) + { + if (System.Environment.TickCount - m_LastExpire > 30000) + DoExpire(); + + SqliteCommand cmd = new SqliteCommand("update tokens set validity = datetime('now', 'localtime', '+" + lifetime.ToString() + + " minutes') where UUID = '" + principalID.ToString() + "' and token = '" + token + "' and validity > datetime('now', 'localtime')"); + + if (ExecuteNonQuery(cmd, m_Connection) > 0) + { + cmd.Dispose(); + return true; + } + + cmd.Dispose(); + + return false; + } + + private void DoExpire() + { + SqliteCommand cmd = new SqliteCommand("delete from tokens where validity < datetime('now', 'localtime')"); + ExecuteNonQuery(cmd, m_Connection); + + cmd.Dispose(); + + m_LastExpire = System.Environment.TickCount; + } + } +} diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs index 1be99ee..ad4e2a2 100644 --- a/OpenSim/Data/SQLite/SQLiteEstateData.cs +++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs @@ -30,7 +30,7 @@ using System.Collections.Generic; using System.Data; using System.Reflection; using log4net; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; @@ -62,8 +62,8 @@ namespace OpenSim.Data.SQLite Migration m = new Migration(m_connection, assem, "EstateStore"); m.Update(); - m_connection.Close(); - m_connection.Open(); + //m_connection.Close(); + // m_connection.Open(); Type t = typeof(EstateSettings); m_Fields = t.GetFields(BindingFlags.NonPublic | @@ -90,7 +90,7 @@ namespace OpenSim.Data.SQLite SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); cmd.CommandText = sql; - cmd.Parameters.Add(":RegionID", regionID.ToString()); + cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); IDataReader r = cmd.ExecuteReader(); @@ -140,13 +140,13 @@ namespace OpenSim.Data.SQLite if (m_FieldMap[name].GetValue(es) is bool) { if ((bool)m_FieldMap[name].GetValue(es)) - cmd.Parameters.Add(":"+name, "1"); + cmd.Parameters.AddWithValue(":"+name, "1"); else - cmd.Parameters.Add(":"+name, "0"); + cmd.Parameters.AddWithValue(":"+name, "0"); } else { - cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString()); + cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString()); } } @@ -164,8 +164,8 @@ namespace OpenSim.Data.SQLite r.Close(); cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; - cmd.Parameters.Add(":RegionID", regionID.ToString()); - cmd.Parameters.Add(":EstateID", es.EstateID.ToString()); + cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); + cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); // This will throw on dupe key try @@ -222,13 +222,13 @@ namespace OpenSim.Data.SQLite if (m_FieldMap[name].GetValue(es) is bool) { if ((bool)m_FieldMap[name].GetValue(es)) - cmd.Parameters.Add(":"+name, "1"); + cmd.Parameters.AddWithValue(":"+name, "1"); else - cmd.Parameters.Add(":"+name, "0"); + cmd.Parameters.AddWithValue(":"+name, "0"); } else { - cmd.Parameters.Add(":"+name, m_FieldMap[name].GetValue(es).ToString()); + cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString()); } } @@ -247,7 +247,7 @@ namespace OpenSim.Data.SQLite SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID"; - cmd.Parameters.Add(":EstateID", es.EstateID); + cmd.Parameters.AddWithValue(":EstateID", es.EstateID); IDataReader r = cmd.ExecuteReader(); @@ -271,7 +271,7 @@ namespace OpenSim.Data.SQLite SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); cmd.CommandText = "delete from estateban where EstateID = :EstateID"; - cmd.Parameters.Add(":EstateID", es.EstateID.ToString()); + cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); cmd.ExecuteNonQuery(); @@ -281,8 +281,8 @@ namespace OpenSim.Data.SQLite foreach (EstateBan b in es.EstateBans) { - cmd.Parameters.Add(":EstateID", es.EstateID.ToString()); - cmd.Parameters.Add(":bannedUUID", b.BannedUserID.ToString()); + cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); + cmd.Parameters.AddWithValue(":bannedUUID", b.BannedUserID.ToString()); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); @@ -294,7 +294,7 @@ namespace OpenSim.Data.SQLite SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); cmd.CommandText = "delete from "+table+" where EstateID = :EstateID"; - cmd.Parameters.Add(":EstateID", EstateID.ToString()); + cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); cmd.ExecuteNonQuery(); @@ -304,8 +304,8 @@ namespace OpenSim.Data.SQLite foreach (UUID uuid in data) { - cmd.Parameters.Add(":EstateID", EstateID.ToString()); - cmd.Parameters.Add(":uuid", uuid.ToString()); + cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); + cmd.Parameters.AddWithValue(":uuid", uuid.ToString()); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); @@ -319,7 +319,7 @@ namespace OpenSim.Data.SQLite SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID"; - cmd.Parameters.Add(":EstateID", EstateID); + cmd.Parameters.AddWithValue(":EstateID", EstateID); IDataReader r = cmd.ExecuteReader(); @@ -336,5 +336,66 @@ namespace OpenSim.Data.SQLite return uuids.ToArray(); } +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteEstateData.cs +======= + + public EstateSettings LoadEstateSettings(int estateID) + { + string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID :EstateID"; + + SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); + + cmd.CommandText = sql; + cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); + + return DoLoad(cmd, UUID.Zero, false); + } + + public List GetEstates(string search) + { + List result = new List(); + + string sql = "select EstateID from estate_settings where estate_settings.EstateName :EstateName"; + + SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); + + cmd.CommandText = sql; + cmd.Parameters.AddWithValue(":EstateName", search); + + IDataReader r = cmd.ExecuteReader(); + + while (r.Read()) + { + result.Add(Convert.ToInt32(r["EstateID"])); + } + r.Close(); + + return result; + } + + public bool LinkRegion(UUID regionID, int estateID) + { + SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); + + cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; + cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); + cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); + + if (cmd.ExecuteNonQuery() == 0) + return false; + + return true; + } + + public List GetRegions(int estateID) + { + return new List(); + } + + public bool DeleteEstate(int estateID) + { + return false; + } +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteEstateData.cs } } diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs index 12b2750..79eaab3 100644 --- a/OpenSim/Data/SQLite/SQLiteFramework.cs +++ b/OpenSim/Data/SQLite/SQLiteFramework.cs @@ -31,7 +31,7 @@ using System.Collections.Generic; using System.Data; using OpenMetaverse; using OpenSim.Framework; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; namespace OpenSim.Data.SQLite { @@ -57,7 +57,19 @@ namespace OpenSim.Data.SQLite { lock (m_Connection) { +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteFramework.cs cmd.Connection = m_Connection; +======= +/* + SqliteConnection newConnection = + (SqliteConnection)((ICloneable)connection).Clone(); + newConnection.Open(); + + cmd.Connection = newConnection; +*/ + cmd.Connection = connection; + //Console.WriteLine("XXX " + cmd.CommandText); +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteFramework.cs return cmd.ExecuteNonQuery(); } @@ -65,12 +77,27 @@ namespace OpenSim.Data.SQLite protected IDataReader ExecuteReader(SqliteCommand cmd) { +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteFramework.cs SqliteConnection newConnection = (SqliteConnection)((ICloneable)m_Connection).Clone(); newConnection.Open(); cmd.Connection = newConnection; return cmd.ExecuteReader(); +======= + lock (connection) + { + //SqliteConnection newConnection = + // (SqliteConnection)((ICloneable)connection).Clone(); + //newConnection.Open(); + + //cmd.Connection = newConnection; + cmd.Connection = connection; + //Console.WriteLine("XXX " + cmd.CommandText); + + return cmd.ExecuteReader(); + } +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteFramework.cs } protected void CloseReaderCommand(SqliteCommand cmd) diff --git a/OpenSim/Data/SQLite/SQLiteFriendsData.cs b/OpenSim/Data/SQLite/SQLiteFriendsData.cs new file mode 100644 index 0000000..b06853c --- /dev/null +++ b/OpenSim/Data/SQLite/SQLiteFriendsData.cs @@ -0,0 +1,70 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using OpenMetaverse; +using OpenSim.Framework; +using Mono.Data.Sqlite; + +namespace OpenSim.Data.SQLite +{ + public class SQLiteFriendsData : SQLiteGenericTableHandler, IFriendsData + { + public SQLiteFriendsData(string connectionString, string realm) + : base(connectionString, realm, "FriendsStore") + { + } + + public FriendsData[] GetFriends(UUID userID) + { + SqliteCommand cmd = new SqliteCommand(); + + cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = :PrincipalID", m_Realm); + cmd.Parameters.AddWithValue(":PrincipalID", userID.ToString()); + + return DoQuery(cmd); + + } + + public bool Delete(UUID principalID, string friend) + { + SqliteCommand cmd = new SqliteCommand(); + + cmd.CommandText = String.Format("delete from {0} where PrincipalID = :PrincipalID and Friend = :Friend", m_Realm); + cmd.Parameters.AddWithValue(":PrincipalID", principalID.ToString()); + cmd.Parameters.AddWithValue(":Friend", friend); + + ExecuteNonQuery(cmd, cmd.Connection); + + return true; + } + + } +} diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs index 8e91693..918cb3d 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs @@ -30,7 +30,7 @@ using System.Collections.Generic; using System.Data; using System.Reflection; using log4net; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; @@ -54,7 +54,27 @@ namespace OpenSim.Data.SQLite m_Realm = realm; if (storeName != String.Empty) { +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs Assembly assem = GetType().Assembly; +======= + m_Connection = new SqliteConnection(connectionString); + Console.WriteLine(string.Format("OPENING CONNECTION FOR {0} USING {1}", storeName, connectionString)); + m_Connection.Open(); + + if (storeName != String.Empty) + { + Assembly assem = GetType().Assembly; + //SqliteConnection newConnection = + // (SqliteConnection)((ICloneable)m_Connection).Clone(); + //newConnection.Open(); + + //Migration m = new Migration(newConnection, assem, storeName); + Migration m = new Migration(m_Connection, assem, storeName); + m.Update(); + //newConnection.Close(); + //newConnection.Dispose(); + } +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs Migration m = new Migration(m_Connection, assem, storeName); m.Update(); @@ -180,7 +200,11 @@ namespace OpenSim.Data.SQLite result.Add(row); } +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs CloseReaderCommand(cmd); +======= + //CloseCommand(cmd); +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs return result.ToArray(); } diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 64591fd..0149838 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs @@ -30,7 +30,7 @@ using System.Collections.Generic; using System.Data; using System.Reflection; using log4net; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using OpenMetaverse; using OpenSim.Framework; @@ -89,6 +89,7 @@ namespace OpenSim.Data.SQLite ds = new DataSet(); +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteInventoryStore.cs ds.Tables.Add(createInventoryFoldersTable()); invFoldersDa.Fill(ds.Tables["inventoryfolders"]); setupFoldersCommands(invFoldersDa, conn); @@ -98,6 +99,19 @@ namespace OpenSim.Data.SQLite invItemsDa.Fill(ds.Tables["inventoryitems"]); setupItemsCommands(invItemsDa, conn); m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); +======= + ds.Tables.Add(createInventoryFoldersTable()); + invFoldersDa.Fill(ds.Tables["inventoryfolders"]); + setupFoldersCommands(invFoldersDa, conn); + CreateDataSetMapping(invFoldersDa, "inventoryfolders"); + m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); + + ds.Tables.Add(createInventoryItemsTable()); + invItemsDa.Fill(ds.Tables["inventoryitems"]); + setupItemsCommands(invItemsDa, conn); + CreateDataSetMapping(invItemsDa, "inventoryitems"); + m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteInventoryStore.cs ds.AcceptChanges(); } @@ -721,6 +735,15 @@ namespace OpenSim.Data.SQLite * **********************************************************************/ + protected void CreateDataSetMapping(IDataAdapter da, string tableName) + { + ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName); + foreach (DataColumn col in ds.Tables[tableName].Columns) + { + dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName); + } + } + /// /// Create the "inventoryitems" table /// diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index 5a4ee2a..85368ab 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs @@ -32,7 +32,7 @@ using System.Drawing; using System.IO; using System.Reflection; using log4net; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; @@ -87,119 +87,142 @@ namespace OpenSim.Data.SQLite /// the connection string public void Initialise(string connectionString) { - m_connectionString = connectionString; + try + { + m_connectionString = connectionString; - ds = new DataSet(); + ds = new DataSet("Region"); - m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString); - m_conn = new SqliteConnection(m_connectionString); - m_conn.Open(); + m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString); + m_conn = new SqliteConnection(m_connectionString); + m_conn.Open(); + SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn); + primDa = new SqliteDataAdapter(primSelectCmd); + SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn); + shapeDa = new SqliteDataAdapter(shapeSelectCmd); + // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); - SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn); - primDa = new SqliteDataAdapter(primSelectCmd); - // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); + SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn); + itemsDa = new SqliteDataAdapter(itemsSelectCmd); - SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn); - shapeDa = new SqliteDataAdapter(shapeSelectCmd); - // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); + SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn); + terrainDa = new SqliteDataAdapter(terrainSelectCmd); - SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn); - itemsDa = new SqliteDataAdapter(itemsSelectCmd); + SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn); + landDa = new SqliteDataAdapter(landSelectCmd); - SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn); - terrainDa = new SqliteDataAdapter(terrainSelectCmd); + SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); + landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); - SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn); - landDa = new SqliteDataAdapter(landSelectCmd); + SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn); + regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd); + // This actually does the roll forward assembly stuff + Assembly assem = GetType().Assembly; + Migration m = new Migration(m_conn, assem, "RegionStore"); + m.Update(); - SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); - landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); + lock (ds) + { + ds.Tables.Add(createPrimTable()); + setupPrimCommands(primDa, m_conn); - SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn); - regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd); - // This actually does the roll forward assembly stuff - Assembly assem = GetType().Assembly; - Migration m = new Migration(m_conn, assem, "RegionStore"); - m.Update(); + ds.Tables.Add(createShapeTable()); + setupShapeCommands(shapeDa, m_conn); - lock (ds) - { - ds.Tables.Add(createPrimTable()); - setupPrimCommands(primDa, m_conn); - primDa.Fill(ds.Tables["prims"]); + ds.Tables.Add(createItemsTable()); + setupItemsCommands(itemsDa, m_conn); - ds.Tables.Add(createShapeTable()); - setupShapeCommands(shapeDa, m_conn); + ds.Tables.Add(createTerrainTable()); + setupTerrainCommands(terrainDa, m_conn); - ds.Tables.Add(createItemsTable()); - setupItemsCommands(itemsDa, m_conn); - itemsDa.Fill(ds.Tables["primitems"]); + ds.Tables.Add(createLandTable()); + setupLandCommands(landDa, m_conn); - ds.Tables.Add(createTerrainTable()); - setupTerrainCommands(terrainDa, m_conn); + ds.Tables.Add(createLandAccessListTable()); + setupLandAccessCommands(landAccessListDa, m_conn); - ds.Tables.Add(createLandTable()); - setupLandCommands(landDa, m_conn); + ds.Tables.Add(createRegionSettingsTable()); + setupRegionSettingsCommands(regionSettingsDa, m_conn); - ds.Tables.Add(createLandAccessListTable()); - setupLandAccessCommands(landAccessListDa, m_conn); + // WORKAROUND: This is a work around for sqlite on + // windows, which gets really unhappy with blob columns + // that have no sample data in them. At some point we + // need to actually find a proper way to handle this. + try + { + primDa.Fill(ds.Tables["prims"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on prims table"); + } - ds.Tables.Add(createRegionSettingsTable()); - - setupRegionSettingsCommands(regionSettingsDa, m_conn); + try + { + shapeDa.Fill(ds.Tables["primshapes"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on primshapes table"); + } - // WORKAROUND: This is a work around for sqlite on - // windows, which gets really unhappy with blob columns - // that have no sample data in them. At some point we - // need to actually find a proper way to handle this. - try - { - shapeDa.Fill(ds.Tables["primshapes"]); - } - catch (Exception) - { - m_log.Info("[REGION DB]: Caught fill error on primshapes table"); - } + try + { + terrainDa.Fill(ds.Tables["terrain"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on terrain table"); + } - try - { - terrainDa.Fill(ds.Tables["terrain"]); - } - catch (Exception) - { - m_log.Info("[REGION DB]: Caught fill error on terrain table"); - } + try + { + landDa.Fill(ds.Tables["land"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on land table"); + } - try - { - landDa.Fill(ds.Tables["land"]); - } - catch (Exception) - { - m_log.Info("[REGION DB]: Caught fill error on land table"); - } + try + { + landAccessListDa.Fill(ds.Tables["landaccesslist"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); + } - try - { - landAccessListDa.Fill(ds.Tables["landaccesslist"]); - } - catch (Exception) - { - m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); - } + try + { + regionSettingsDa.Fill(ds.Tables["regionsettings"]); + } + catch (Exception) + { + m_log.Info("[REGION DB]: Caught fill error on regionsettings table"); + } - try - { - regionSettingsDa.Fill(ds.Tables["regionsettings"]); - } - catch (Exception) - { - m_log.Info("[REGION DB]: Caught fill error on regionsettings table"); + // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values! + // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409 + // Possibly because we manually set up our own DataTables before connecting to the database + CreateDataSetMapping(primDa, "prims"); + CreateDataSetMapping(shapeDa, "primshapes"); + CreateDataSetMapping(itemsDa, "primitems"); + CreateDataSetMapping(terrainDa, "terrain"); + CreateDataSetMapping(landDa, "land"); + CreateDataSetMapping(landAccessListDa, "landaccesslist"); + CreateDataSetMapping(regionSettingsDa, "regionsettings"); } - return; } + catch (Exception e) + { + m_log.Error(e); + Environment.Exit(23); + } + + return; } public void Dispose() @@ -594,7 +617,7 @@ namespace OpenSim.Data.SQLite } } } - rev = (int) row["Revision"]; + rev = Convert.ToInt32(row["Revision"]); } else { @@ -746,6 +769,7 @@ namespace OpenSim.Data.SQLite /// public void Commit() { + m_log.Debug("[SQLITE]: Starting commit"); lock (ds) { primDa.Update(ds, "prims"); @@ -760,18 +784,11 @@ namespace OpenSim.Data.SQLite { regionSettingsDa.Update(ds, "regionsettings"); } - catch (SqliteExecutionException SqlEx) + catch (SqliteException SqlEx) { - if (SqlEx.Message.Contains("logic error")) - { - throw new Exception( - "There was a SQL error or connection string configuration error when saving the region settings. This could be a bug, it could also happen if ConnectionString is defined in the [DatabaseService] section of StandaloneCommon.ini in the config_include folder. This could also happen if the config_include folder doesn't exist or if the OpenSim.ini [Architecture] section isn't set. If this is your first time running OpenSimulator, please restart the simulator and bug a developer to fix this!", - SqlEx); - } - else - { - throw SqlEx; - } + throw new Exception( + "There was a SQL error or connection string configuration error when saving the region settings. This could be a bug, it could also happen if ConnectionString is defined in the [DatabaseService] section of StandaloneCommon.ini in the config_include folder. This could also happen if the config_include folder doesn't exist or if the OpenSim.ini [Architecture] section isn't set. If this is your first time running OpenSimulator, please restart the simulator and bug a developer to fix this!", + SqlEx); } ds.AcceptChanges(); } @@ -793,6 +810,15 @@ namespace OpenSim.Data.SQLite * **********************************************************************/ + protected void CreateDataSetMapping(IDataAdapter da, string tableName) + { + ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName); + foreach (DataColumn col in ds.Tables[tableName].Columns) + { + dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName); + } + } + /// /// /// @@ -1955,6 +1981,7 @@ namespace OpenSim.Data.SQLite sql += ") values (:"; sql += String.Join(", :", cols); sql += ")"; + m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql); SqliteCommand cmd = new SqliteCommand(sql); // this provides the binding for all our parameters, so @@ -2250,6 +2277,36 @@ namespace OpenSim.Data.SQLite return DbType.String; } } + + static void PrintDataSet(DataSet ds) + { + // Print out any name and extended properties. + Console.WriteLine("DataSet is named: {0}", ds.DataSetName); + foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties) + { + Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value); + } + Console.WriteLine(); + foreach (DataTable dt in ds.Tables) + { + Console.WriteLine("=> {0} Table:", dt.TableName); + // Print out the column names. + for (int curCol = 0; curCol < dt.Columns.Count; curCol++) + { + Console.Write(dt.Columns[curCol].ColumnName + "\t"); + } + Console.WriteLine("\n----------------------------------"); + // Print the DataTable. + for (int curRow = 0; curRow < dt.Rows.Count; curRow++) + { + for (int curCol = 0; curCol < dt.Columns.Count; curCol++) + { + Console.Write(dt.Rows[curRow][curCol].ToString() + "\t"); + } + Console.WriteLine(); + } + } + } } } diff --git a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs new file mode 100644 index 0000000..893f105 --- /dev/null +++ b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs @@ -0,0 +1,81 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data; +using OpenMetaverse; +using OpenSim.Framework; +using Mono.Data.Sqlite; + +namespace OpenSim.Data.SQLite +{ + public class SQLiteUserAccountData : SQLiteGenericTableHandler, IUserAccountData + { + public SQLiteUserAccountData(string connectionString, string realm) + : base(connectionString, realm, "UserAccount") + { + } + + public UserAccountData[] GetUsers(UUID scopeID, string query) + { + string[] words = query.Split(new char[] {' '}); + + for (int i = 0 ; i < words.Length ; i++) + { + if (words[i].Length < 3) + { + if (i != words.Length - 1) + Array.Copy(words, i + 1, words, i, words.Length - i - 1); + Array.Resize(ref words, words.Length - 1); + } + } + + if (words.Length == 0) + return new UserAccountData[0]; + + if (words.Length > 2) + return new UserAccountData[0]; + + SqliteCommand cmd = new SqliteCommand(); + + if (words.Length == 1) + { + cmd.CommandText = String.Format("select * from {0} where ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{2}%')", + m_Realm, scopeID.ToString(), words[0]); + } + else + { + cmd.CommandText = String.Format("select * from {0} where (ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{3}%')", + m_Realm, scopeID.ToString(), words[0], words[1]); + } + + return DoQuery(cmd); + } + } +} diff --git a/OpenSim/Data/SQLite/SQLiteUtils.cs b/OpenSim/Data/SQLite/SQLiteUtils.cs index 4a835ce..07c6b69 100644 --- a/OpenSim/Data/SQLite/SQLiteUtils.cs +++ b/OpenSim/Data/SQLite/SQLiteUtils.cs @@ -27,7 +27,7 @@ using System; using System.Data; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; namespace OpenSim.Data.SQLite { diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 5c93f88..0650a86 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs @@ -29,7 +29,7 @@ using System; using System.Data; using System.Reflection; using System.Collections.Generic; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using log4net; using OpenMetaverse; using OpenSim.Framework; @@ -147,7 +147,11 @@ namespace OpenSim.Data.SQLite } reader.Close(); +<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteXInventoryData.cs CloseReaderCommand(cmd); +======= + //CloseCommand(cmd); +>>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteXInventoryData.cs return perms; } -- cgit v1.1 From d8b604b550c76610187d929087bce3b08e7018c5 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Apr 2010 18:18:21 +0100 Subject: take out some debug logging in the sqlite db adaptor --- OpenSim/Data/SQLite/SQLiteRegionData.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'OpenSim/Data/SQLite') diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index 85368ab..fe6e919 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs @@ -769,7 +769,7 @@ namespace OpenSim.Data.SQLite /// public void Commit() { - m_log.Debug("[SQLITE]: Starting commit"); + //m_log.Debug("[SQLITE]: Starting commit"); lock (ds) { primDa.Update(ds, "prims"); @@ -1914,7 +1914,7 @@ namespace OpenSim.Data.SQLite /// public void StorePrimInventory(UUID primID, ICollection items) { - m_log.InfoFormat("[REGION DB]: Entered StorePrimInventory with prim ID {0}", primID); + //m_log.InfoFormat("[REGION DB]: Entered StorePrimInventory with prim ID {0}", primID); DataTable dbItems = ds.Tables["primitems"]; @@ -1981,7 +1981,7 @@ namespace OpenSim.Data.SQLite sql += ") values (:"; sql += String.Join(", :", cols); sql += ")"; - m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql); + //m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql); SqliteCommand cmd = new SqliteCommand(sql); // this provides the binding for all our parameters, so -- cgit v1.1 From 0b8b302aa0f2ee25be5cbdfefe232459e6e5b778 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Apr 2010 20:05:57 +0100 Subject: Fix a bunch of issues that crop up after the naive porting of the new sqlite db from master to 0.6.9 --- OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | 257 ----------------------- OpenSim/Data/SQLite/SQLiteEstateData.cs | 65 +----- OpenSim/Data/SQLite/SQLiteFramework.cs | 27 +-- OpenSim/Data/SQLite/SQLiteFriendsData.cs | 70 ------ OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | 13 +- OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 18 +- OpenSim/Data/SQLite/SQLiteManager.cs | 8 +- OpenSim/Data/SQLite/SQLiteUserAccountData.cs | 81 ------- OpenSim/Data/SQLite/SQLiteUserData.cs | 2 +- OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 6 +- 10 files changed, 15 insertions(+), 532 deletions(-) delete mode 100644 OpenSim/Data/SQLite/SQLiteAuthenticationData.cs delete mode 100644 OpenSim/Data/SQLite/SQLiteFriendsData.cs delete mode 100644 OpenSim/Data/SQLite/SQLiteUserAccountData.cs (limited to 'OpenSim/Data/SQLite') diff --git a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs deleted file mode 100644 index 086ac0a..0000000 --- a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using OpenMetaverse; -using OpenSim.Framework; -using Mono.Data.Sqlite; - -namespace OpenSim.Data.SQLite -{ - public class SQLiteAuthenticationData : SQLiteFramework, IAuthenticationData - { - private string m_Realm; - private List m_ColumnNames; - private int m_LastExpire; - private string m_connectionString; - - protected static SqliteConnection m_Connection; - private static bool m_initialized = false; - - public SQLiteAuthenticationData(string connectionString, string realm) - : base(connectionString) - { - m_Realm = realm; - m_connectionString = connectionString; - - if (!m_initialized) - { - m_Connection = new SqliteConnection(connectionString); - m_Connection.Open(); - - Migration m = new Migration(m_Connection, GetType().Assembly, "AuthStore"); - m.Update(); - - m_initialized = true; - } - } - - public AuthenticationData Get(UUID principalID) - { - AuthenticationData ret = new AuthenticationData(); - ret.Data = new Dictionary(); - - SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = :PrincipalID"); - cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); - - IDataReader result = ExecuteReader(cmd, m_Connection); - - try - { - if (result.Read()) - { - ret.PrincipalID = principalID; - - if (m_ColumnNames == null) - { - m_ColumnNames = new List(); - - DataTable schemaTable = result.GetSchemaTable(); - foreach (DataRow row in schemaTable.Rows) - m_ColumnNames.Add(row["ColumnName"].ToString()); - } - - foreach (string s in m_ColumnNames) - { - if (s == "UUID") - continue; - - ret.Data[s] = result[s].ToString(); - } - - return ret; - } - else - { - return null; - } - } - catch - { - } - finally - { - //CloseCommand(cmd); - } - - return null; - } - - public bool Store(AuthenticationData data) - { - if (data.Data.ContainsKey("UUID")) - data.Data.Remove("UUID"); - - string[] fields = new List(data.Data.Keys).ToArray(); - string[] values = new string[data.Data.Count]; - int i = 0; - foreach (object o in data.Data.Values) - values[i++] = o.ToString(); - - SqliteCommand cmd = new SqliteCommand(); - - if (Get(data.PrincipalID) != null) - { - - - string update = "update `" + m_Realm + "` set "; - bool first = true; - foreach (string field in fields) - { - if (!first) - update += ", "; - update += "`" + field + "` = :" + field; - cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); - - first = false; - } - - update += " where UUID = :UUID"; - cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); - - cmd.CommandText = update; - try - { - if (ExecuteNonQuery(cmd, m_Connection) < 1) - { - //CloseCommand(cmd); - return false; - } - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - //CloseCommand(cmd); - return false; - } - } - - else - { - string insert = "insert into `" + m_Realm + "` (`UUID`, `" + - String.Join("`, `", fields) + - "`) values (:UUID, :" + String.Join(", :", fields) + ")"; - - cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); - foreach (string field in fields) - cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); - - cmd.CommandText = insert; - - try - { - if (ExecuteNonQuery(cmd, m_Connection) < 1) - { - //CloseCommand(cmd); - return false; - } - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - //CloseCommand(cmd); - return false; - } - } - - //CloseCommand(cmd); - - return true; - } - - public bool SetDataItem(UUID principalID, string item, string value) - { - SqliteCommand cmd = new SqliteCommand("update `" + m_Realm + - "` set `" + item + "` = " + value + " where UUID = '" + principalID.ToString() + "'"); - - if (ExecuteNonQuery(cmd, m_Connection) > 0) - return true; - - return false; - } - - public bool SetToken(UUID principalID, string token, int lifetime) - { - if (System.Environment.TickCount - m_LastExpire > 30000) - DoExpire(); - - SqliteCommand cmd = new SqliteCommand("insert into tokens (UUID, token, validity) values ('" + principalID.ToString() + - "', '" + token + "', datetime('now', 'localtime', '+" + lifetime.ToString() + " minutes'))"); - - if (ExecuteNonQuery(cmd, m_Connection) > 0) - { - cmd.Dispose(); - return true; - } - - cmd.Dispose(); - return false; - } - - public bool CheckToken(UUID principalID, string token, int lifetime) - { - if (System.Environment.TickCount - m_LastExpire > 30000) - DoExpire(); - - SqliteCommand cmd = new SqliteCommand("update tokens set validity = datetime('now', 'localtime', '+" + lifetime.ToString() + - " minutes') where UUID = '" + principalID.ToString() + "' and token = '" + token + "' and validity > datetime('now', 'localtime')"); - - if (ExecuteNonQuery(cmd, m_Connection) > 0) - { - cmd.Dispose(); - return true; - } - - cmd.Dispose(); - - return false; - } - - private void DoExpire() - { - SqliteCommand cmd = new SqliteCommand("delete from tokens where validity < datetime('now', 'localtime')"); - ExecuteNonQuery(cmd, m_Connection); - - cmd.Dispose(); - - m_LastExpire = System.Environment.TickCount; - } - } -} diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs index ad4e2a2..643e55d 100644 --- a/OpenSim/Data/SQLite/SQLiteEstateData.cs +++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs @@ -180,7 +180,7 @@ namespace OpenSim.Data.SQLite // cmd.Parameters.Clear(); cmd.CommandText = "insert into estateban select "+es.EstateID.ToString()+", bannedUUID, bannedIp, bannedIpHostMask, '' from regionban where regionban.regionUUID = :UUID"; - cmd.Parameters.Add(":UUID", regionID.ToString()); + cmd.Parameters.AddWithValue(":UUID", regionID.ToString()); try { @@ -336,66 +336,5 @@ namespace OpenSim.Data.SQLite return uuids.ToArray(); } -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteEstateData.cs -======= - - public EstateSettings LoadEstateSettings(int estateID) - { - string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID :EstateID"; - - SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); - - cmd.CommandText = sql; - cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); - - return DoLoad(cmd, UUID.Zero, false); - } - - public List GetEstates(string search) - { - List result = new List(); - - string sql = "select EstateID from estate_settings where estate_settings.EstateName :EstateName"; - - SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); - - cmd.CommandText = sql; - cmd.Parameters.AddWithValue(":EstateName", search); - - IDataReader r = cmd.ExecuteReader(); - - while (r.Read()) - { - result.Add(Convert.ToInt32(r["EstateID"])); - } - r.Close(); - - return result; - } - - public bool LinkRegion(UUID regionID, int estateID) - { - SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); - - cmd.CommandText = "insert into estate_map values (:RegionID, :EstateID)"; - cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); - cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); - - if (cmd.ExecuteNonQuery() == 0) - return false; - - return true; - } - - public List GetRegions(int estateID) - { - return new List(); - } - - public bool DeleteEstate(int estateID) - { - return false; - } ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteEstateData.cs } -} +} \ No newline at end of file diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs index 79eaab3..9567727 100644 --- a/OpenSim/Data/SQLite/SQLiteFramework.cs +++ b/OpenSim/Data/SQLite/SQLiteFramework.cs @@ -57,19 +57,7 @@ namespace OpenSim.Data.SQLite { lock (m_Connection) { -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteFramework.cs cmd.Connection = m_Connection; -======= -/* - SqliteConnection newConnection = - (SqliteConnection)((ICloneable)connection).Clone(); - newConnection.Open(); - - cmd.Connection = newConnection; -*/ - cmd.Connection = connection; - //Console.WriteLine("XXX " + cmd.CommandText); ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteFramework.cs return cmd.ExecuteNonQuery(); } @@ -77,27 +65,18 @@ namespace OpenSim.Data.SQLite protected IDataReader ExecuteReader(SqliteCommand cmd) { -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteFramework.cs - SqliteConnection newConnection = - (SqliteConnection)((ICloneable)m_Connection).Clone(); - newConnection.Open(); - - cmd.Connection = newConnection; - return cmd.ExecuteReader(); -======= - lock (connection) + lock (m_Connection) { //SqliteConnection newConnection = // (SqliteConnection)((ICloneable)connection).Clone(); //newConnection.Open(); //cmd.Connection = newConnection; - cmd.Connection = connection; + cmd.Connection = m_Connection; //Console.WriteLine("XXX " + cmd.CommandText); return cmd.ExecuteReader(); } ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteFramework.cs } protected void CloseReaderCommand(SqliteCommand cmd) @@ -107,4 +86,4 @@ namespace OpenSim.Data.SQLite cmd.Dispose(); } } -} +} \ No newline at end of file diff --git a/OpenSim/Data/SQLite/SQLiteFriendsData.cs b/OpenSim/Data/SQLite/SQLiteFriendsData.cs deleted file mode 100644 index b06853c..0000000 --- a/OpenSim/Data/SQLite/SQLiteFriendsData.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using OpenMetaverse; -using OpenSim.Framework; -using Mono.Data.Sqlite; - -namespace OpenSim.Data.SQLite -{ - public class SQLiteFriendsData : SQLiteGenericTableHandler, IFriendsData - { - public SQLiteFriendsData(string connectionString, string realm) - : base(connectionString, realm, "FriendsStore") - { - } - - public FriendsData[] GetFriends(UUID userID) - { - SqliteCommand cmd = new SqliteCommand(); - - cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = :PrincipalID", m_Realm); - cmd.Parameters.AddWithValue(":PrincipalID", userID.ToString()); - - return DoQuery(cmd); - - } - - public bool Delete(UUID principalID, string friend) - { - SqliteCommand cmd = new SqliteCommand(); - - cmd.CommandText = String.Format("delete from {0} where PrincipalID = :PrincipalID and Friend = :Friend", m_Realm); - cmd.Parameters.AddWithValue(":PrincipalID", principalID.ToString()); - cmd.Parameters.AddWithValue(":Friend", friend); - - ExecuteNonQuery(cmd, cmd.Connection); - - return true; - } - - } -} diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs index 918cb3d..86eaca1 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs @@ -54,11 +54,8 @@ namespace OpenSim.Data.SQLite m_Realm = realm; if (storeName != String.Empty) { -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs - Assembly assem = GetType().Assembly; -======= m_Connection = new SqliteConnection(connectionString); - Console.WriteLine(string.Format("OPENING CONNECTION FOR {0} USING {1}", storeName, connectionString)); + //Console.WriteLine(string.Format("OPENING CONNECTION FOR {0} USING {1}", storeName, connectionString)); m_Connection.Open(); if (storeName != String.Empty) @@ -74,10 +71,6 @@ namespace OpenSim.Data.SQLite //newConnection.Close(); //newConnection.Dispose(); } ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs - - Migration m = new Migration(m_Connection, assem, storeName); - m.Update(); } Type t = typeof(T); @@ -200,11 +193,7 @@ namespace OpenSim.Data.SQLite result.Add(row); } -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs - CloseReaderCommand(cmd); -======= //CloseCommand(cmd); ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs return result.ToArray(); } diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 0149838..9ce21b1 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs @@ -88,30 +88,18 @@ namespace OpenSim.Data.SQLite invFoldersDa = new SqliteDataAdapter(foldersSelectCmd); ds = new DataSet(); - -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteInventoryStore.cs + ds.Tables.Add(createInventoryFoldersTable()); invFoldersDa.Fill(ds.Tables["inventoryfolders"]); setupFoldersCommands(invFoldersDa, conn); + CreateDataSetMapping(invFoldersDa, "inventoryfolders"); m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); ds.Tables.Add(createInventoryItemsTable()); invItemsDa.Fill(ds.Tables["inventoryitems"]); setupItemsCommands(invItemsDa, conn); + CreateDataSetMapping(invItemsDa, "inventoryitems"); m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); -======= - ds.Tables.Add(createInventoryFoldersTable()); - invFoldersDa.Fill(ds.Tables["inventoryfolders"]); - setupFoldersCommands(invFoldersDa, conn); - CreateDataSetMapping(invFoldersDa, "inventoryfolders"); - m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); - - ds.Tables.Add(createInventoryItemsTable()); - invItemsDa.Fill(ds.Tables["inventoryitems"]); - setupItemsCommands(invItemsDa, conn); - CreateDataSetMapping(invItemsDa, "inventoryitems"); - m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteInventoryStore.cs ds.AcceptChanges(); } diff --git a/OpenSim/Data/SQLite/SQLiteManager.cs b/OpenSim/Data/SQLite/SQLiteManager.cs index b6d4a1c..7dcd323 100644 --- a/OpenSim/Data/SQLite/SQLiteManager.cs +++ b/OpenSim/Data/SQLite/SQLiteManager.cs @@ -28,9 +28,9 @@ using System; using System.Collections.Generic; using System.Data; -using System.Data.SQLite; using System.Reflection; using log4net; +using Mono.Data.Sqlite; using OpenMetaverse; namespace OpenSim.Data.SQLite @@ -66,7 +66,7 @@ namespace OpenSim.Data.SQLite connectionString = "URI=file:GridServerSqlite.db;"; } - dbcon = new SQLiteConnection(connectionString); + dbcon = new SqliteConnection(connectionString); dbcon.Open(); } @@ -93,11 +93,11 @@ namespace OpenSim.Data.SQLite /// A SQLite DB Command public IDbCommand Query(string sql, Dictionary parameters) { - SQLiteCommand dbcommand = (SQLiteCommand) dbcon.CreateCommand(); + SqliteCommand dbcommand = (SqliteCommand) dbcon.CreateCommand(); dbcommand.CommandText = sql; foreach (KeyValuePair param in parameters) { - SQLiteParameter paramx = new SQLiteParameter(param.Key, param.Value); + SqliteParameter paramx = new SqliteParameter(param.Key, param.Value); dbcommand.Parameters.Add(paramx); } diff --git a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs deleted file mode 100644 index 893f105..0000000 --- a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using OpenMetaverse; -using OpenSim.Framework; -using Mono.Data.Sqlite; - -namespace OpenSim.Data.SQLite -{ - public class SQLiteUserAccountData : SQLiteGenericTableHandler, IUserAccountData - { - public SQLiteUserAccountData(string connectionString, string realm) - : base(connectionString, realm, "UserAccount") - { - } - - public UserAccountData[] GetUsers(UUID scopeID, string query) - { - string[] words = query.Split(new char[] {' '}); - - for (int i = 0 ; i < words.Length ; i++) - { - if (words[i].Length < 3) - { - if (i != words.Length - 1) - Array.Copy(words, i + 1, words, i, words.Length - i - 1); - Array.Resize(ref words, words.Length - 1); - } - } - - if (words.Length == 0) - return new UserAccountData[0]; - - if (words.Length > 2) - return new UserAccountData[0]; - - SqliteCommand cmd = new SqliteCommand(); - - if (words.Length == 1) - { - cmd.CommandText = String.Format("select * from {0} where ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{2}%')", - m_Realm, scopeID.ToString(), words[0]); - } - else - { - cmd.CommandText = String.Format("select * from {0} where (ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{3}%')", - m_Realm, scopeID.ToString(), words[0], words[1]); - } - - return DoQuery(cmd); - } - } -} diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs index caddcf8..12db403 100644 --- a/OpenSim/Data/SQLite/SQLiteUserData.cs +++ b/OpenSim/Data/SQLite/SQLiteUserData.cs @@ -30,7 +30,7 @@ using System.Collections.Generic; using System.Data; using System.Reflection; using log4net; -using Mono.Data.SqliteClient; +using Mono.Data.Sqlite; using OpenMetaverse; using OpenSim.Framework; diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 0650a86..0d211b6 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs @@ -147,12 +147,8 @@ namespace OpenSim.Data.SQLite } reader.Close(); -<<<<<<< HEAD:OpenSim/Data/SQLite/SQLiteXInventoryData.cs - CloseReaderCommand(cmd); -======= + //CloseCommand(cmd); ->>>>>>> cc67de5... rename SQLiteNG to SQLite and SQLite to SQLiteLegacy:OpenSim/Data/SQLite/SQLiteXInventoryData.cs - return perms; } } -- cgit v1.1 From 8966ed9c82c8199bf0da61815d04d485d67aa34a Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Apr 2010 21:37:31 +0100 Subject: fix an issue with user appearance where the new sqlite db adapter expects directly specification of byte[] type rather than base64 strings --- OpenSim/Data/SQLite/SQLiteUserData.cs | 37 +++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'OpenSim/Data/SQLite') diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs index 12db403..bffc0d0 100644 --- a/OpenSim/Data/SQLite/SQLiteUserData.cs +++ b/OpenSim/Data/SQLite/SQLiteUserData.cs @@ -108,22 +108,32 @@ namespace OpenSim.Data.SQLite lock (ds) { + Console.WriteLine("Here1"); ds.Tables.Add(createUsersTable()); ds.Tables.Add(createUserAgentsTable()); ds.Tables.Add(createUserFriendsTable()); ds.Tables.Add(createAvatarAppearanceTable()); + Console.WriteLine("Here2"); setupUserCommands(da, conn); da.Fill(ds.Tables["users"]); + CreateDataSetMapping(da, "users"); + Console.WriteLine("Here3"); setupAgentCommands(dua, conn); dua.Fill(ds.Tables["useragents"]); + CreateDataSetMapping(dua, "useragents"); + Console.WriteLine("Here4"); setupUserFriendsCommands(daf, conn); daf.Fill(ds.Tables["userfriends"]); + CreateDataSetMapping(daf, "userfriends"); + Console.WriteLine("Here5"); setupAvatarAppearanceCommands(daa, conn); daa.Fill(ds.Tables["avatarappearance"]); + CreateDataSetMapping(daa, "avatarappearance"); + Console.WriteLine("Here6"); } return; @@ -706,15 +716,10 @@ namespace OpenSim.Data.SQLite aa.SkirtItem = new UUID((String)row["SkirtItem"]); aa.SkirtAsset = new UUID((String)row["SkirtAsset"]); - // Ewe Loon - // Used Base64String because for some reason it wont accept using Byte[] (which works in Region date) - - String str = (String)row["Texture"]; - byte[] texture = Convert.FromBase64String(str); + byte[] texture = (byte[])row["Texture"]; aa.Texture = new Primitive.TextureEntry(texture, 0, texture.Length); - str = (String)row["VisualParams"]; - byte[] VisualParams = Convert.FromBase64String(str); + byte[] VisualParams = (byte[])row["VisualParams"]; aa.VisualParams = VisualParams; aa.Serial = Convert.ToInt32(row["Serial"]); @@ -793,6 +798,15 @@ namespace OpenSim.Data.SQLite * **********************************************************************/ + protected void CreateDataSetMapping(IDataAdapter da, string tableName) + { + ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName); + foreach (DataColumn col in ds.Tables[tableName].Columns) + { + dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName); + } + } + /// /// Create the "users" table /// @@ -924,9 +938,8 @@ namespace OpenSim.Data.SQLite SQLiteUtil.createCol(aa, "SkirtItem", typeof(String)); SQLiteUtil.createCol(aa, "SkirtAsset", typeof(String)); - // Used Base64String because for some reason it wont accept using Byte[] (which works in Region date) - SQLiteUtil.createCol(aa, "Texture", typeof (String)); - SQLiteUtil.createCol(aa, "VisualParams", typeof (String)); + SQLiteUtil.createCol(aa, "Texture", typeof (Byte[])); + SQLiteUtil.createCol(aa, "VisualParams", typeof (Byte[])); SQLiteUtil.createCol(aa, "Serial", typeof(Int32)); SQLiteUtil.createCol(aa, "AvatarHeight", typeof(Double)); @@ -1090,8 +1103,8 @@ namespace OpenSim.Data.SQLite row["SkirtAsset"] = appearance.SkirtAsset.ToString(); // Used Base64String because for some reason it wont accept using Byte[] (which works in Region date) - row["Texture"] = Convert.ToBase64String(appearance.Texture.GetBytes()); - row["VisualParams"] = Convert.ToBase64String(appearance.VisualParams); + row["Texture"] = appearance.Texture.GetBytes(); + row["VisualParams"] = appearance.VisualParams; row["Serial"] = appearance.Serial; row["AvatarHeight"] = appearance.AvatarHeight; -- cgit v1.1 From 139f425f4cf4c720681a10e9cd5399fe0ed3b86c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 30 Apr 2010 22:08:57 +0100 Subject: take out some more sqlite db console debug lines --- OpenSim/Data/SQLite/SQLiteUserData.cs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'OpenSim/Data/SQLite') diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs index bffc0d0..ea755b0 100644 --- a/OpenSim/Data/SQLite/SQLiteUserData.cs +++ b/OpenSim/Data/SQLite/SQLiteUserData.cs @@ -108,32 +108,26 @@ namespace OpenSim.Data.SQLite lock (ds) { - Console.WriteLine("Here1"); ds.Tables.Add(createUsersTable()); ds.Tables.Add(createUserAgentsTable()); ds.Tables.Add(createUserFriendsTable()); ds.Tables.Add(createAvatarAppearanceTable()); - Console.WriteLine("Here2"); setupUserCommands(da, conn); da.Fill(ds.Tables["users"]); CreateDataSetMapping(da, "users"); - Console.WriteLine("Here3"); setupAgentCommands(dua, conn); dua.Fill(ds.Tables["useragents"]); CreateDataSetMapping(dua, "useragents"); - Console.WriteLine("Here4"); setupUserFriendsCommands(daf, conn); daf.Fill(ds.Tables["userfriends"]); CreateDataSetMapping(daf, "userfriends"); - Console.WriteLine("Here5"); setupAvatarAppearanceCommands(daa, conn); daa.Fill(ds.Tables["avatarappearance"]); CreateDataSetMapping(daa, "avatarappearance"); - Console.WriteLine("Here6"); } return; -- cgit v1.1 From 8eb70f9719585f26f4dc610b383d546bda091655 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 4 Jun 2010 17:14:12 +0100 Subject: Fix bug where prim items were not loaded in the new sqlite database handler This addresses mantis http://opensimulator.org/mantis/view.php?id=4739 --- OpenSim/Data/SQLite/SQLiteRegionData.cs | 66 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'OpenSim/Data/SQLite') diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index fe6e919..4313db8 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs @@ -93,7 +93,7 @@ namespace OpenSim.Data.SQLite ds = new DataSet("Region"); - m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString); + m_log.Info("[SQLITE REGION DB]: Sqlite - connecting: " + connectionString); m_conn = new SqliteConnection(m_connectionString); m_conn.Open(); @@ -156,7 +156,7 @@ namespace OpenSim.Data.SQLite } catch (Exception) { - m_log.Info("[REGION DB]: Caught fill error on prims table"); + m_log.Info("[SQLITE REGION DB]: Caught fill error on prims table"); } try @@ -165,16 +165,25 @@ namespace OpenSim.Data.SQLite } catch (Exception) { - m_log.Info("[REGION DB]: Caught fill error on primshapes table"); + m_log.Info("[SQLITE REGION DB]: Caught fill error on primshapes table"); } try { + itemsDa.Fill(ds.Tables["primitems"]); + } + catch (Exception) + { + m_log.Info("[SQLITE REGION DB]: Caught fill error on primitems table"); + } + + try + { terrainDa.Fill(ds.Tables["terrain"]); } catch (Exception) { - m_log.Info("[REGION DB]: Caught fill error on terrain table"); + m_log.Info("[SQLITE REGION DB]: Caught fill error on terrain table"); } try @@ -183,7 +192,7 @@ namespace OpenSim.Data.SQLite } catch (Exception) { - m_log.Info("[REGION DB]: Caught fill error on land table"); + m_log.Info("[SQLITE REGION DB]: Caught fill error on land table"); } try @@ -192,7 +201,7 @@ namespace OpenSim.Data.SQLite } catch (Exception) { - m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); + m_log.Info("[SQLITE REGION DB]: Caught fill error on landaccesslist table"); } try @@ -201,7 +210,7 @@ namespace OpenSim.Data.SQLite } catch (Exception) { - m_log.Info("[REGION DB]: Caught fill error on regionsettings table"); + m_log.Info("[SQLITE REGION DB]: Caught fill error on regionsettings table"); } // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values! @@ -425,7 +434,7 @@ namespace OpenSim.Data.SQLite lock (ds) { DataRow[] primsForRegion = prims.Select(byRegion); - m_log.Info("[REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); +// m_log.Info("[SQLITE REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); // First, create all groups foreach (DataRow primRow in primsForRegion) @@ -447,8 +456,8 @@ namespace OpenSim.Data.SQLite } else { - m_log.Info( - "[REGION DB]: No shape found for prim in storage, so setting default box shape"); + m_log.Warn( + "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape"); prim.Shape = PrimitiveBaseShape.Default; } @@ -460,11 +469,11 @@ namespace OpenSim.Data.SQLite } catch (Exception e) { - m_log.Error("[REGION DB]: Failed create prim object in new group, exception and data follows"); - m_log.Info("[REGION DB]: " + e.ToString()); + m_log.Error("[SQLITE REGION DB]: Failed create prim object in new group, exception and data follows"); + m_log.Error("[SQLITE REGION DB]: ", e); foreach (DataColumn col in prims.Columns) { - m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); + m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); } } } @@ -489,7 +498,7 @@ namespace OpenSim.Data.SQLite else { m_log.Warn( - "[REGION DB]: No shape found for prim in storage, so setting default box shape"); + "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape"); prim.Shape = PrimitiveBaseShape.Default; } @@ -499,11 +508,11 @@ namespace OpenSim.Data.SQLite } catch (Exception e) { - m_log.Error("[REGION DB]: Failed create prim object in group, exception and data follows"); - m_log.Info("[REGION DB]: " + e.ToString()); + m_log.Error("[SQLITE REGION DB]: Failed create prim object in group, exception and data follows"); + m_log.Error("[SQLITE REGION DB]: ", e); foreach (DataColumn col in prims.Columns) { - m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); + m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); } } } @@ -516,20 +525,23 @@ namespace OpenSim.Data.SQLite /// /// the prim private void LoadItems(SceneObjectPart prim) - { - //m_log.DebugFormat("[DATASTORE]: Loading inventory for {0}, {1}", prim.Name, prim.UUID); - + { +// m_log.DebugFormat("[SQLITE REGION DB]: Loading inventory for {0} {1}", prim.Name, prim.UUID); + DataTable dbItems = ds.Tables["primitems"]; - String sql = String.Format("primID = '{0}'", prim.UUID.ToString()); + String sql = String.Format("primID = '{0}'", prim.UUID.ToString()); DataRow[] dbItemRows = dbItems.Select(sql); IList inventory = new List(); +// m_log.DebugFormat( +// "[SQLITE REGION DB]: Found {0} items for {1} {2}", dbItemRows.Length, prim.Name, prim.UUID); + foreach (DataRow row in dbItemRows) { TaskInventoryItem item = buildItem(row); inventory.Add(item); - //m_log.DebugFormat("[DATASTORE]: Restored item {0}, {1}", item.Name, item.ItemID); +// m_log.DebugFormat("[SQLITE REGION DB]: Restored item {0} {1}", item.Name, item.ItemID); } prim.Inventory.RestoreInventoryItems(inventory); @@ -565,7 +577,7 @@ namespace OpenSim.Data.SQLite // the following is an work around for .NET. The perf // issues associated with it aren't as bad as you think. - m_log.Info("[REGION DB]: Storing terrain revision r" + revision.ToString()); + m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString()); String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + " values(:RegionUUID, :Revision, :Heightfield)"; @@ -621,11 +633,11 @@ namespace OpenSim.Data.SQLite } else { - m_log.Info("[REGION DB]: No terrain found for region"); + m_log.Warn("[SQLITE REGION DB]: No terrain found for region"); return null; } - m_log.Info("[REGION DB]: Loaded terrain revision r" + rev.ToString()); + m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); } } return terret; @@ -1407,7 +1419,7 @@ namespace OpenSim.Data.SQLite } catch (InvalidCastException) { - m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name); + m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name); newData.UserLocation = Vector3.Zero; newData.UserLookAt = Vector3.Zero; } @@ -1914,7 +1926,7 @@ namespace OpenSim.Data.SQLite /// public void StorePrimInventory(UUID primID, ICollection items) { - //m_log.InfoFormat("[REGION DB]: Entered StorePrimInventory with prim ID {0}", primID); +// m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID); DataTable dbItems = ds.Tables["primitems"]; -- cgit v1.1