diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs | 246 |
1 files changed, 161 insertions, 85 deletions
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index b6c6c83..aa90eac 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs | |||
@@ -34,6 +34,8 @@ namespace OpenSim.DataStore.MonoSqliteStorage | |||
34 | public void Initialise(string dbfile, string dbname) | 34 | public void Initialise(string dbfile, string dbname) |
35 | { | 35 | { |
36 | string connectionString = "URI=file:" + dbfile + ",version=3"; | 36 | string connectionString = "URI=file:" + dbfile + ",version=3"; |
37 | |||
38 | ds = new DataSet(); | ||
37 | 39 | ||
38 | MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + dbfile); | 40 | MainLog.Instance.Verbose("DATASTORE", "Sqlite - connecting: " + dbfile); |
39 | SqliteConnection conn = new SqliteConnection(connectionString); | 41 | SqliteConnection conn = new SqliteConnection(connectionString); |
@@ -46,12 +48,17 @@ namespace OpenSim.DataStore.MonoSqliteStorage | |||
46 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); | 48 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); |
47 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); | 49 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); |
48 | 50 | ||
49 | ds = new DataSet(); | ||
50 | 51 | ||
51 | // We fill the data set, now we've got copies in memory for the information | 52 | // We fill the data set, now we've got copies in memory for the information |
52 | // TODO: see if the linkage actually holds. | 53 | // TODO: see if the linkage actually holds. |
53 | // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); | 54 | // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); |
54 | primDa.Fill(ds, "prims"); | 55 | try { |
56 | primDa.Fill(ds, "prims"); | ||
57 | } catch (Mono.Data.SqliteClient.SqliteSyntaxException) { | ||
58 | InitDB(conn); | ||
59 | primDa.Fill(ds, "prims"); | ||
60 | } | ||
61 | |||
55 | shapeDa.Fill(ds, "primshapes"); | 62 | shapeDa.Fill(ds, "primshapes"); |
56 | ds.AcceptChanges(); | 63 | ds.AcceptChanges(); |
57 | 64 | ||
@@ -67,6 +74,17 @@ namespace OpenSim.DataStore.MonoSqliteStorage | |||
67 | return; | 74 | return; |
68 | } | 75 | } |
69 | 76 | ||
77 | ///<summary> | ||
78 | /// This is a convenience function that collapses 5 repetitive | ||
79 | /// lines for defining SqliteParameters to 2 parameters: | ||
80 | /// column name and database type. | ||
81 | /// | ||
82 | /// It assumes certain conventions like :param as the param | ||
83 | /// name to replace in parametrized queries, and that source | ||
84 | /// version is always current version, both of which are fine | ||
85 | /// for us. | ||
86 | ///</summary> | ||
87 | ///<returns>a built sqlite parameter</returns> | ||
70 | private SqliteParameter createSqliteParameter(string name, DbType type) | 88 | private SqliteParameter createSqliteParameter(string name, DbType type) |
71 | { | 89 | { |
72 | SqliteParameter param = new SqliteParameter(); | 90 | SqliteParameter param = new SqliteParameter(); |
@@ -77,89 +95,6 @@ namespace OpenSim.DataStore.MonoSqliteStorage | |||
77 | return param; | 95 | return param; |
78 | } | 96 | } |
79 | 97 | ||
80 | private Dictionary<string, DbType> createPrimDataDefs() | ||
81 | { | ||
82 | Dictionary<string, DbType> data = new Dictionary<string, DbType>(); | ||
83 | data.Add("UUID", DbType.String); | ||
84 | data.Add("ParentID", DbType.Int32); | ||
85 | data.Add("CreationDate", DbType.Int32); | ||
86 | data.Add("Name", DbType.String); | ||
87 | data.Add("SceneGroupID", DbType.String); | ||
88 | // various text fields | ||
89 | data.Add("Text", DbType.String); | ||
90 | data.Add("Description", DbType.String); | ||
91 | data.Add("SitName", DbType.String); | ||
92 | data.Add("TouchName", DbType.String); | ||
93 | // permissions | ||
94 | data.Add("CreatorID", DbType.String); | ||
95 | data.Add("OwnerID", DbType.String); | ||
96 | data.Add("GroupID", DbType.String); | ||
97 | data.Add("LastOwnerID", DbType.String); | ||
98 | data.Add("OwnerMask", DbType.Int32); | ||
99 | data.Add("NextOwnerMask", DbType.Int32); | ||
100 | data.Add("GroupMask", DbType.Int32); | ||
101 | data.Add("EveryoneMask", DbType.Int32); | ||
102 | data.Add("BaseMask", DbType.Int32); | ||
103 | // vectors | ||
104 | data.Add("PositionX", DbType.Double); | ||
105 | data.Add("PositionY", DbType.Double); | ||
106 | data.Add("PositionZ", DbType.Double); | ||
107 | data.Add("GroupPositionX", DbType.Double); | ||
108 | data.Add("GroupPositionY", DbType.Double); | ||
109 | data.Add("GroupPositionZ", DbType.Double); | ||
110 | data.Add("VelocityX", DbType.Double); | ||
111 | data.Add("VelocityY", DbType.Double); | ||
112 | data.Add("VelocityZ", DbType.Double); | ||
113 | data.Add("AngularVelocityX", DbType.Double); | ||
114 | data.Add("AngularVelocityY", DbType.Double); | ||
115 | data.Add("AngularVelocityZ", DbType.Double); | ||
116 | data.Add("AccelerationX", DbType.Double); | ||
117 | data.Add("AccelerationY", DbType.Double); | ||
118 | data.Add("AccelerationZ", DbType.Double); | ||
119 | // quaternions | ||
120 | data.Add("RotationX", DbType.Double); | ||
121 | data.Add("RotationY", DbType.Double); | ||
122 | data.Add("RotationZ", DbType.Double); | ||
123 | data.Add("RotationW", DbType.Double); | ||
124 | return data; | ||
125 | } | ||
126 | |||
127 | private Dictionary<string, DbType> createShapeDataDefs() | ||
128 | { | ||
129 | Dictionary<string, DbType> data = new Dictionary<string, DbType>(); | ||
130 | data.Add("UUID", DbType.String); | ||
131 | // shape is an enum | ||
132 | data.Add("Shape", DbType.Int32); | ||
133 | // vectors | ||
134 | data.Add("ScaleX", DbType.Double); | ||
135 | data.Add("ScaleY", DbType.Double); | ||
136 | data.Add("ScaleZ", DbType.Double); | ||
137 | // paths | ||
138 | data.Add("PCode", DbType.Int32); | ||
139 | data.Add("PathBegin", DbType.Int32); | ||
140 | data.Add("PathEnd", DbType.Int32); | ||
141 | data.Add("PathScaleX", DbType.Int32); | ||
142 | data.Add("PathScaleY", DbType.Int32); | ||
143 | data.Add("PathShearX", DbType.Int32); | ||
144 | data.Add("PathShearY", DbType.Int32); | ||
145 | data.Add("PathSkew", DbType.Int32); | ||
146 | data.Add("PathCurve", DbType.Int32); | ||
147 | data.Add("PathRadiusOffset", DbType.Int32); | ||
148 | data.Add("PathRevolutions", DbType.Int32); | ||
149 | data.Add("PathTaperX", DbType.Int32); | ||
150 | data.Add("PathTaperY", DbType.Int32); | ||
151 | data.Add("PathTwist", DbType.Int32); | ||
152 | data.Add("PathTwistBegin", DbType.Int32); | ||
153 | // profile | ||
154 | data.Add("ProfileBegin", DbType.Int32); | ||
155 | data.Add("ProfileEnd", DbType.Int32); | ||
156 | data.Add("ProfileCurve", DbType.Int32); | ||
157 | data.Add("ProfileHollow", DbType.Int32); | ||
158 | // text TODO: this isn't right, but I'm not sure the right | ||
159 | // way to specify this as a blob atm | ||
160 | data.Add("Texture", DbType.Binary); | ||
161 | return data; | ||
162 | } | ||
163 | 98 | ||
164 | private SqliteCommand createInsertCommand(string table, Dictionary<string, DbType> defs) | 99 | private SqliteCommand createInsertCommand(string table, Dictionary<string, DbType> defs) |
165 | { | 100 | { |
@@ -640,5 +575,146 @@ namespace OpenSim.DataStore.MonoSqliteStorage | |||
640 | return textureEntry; | 575 | return textureEntry; |
641 | } | 576 | } |
642 | } | 577 | } |
578 | |||
579 | private void InitDB(SqliteConnection conn) | ||
580 | { | ||
581 | string createPrims = defineTable("prims", "UUID", createPrimDataDefs()); | ||
582 | string createShapes = defineTable("primshapes", "UUID", createShapeDataDefs()); | ||
583 | |||
584 | SqliteCommand pcmd = new SqliteCommand(createPrims, conn); | ||
585 | SqliteCommand scmd = new SqliteCommand(createShapes, conn); | ||
586 | conn.Open(); | ||
587 | pcmd.ExecuteNonQuery(); | ||
588 | scmd.ExecuteNonQuery(); | ||
589 | conn.Close(); | ||
590 | } | ||
591 | |||
592 | private string defineTable(string name, string primkey, Dictionary<string, DbType> cols) | ||
593 | { | ||
594 | string sql = "create table " + name + "("; | ||
595 | string subsql = ""; | ||
596 | foreach (string key in cols.Keys) | ||
597 | { | ||
598 | if (subsql.Length > 0) | ||
599 | { // a map function would rock so much here | ||
600 | subsql += ",\n"; | ||
601 | } | ||
602 | subsql += key + " " + sqliteType(cols[key]); | ||
603 | if(key == primkey) | ||
604 | { | ||
605 | subsql += " primary key"; | ||
606 | } | ||
607 | } | ||
608 | sql += subsql; | ||
609 | sql += ")"; | ||
610 | return sql; | ||
611 | } | ||
612 | |||
613 | private string sqliteType(DbType type) | ||
614 | { | ||
615 | switch(type) { | ||
616 | case DbType.String: | ||
617 | return "varchar(255)"; | ||
618 | |||
619 | case DbType.Int32: | ||
620 | return "integer"; | ||
621 | |||
622 | case DbType.Double: | ||
623 | return "float"; | ||
624 | |||
625 | case DbType.Binary: | ||
626 | return "blob"; | ||
627 | |||
628 | default: | ||
629 | return "varchar(255)"; | ||
630 | } | ||
631 | } | ||
632 | |||
633 | /// Methods after this point are big data definition | ||
634 | /// methods, and aren't really interesting unless you are | ||
635 | /// adjusting the schema. | ||
636 | private Dictionary<string, DbType> createPrimDataDefs() | ||
637 | { | ||
638 | Dictionary<string, DbType> data = new Dictionary<string, DbType>(); | ||
639 | data.Add("UUID", DbType.String); | ||
640 | data.Add("ParentID", DbType.Int32); | ||
641 | data.Add("CreationDate", DbType.Int32); | ||
642 | data.Add("Name", DbType.String); | ||
643 | data.Add("SceneGroupID", DbType.String); | ||
644 | // various text fields | ||
645 | data.Add("Text", DbType.String); | ||
646 | data.Add("Description", DbType.String); | ||
647 | data.Add("SitName", DbType.String); | ||
648 | data.Add("TouchName", DbType.String); | ||
649 | // permissions | ||
650 | data.Add("CreatorID", DbType.String); | ||
651 | data.Add("OwnerID", DbType.String); | ||
652 | data.Add("GroupID", DbType.String); | ||
653 | data.Add("LastOwnerID", DbType.String); | ||
654 | data.Add("OwnerMask", DbType.Int32); | ||
655 | data.Add("NextOwnerMask", DbType.Int32); | ||
656 | data.Add("GroupMask", DbType.Int32); | ||
657 | data.Add("EveryoneMask", DbType.Int32); | ||
658 | data.Add("BaseMask", DbType.Int32); | ||
659 | // vectors | ||
660 | data.Add("PositionX", DbType.Double); | ||
661 | data.Add("PositionY", DbType.Double); | ||
662 | data.Add("PositionZ", DbType.Double); | ||
663 | data.Add("GroupPositionX", DbType.Double); | ||
664 | data.Add("GroupPositionY", DbType.Double); | ||
665 | data.Add("GroupPositionZ", DbType.Double); | ||
666 | data.Add("VelocityX", DbType.Double); | ||
667 | data.Add("VelocityY", DbType.Double); | ||
668 | data.Add("VelocityZ", DbType.Double); | ||
669 | data.Add("AngularVelocityX", DbType.Double); | ||
670 | data.Add("AngularVelocityY", DbType.Double); | ||
671 | data.Add("AngularVelocityZ", DbType.Double); | ||
672 | data.Add("AccelerationX", DbType.Double); | ||
673 | data.Add("AccelerationY", DbType.Double); | ||
674 | data.Add("AccelerationZ", DbType.Double); | ||
675 | // quaternions | ||
676 | data.Add("RotationX", DbType.Double); | ||
677 | data.Add("RotationY", DbType.Double); | ||
678 | data.Add("RotationZ", DbType.Double); | ||
679 | data.Add("RotationW", DbType.Double); | ||
680 | return data; | ||
681 | } | ||
682 | |||
683 | private Dictionary<string, DbType> createShapeDataDefs() | ||
684 | { | ||
685 | Dictionary<string, DbType> data = new Dictionary<string, DbType>(); | ||
686 | data.Add("UUID", DbType.String); | ||
687 | // shape is an enum | ||
688 | data.Add("Shape", DbType.Int32); | ||
689 | // vectors | ||
690 | data.Add("ScaleX", DbType.Double); | ||
691 | data.Add("ScaleY", DbType.Double); | ||
692 | data.Add("ScaleZ", DbType.Double); | ||
693 | // paths | ||
694 | data.Add("PCode", DbType.Int32); | ||
695 | data.Add("PathBegin", DbType.Int32); | ||
696 | data.Add("PathEnd", DbType.Int32); | ||
697 | data.Add("PathScaleX", DbType.Int32); | ||
698 | data.Add("PathScaleY", DbType.Int32); | ||
699 | data.Add("PathShearX", DbType.Int32); | ||
700 | data.Add("PathShearY", DbType.Int32); | ||
701 | data.Add("PathSkew", DbType.Int32); | ||
702 | data.Add("PathCurve", DbType.Int32); | ||
703 | data.Add("PathRadiusOffset", DbType.Int32); | ||
704 | data.Add("PathRevolutions", DbType.Int32); | ||
705 | data.Add("PathTaperX", DbType.Int32); | ||
706 | data.Add("PathTaperY", DbType.Int32); | ||
707 | data.Add("PathTwist", DbType.Int32); | ||
708 | data.Add("PathTwistBegin", DbType.Int32); | ||
709 | // profile | ||
710 | data.Add("ProfileBegin", DbType.Int32); | ||
711 | data.Add("ProfileEnd", DbType.Int32); | ||
712 | data.Add("ProfileCurve", DbType.Int32); | ||
713 | data.Add("ProfileHollow", DbType.Int32); | ||
714 | // text TODO: this isn't right, but I'm not sure the right | ||
715 | // way to specify this as a blob atm | ||
716 | data.Add("Texture", DbType.Binary); | ||
717 | return data; | ||
718 | } | ||
643 | } | 719 | } |
644 | } | 720 | } |