diff options
author | Teravus Ovares (Dan Olivares) | 2010-02-13 05:09:15 -0500 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2010-02-13 05:09:15 -0500 |
commit | fa6da2f6c666e786513e4c822a37d6755c9ff716 (patch) | |
tree | 7c440b1bbba71da3853cf95b16e1e042d3ab1817 /OpenSim/Data/SQLite/SQLiteRegionData.cs | |
parent | minor: update CONTRIBUTORS.txt (diff) | |
download | opensim-SC-fa6da2f6c666e786513e4c822a37d6755c9ff716.zip opensim-SC-fa6da2f6c666e786513e4c822a37d6755c9ff716.tar.gz opensim-SC-fa6da2f6c666e786513e4c822a37d6755c9ff716.tar.bz2 opensim-SC-fa6da2f6c666e786513e4c822a37d6755c9ff716.tar.xz |
* This is an attempt to resolve mantis 4437 by using SqliteAdapter type statements instead of blanket SQL statements. The hope is that this makes SQLite work on Linux/Mono again. Re: http://opensimulator.org/mantis/view.php?id=4437
* Added a 'Create Update Statement' method that takes two fields for a primary key
* Added an Update and Delete command for parcels and land access list table rows.
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteRegionData.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteRegionData.cs | 111 |
1 files changed, 100 insertions, 11 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index b68de1a..1285064 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs | |||
@@ -617,18 +617,42 @@ namespace OpenSim.Data.SQLite | |||
617 | { | 617 | { |
618 | lock (ds) | 618 | lock (ds) |
619 | { | 619 | { |
620 | using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn)) | 620 | // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter |
621 | // after you're done. | ||
622 | // replaced below code with the SqliteAdapter version. | ||
623 | //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn)) | ||
624 | //{ | ||
625 | // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString())); | ||
626 | // cmd.ExecuteNonQuery(); | ||
627 | //} | ||
628 | |||
629 | //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn)) | ||
630 | //{ | ||
631 | // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString())); | ||
632 | // cmd.ExecuteNonQuery(); | ||
633 | //} | ||
634 | |||
635 | DataTable land = ds.Tables["land"]; | ||
636 | DataTable landaccesslist = ds.Tables["landaccesslist"]; | ||
637 | DataRow landRow = land.Rows.Find(globalID.ToString()); | ||
638 | if (landRow != null) | ||
621 | { | 639 | { |
622 | cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString())); | 640 | land.Rows.Remove(landRow); |
623 | cmd.ExecuteNonQuery(); | ||
624 | } | 641 | } |
625 | 642 | List<DataRow> rowsToDelete = new List<DataRow>(); | |
626 | using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn)) | 643 | foreach (DataRow rowToCheck in landaccesslist.Rows) |
627 | { | 644 | { |
628 | cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString())); | 645 | if (rowToCheck["LandUUID"].ToString() == globalID.ToString()) |
629 | cmd.ExecuteNonQuery(); | 646 | rowsToDelete.Add(rowToCheck); |
647 | } | ||
648 | for (int iter = 0; iter < rowsToDelete.Count; iter++) | ||
649 | { | ||
650 | landaccesslist.Rows.Remove(rowsToDelete[iter]); | ||
630 | } | 651 | } |
652 | |||
653 | |||
631 | } | 654 | } |
655 | Commit(); | ||
632 | } | 656 | } |
633 | 657 | ||
634 | /// <summary> | 658 | /// <summary> |
@@ -655,12 +679,27 @@ namespace OpenSim.Data.SQLite | |||
655 | } | 679 | } |
656 | 680 | ||
657 | // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around | 681 | // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around |
658 | using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn)) | 682 | //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn)) |
683 | //{ | ||
684 | // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString())); | ||
685 | // cmd.ExecuteNonQuery(); | ||
686 | |||
687 | // } | ||
688 | |||
689 | // This is the slower.. but more appropriate thing to do | ||
690 | |||
691 | // We can't modify the table with direct queries before calling Commit() and re-filling them. | ||
692 | List<DataRow> rowsToDelete = new List<DataRow>(); | ||
693 | foreach (DataRow rowToCheck in landaccesslist.Rows) | ||
659 | { | 694 | { |
660 | cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString())); | 695 | if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString()) |
661 | cmd.ExecuteNonQuery(); | 696 | rowsToDelete.Add(rowToCheck); |
662 | } | 697 | } |
663 | 698 | for (int iter = 0; iter < rowsToDelete.Count; iter++) | |
699 | { | ||
700 | landaccesslist.Rows.Remove(rowsToDelete[iter]); | ||
701 | } | ||
702 | rowsToDelete.Clear(); | ||
664 | foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList) | 703 | foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList) |
665 | { | 704 | { |
666 | DataRow newAccessRow = landaccesslist.NewRow(); | 705 | DataRow newAccessRow = landaccesslist.NewRow(); |
@@ -1813,6 +1852,7 @@ namespace OpenSim.Data.SQLite | |||
1813 | /// <param name="regionUUID"></param> | 1852 | /// <param name="regionUUID"></param> |
1814 | private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID) | 1853 | private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID) |
1815 | { | 1854 | { |
1855 | |||
1816 | DataTable prims = ds.Tables["prims"]; | 1856 | DataTable prims = ds.Tables["prims"]; |
1817 | DataTable shapes = ds.Tables["primshapes"]; | 1857 | DataTable shapes = ds.Tables["primshapes"]; |
1818 | 1858 | ||
@@ -1962,6 +2002,40 @@ namespace OpenSim.Data.SQLite | |||
1962 | } | 2002 | } |
1963 | 2003 | ||
1964 | /// <summary> | 2004 | /// <summary> |
2005 | /// create an update command | ||
2006 | /// </summary> | ||
2007 | /// <param name="table">table name</param> | ||
2008 | /// <param name="pk"></param> | ||
2009 | /// <param name="dt"></param> | ||
2010 | /// <returns>the created command</returns> | ||
2011 | private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt) | ||
2012 | { | ||
2013 | string sql = "update " + table + " set "; | ||
2014 | string subsql = String.Empty; | ||
2015 | foreach (DataColumn col in dt.Columns) | ||
2016 | { | ||
2017 | if (subsql.Length > 0) | ||
2018 | { | ||
2019 | // a map function would rock so much here | ||
2020 | subsql += ", "; | ||
2021 | } | ||
2022 | subsql += col.ColumnName + "= :" + col.ColumnName; | ||
2023 | } | ||
2024 | sql += subsql; | ||
2025 | sql += " where " + pk1 + " and " + pk2; | ||
2026 | SqliteCommand cmd = new SqliteCommand(sql); | ||
2027 | |||
2028 | // this provides the binding for all our parameters, so | ||
2029 | // much less code than it used to be | ||
2030 | |||
2031 | foreach (DataColumn col in dt.Columns) | ||
2032 | { | ||
2033 | cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); | ||
2034 | } | ||
2035 | return cmd; | ||
2036 | } | ||
2037 | |||
2038 | /// <summary> | ||
1965 | /// | 2039 | /// |
1966 | /// </summary> | 2040 | /// </summary> |
1967 | /// <param name="dt">Data Table</param> | 2041 | /// <param name="dt">Data Table</param> |
@@ -2079,6 +2153,11 @@ namespace OpenSim.Data.SQLite | |||
2079 | 2153 | ||
2080 | da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]); | 2154 | da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]); |
2081 | da.UpdateCommand.Connection = conn; | 2155 | da.UpdateCommand.Connection = conn; |
2156 | |||
2157 | SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID"); | ||
2158 | delete.Parameters.Add(createSqliteParameter("UUID", typeof(String))); | ||
2159 | da.DeleteCommand = delete; | ||
2160 | da.DeleteCommand.Connection = conn; | ||
2082 | } | 2161 | } |
2083 | 2162 | ||
2084 | /// <summary> | 2163 | /// <summary> |
@@ -2090,6 +2169,16 @@ namespace OpenSim.Data.SQLite | |||
2090 | { | 2169 | { |
2091 | da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]); | 2170 | da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]); |
2092 | da.InsertCommand.Connection = conn; | 2171 | da.InsertCommand.Connection = conn; |
2172 | |||
2173 | da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]); | ||
2174 | da.UpdateCommand.Connection = conn; | ||
2175 | |||
2176 | SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID"); | ||
2177 | delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String))); | ||
2178 | delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String))); | ||
2179 | da.DeleteCommand = delete; | ||
2180 | da.DeleteCommand.Connection = conn; | ||
2181 | |||
2093 | } | 2182 | } |
2094 | 2183 | ||
2095 | private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn) | 2184 | private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn) |