diff options
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteInventoryStore.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 64591fd..ece2495 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs | |||
@@ -30,7 +30,7 @@ using System.Collections.Generic; | |||
30 | using System.Data; | 30 | using System.Data; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using log4net; | 32 | using log4net; |
33 | using Mono.Data.SqliteClient; | 33 | using Mono.Data.Sqlite; |
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | 36 | ||
@@ -46,10 +46,12 @@ namespace OpenSim.Data.SQLite | |||
46 | private const string invItemsSelect = "select * from inventoryitems"; | 46 | private const string invItemsSelect = "select * from inventoryitems"; |
47 | private const string invFoldersSelect = "select * from inventoryfolders"; | 47 | private const string invFoldersSelect = "select * from inventoryfolders"; |
48 | 48 | ||
49 | private SqliteConnection conn; | 49 | private static SqliteConnection conn; |
50 | private DataSet ds; | 50 | private static DataSet ds; |
51 | private SqliteDataAdapter invItemsDa; | 51 | private static SqliteDataAdapter invItemsDa; |
52 | private SqliteDataAdapter invFoldersDa; | 52 | private static SqliteDataAdapter invFoldersDa; |
53 | |||
54 | private static bool m_Initialized = false; | ||
53 | 55 | ||
54 | public void Initialise() | 56 | public void Initialise() |
55 | { | 57 | { |
@@ -67,39 +69,46 @@ namespace OpenSim.Data.SQLite | |||
67 | /// <param name="dbconnect">connect string</param> | 69 | /// <param name="dbconnect">connect string</param> |
68 | public void Initialise(string dbconnect) | 70 | public void Initialise(string dbconnect) |
69 | { | 71 | { |
70 | if (dbconnect == string.Empty) | 72 | if (!m_Initialized) |
71 | { | 73 | { |
72 | dbconnect = "URI=file:inventoryStore.db,version=3"; | 74 | m_Initialized = true; |
73 | } | 75 | |
74 | m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect); | 76 | if (dbconnect == string.Empty) |
75 | conn = new SqliteConnection(dbconnect); | 77 | { |
78 | dbconnect = "URI=file:inventoryStore.db,version=3"; | ||
79 | } | ||
80 | m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect); | ||
81 | conn = new SqliteConnection(dbconnect); | ||
76 | 82 | ||
77 | conn.Open(); | 83 | conn.Open(); |
78 | 84 | ||
79 | Assembly assem = GetType().Assembly; | 85 | Assembly assem = GetType().Assembly; |
80 | Migration m = new Migration(conn, assem, "InventoryStore"); | 86 | Migration m = new Migration(conn, assem, "InventoryStore"); |
81 | m.Update(); | 87 | m.Update(); |
82 | 88 | ||
83 | SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn); | 89 | SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn); |
84 | invItemsDa = new SqliteDataAdapter(itemsSelectCmd); | 90 | invItemsDa = new SqliteDataAdapter(itemsSelectCmd); |
85 | // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); | 91 | // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); |
86 | 92 | ||
87 | SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn); | 93 | SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn); |
88 | invFoldersDa = new SqliteDataAdapter(foldersSelectCmd); | 94 | invFoldersDa = new SqliteDataAdapter(foldersSelectCmd); |
89 | 95 | ||
90 | ds = new DataSet(); | 96 | ds = new DataSet(); |
91 | 97 | ||
92 | ds.Tables.Add(createInventoryFoldersTable()); | 98 | ds.Tables.Add(createInventoryFoldersTable()); |
93 | invFoldersDa.Fill(ds.Tables["inventoryfolders"]); | 99 | invFoldersDa.Fill(ds.Tables["inventoryfolders"]); |
94 | setupFoldersCommands(invFoldersDa, conn); | 100 | setupFoldersCommands(invFoldersDa, conn); |
95 | m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); | 101 | CreateDataSetMapping(invFoldersDa, "inventoryfolders"); |
102 | m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions"); | ||
96 | 103 | ||
97 | ds.Tables.Add(createInventoryItemsTable()); | 104 | ds.Tables.Add(createInventoryItemsTable()); |
98 | invItemsDa.Fill(ds.Tables["inventoryitems"]); | 105 | invItemsDa.Fill(ds.Tables["inventoryitems"]); |
99 | setupItemsCommands(invItemsDa, conn); | 106 | setupItemsCommands(invItemsDa, conn); |
100 | m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); | 107 | CreateDataSetMapping(invItemsDa, "inventoryitems"); |
108 | m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions"); | ||
101 | 109 | ||
102 | ds.AcceptChanges(); | 110 | ds.AcceptChanges(); |
111 | } | ||
103 | } | 112 | } |
104 | 113 | ||
105 | /// <summary> | 114 | /// <summary> |
@@ -721,6 +730,15 @@ namespace OpenSim.Data.SQLite | |||
721 | * | 730 | * |
722 | **********************************************************************/ | 731 | **********************************************************************/ |
723 | 732 | ||
733 | protected void CreateDataSetMapping(IDataAdapter da, string tableName) | ||
734 | { | ||
735 | ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName); | ||
736 | foreach (DataColumn col in ds.Tables[tableName].Columns) | ||
737 | { | ||
738 | dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName); | ||
739 | } | ||
740 | } | ||
741 | |||
724 | /// <summary> | 742 | /// <summary> |
725 | /// Create the "inventoryitems" table | 743 | /// Create the "inventoryitems" table |
726 | /// </summary> | 744 | /// </summary> |