aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
diff options
context:
space:
mode:
authorSean Dague2008-06-11 21:01:33 +0000
committerSean Dague2008-06-11 21:01:33 +0000
commit6c1fce61473b8d3faf9ee4602b9d0a392f148b7c (patch)
tree0cb0091493f725c0b06c2ceba493220eb85d507d /OpenSim/Data/SQLite/SQLiteInventoryStore.cs
parentupdated resources for current sqlite schema for migrations (diff)
downloadopensim-SC_OLD-6c1fce61473b8d3faf9ee4602b9d0a392f148b7c.zip
opensim-SC_OLD-6c1fce61473b8d3faf9ee4602b9d0a392f148b7c.tar.gz
opensim-SC_OLD-6c1fce61473b8d3faf9ee4602b9d0a392f148b7c.tar.bz2
opensim-SC_OLD-6c1fce61473b8d3faf9ee4602b9d0a392f148b7c.tar.xz
check in working migration code fore SQLite. This
is now using migrations instead of the old model to create tables. Tested for existing old tables, and for creating new ones.
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteInventoryStore.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteInventoryStore.cs120
1 files changed, 65 insertions, 55 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
index 5acc5f2..5b77f82 100644
--- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
+++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs
@@ -61,7 +61,12 @@ namespace OpenSim.Data.SQLite
61 61
62 conn.Open(); 62 conn.Open();
63 63
64 TestTables(conn); 64 Assembly assem = GetType().Assembly;
65 Migration m = new Migration(conn, assem, "InventoryStore");
66 // TODO: remove this line after changeset 6000
67 TestTables(conn, m);
68
69 m.Update();
65 70
66 SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn); 71 SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
67 invItemsDa = new SqliteDataAdapter(itemsSelectCmd); 72 invItemsDa = new SqliteDataAdapter(itemsSelectCmd);
@@ -672,7 +677,7 @@ namespace OpenSim.Data.SQLite
672 scmd.ExecuteNonQuery(); 677 scmd.ExecuteNonQuery();
673 } 678 }
674 679
675 private static bool TestTables(SqliteConnection conn) 680 private static bool TestTables(SqliteConnection conn, Migration m)
676 { 681 {
677 SqliteCommand invItemsSelectCmd = new SqliteCommand(invItemsSelect, conn); 682 SqliteCommand invItemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
678 SqliteDataAdapter pDa = new SqliteDataAdapter(invItemsSelectCmd); 683 SqliteDataAdapter pDa = new SqliteDataAdapter(invItemsSelectCmd);
@@ -688,63 +693,68 @@ namespace OpenSim.Data.SQLite
688 catch (SqliteSyntaxException) 693 catch (SqliteSyntaxException)
689 { 694 {
690 m_log.Info("[INVENTORY DB]: SQLite Database doesn't exist... creating"); 695 m_log.Info("[INVENTORY DB]: SQLite Database doesn't exist... creating");
691 InitDB(conn); 696 return false;
692 } 697 }
693 698
694 pDa.Fill(tmpDS, "inventoryitems"); 699 if (m.Version == 0)
695 sDa.Fill(tmpDS, "inventoryfolders"); 700 m.Version = 1;
696
697 // Very clumsy way of checking whether we need to upgrade the database table version and then updating. Only
698 // putting up with this because this code should be blown away soon by nhibernate...
699 conn.Open();
700
701 SqliteCommand cmd;
702 try
703 {
704 cmd = new SqliteCommand("select salePrice from inventoryitems limit 1;", conn);
705 cmd.ExecuteNonQuery();
706 }
707 catch (SqliteSyntaxException)
708 {
709 m_log.Info("[INVENTORY DB]: Upgrading sqlite inventory database to version 2");
710
711 cmd = new SqliteCommand("alter table inventoryitems add column salePrice integer default 99;", conn);
712 cmd.ExecuteNonQuery();
713 cmd = new SqliteCommand("alter table inventoryitems add column saleType integer default 0;", conn);
714 cmd.ExecuteNonQuery();
715 cmd = new SqliteCommand("alter table inventoryitems add column creationDate integer default 2000;", conn);
716 cmd.ExecuteNonQuery();
717 cmd = new SqliteCommand("alter table inventoryitems add column groupID varchar(255) default '00000000-0000-0000-0000-000000000000';", conn);
718 cmd.ExecuteNonQuery();
719 cmd = new SqliteCommand("alter table inventoryitems add column groupOwned integer default 0;", conn);
720 cmd.ExecuteNonQuery();
721 cmd = new SqliteCommand("alter table inventoryitems add column flags integer default 0;", conn);
722 cmd.ExecuteNonQuery();
723 701
724 pDa.Fill(tmpDS, "inventoryitems");
725 }
726 finally
727 {
728 conn.Close();
729 }
730
731 foreach (DataColumn col in createInventoryItemsTable().Columns)
732 {
733 if (! tmpDS.Tables["inventoryitems"].Columns.Contains(col.ColumnName))
734 {
735 m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
736 return false;
737 }
738 }
739 foreach (DataColumn col in createInventoryFoldersTable().Columns)
740 {
741 if (! tmpDS.Tables["inventoryfolders"].Columns.Contains(col.ColumnName))
742 {
743 m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
744 return false;
745 }
746 }
747 return true; 702 return true;
703
704 // pDa.Fill(tmpDS, "inventoryitems");
705 // sDa.Fill(tmpDS, "inventoryfolders");
706
707 // // Very clumsy way of checking whether we need to upgrade the database table version and then updating. Only
708 // // putting up with this because this code should be blown away soon by nhibernate...
709 // conn.Open();
710
711 // SqliteCommand cmd;
712 // try
713 // {
714 // cmd = new SqliteCommand("select salePrice from inventoryitems limit 1;", conn);
715 // cmd.ExecuteNonQuery();
716 // }
717 // catch (SqliteSyntaxException)
718 // {
719 // m_log.Info("[INVENTORY DB]: Upgrading sqlite inventory database to version 2");
720
721 // cmd = new SqliteCommand("alter table inventoryitems add column salePrice integer default 99;", conn);
722 // cmd.ExecuteNonQuery();
723 // cmd = new SqliteCommand("alter table inventoryitems add column saleType integer default 0;", conn);
724 // cmd.ExecuteNonQuery();
725 // cmd = new SqliteCommand("alter table inventoryitems add column creationDate integer default 2000;", conn);
726 // cmd.ExecuteNonQuery();
727 // cmd = new SqliteCommand("alter table inventoryitems add column groupID varchar(255) default '00000000-0000-0000-0000-000000000000';", conn);
728 // cmd.ExecuteNonQuery();
729 // cmd = new SqliteCommand("alter table inventoryitems add column groupOwned integer default 0;", conn);
730 // cmd.ExecuteNonQuery();
731 // cmd = new SqliteCommand("alter table inventoryitems add column flags integer default 0;", conn);
732 // cmd.ExecuteNonQuery();
733
734 // pDa.Fill(tmpDS, "inventoryitems");
735 // }
736 // finally
737 // {
738 // conn.Close();
739 // }
740
741 // foreach (DataColumn col in createInventoryItemsTable().Columns)
742 // {
743 // if (! tmpDS.Tables["inventoryitems"].Columns.Contains(col.ColumnName))
744 // {
745 // m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
746 // return false;
747 // }
748 // }
749 // foreach (DataColumn col in createInventoryFoldersTable().Columns)
750 // {
751 // if (! tmpDS.Tables["inventoryfolders"].Columns.Contains(col.ColumnName))
752 // {
753 // m_log.Info("[INVENTORY DB]: Missing required column:" + col.ColumnName);
754 // return false;
755 // }
756 // }
757 // return true;
748 } 758 }
749 } 759 }
750} 760}