diff options
author | Jeff Ames | 2008-06-26 20:14:33 +0000 |
---|---|---|
committer | Jeff Ames | 2008-06-26 20:14:33 +0000 |
commit | 9fae975a53fbb852dfbaf811dca259ddd4f74f4c (patch) | |
tree | 7273987bd5c30c4fabca6fa68b43ce25304a703a /OpenSim/Data/SQLite/SQLiteUtils.cs | |
parent | Update svn properties. Minor formatting cleanup. (diff) | |
download | opensim-SC_OLD-9fae975a53fbb852dfbaf811dca259ddd4f74f4c.zip opensim-SC_OLD-9fae975a53fbb852dfbaf811dca259ddd4f74f4c.tar.gz opensim-SC_OLD-9fae975a53fbb852dfbaf811dca259ddd4f74f4c.tar.bz2 opensim-SC_OLD-9fae975a53fbb852dfbaf811dca259ddd4f74f4c.tar.xz |
Apply patch from bug #1605 -- Documentation for Data/SQLite. Thanks kerunix_Flan!
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteUtils.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteUtils.cs | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteUtils.cs b/OpenSim/Data/SQLite/SQLiteUtils.cs index 0862de0..18bb137 100644 --- a/OpenSim/Data/SQLite/SQLiteUtils.cs +++ b/OpenSim/Data/SQLite/SQLiteUtils.cs | |||
@@ -44,6 +44,12 @@ namespace OpenSim.Data.SQLite | |||
44 | * | 44 | * |
45 | **********************************************************************/ | 45 | **********************************************************************/ |
46 | 46 | ||
47 | /// <summary> | ||
48 | /// | ||
49 | /// </summary> | ||
50 | /// <param name="dt"></param> | ||
51 | /// <param name="name"></param> | ||
52 | /// <param name="type"></param> | ||
47 | public static void createCol(DataTable dt, string name, Type type) | 53 | public static void createCol(DataTable dt, string name, Type type) |
48 | { | 54 | { |
49 | DataColumn col = new DataColumn(name, type); | 55 | DataColumn col = new DataColumn(name, type); |
@@ -60,17 +66,24 @@ namespace OpenSim.Data.SQLite | |||
60 | * | 66 | * |
61 | **********************************************************************/ | 67 | **********************************************************************/ |
62 | 68 | ||
69 | /// <summary> | ||
70 | /// Create an insert command | ||
71 | /// </summary> | ||
72 | /// <param name="table">table name</param> | ||
73 | /// <param name="dt">data table</param> | ||
74 | /// <returns>the created command</returns> | ||
75 | /// <remarks> | ||
76 | /// This is subtle enough to deserve some commentary. | ||
77 | /// Instead of doing *lots* and *lots of hardcoded strings | ||
78 | /// for database definitions we'll use the fact that | ||
79 | /// realistically all insert statements look like "insert | ||
80 | /// into A(b, c) values(:b, :c) on the parameterized query | ||
81 | /// front. If we just have a list of b, c, etc... we can | ||
82 | /// generate these strings instead of typing them out. | ||
83 | /// </remarks> | ||
63 | public static SqliteCommand createInsertCommand(string table, DataTable dt) | 84 | public static SqliteCommand createInsertCommand(string table, DataTable dt) |
64 | { | 85 | { |
65 | /** | 86 | |
66 | * This is subtle enough to deserve some commentary. | ||
67 | * Instead of doing *lots* and *lots of hardcoded strings | ||
68 | * for database definitions we'll use the fact that | ||
69 | * realistically all insert statements look like "insert | ||
70 | * into A(b, c) values(:b, :c) on the parameterized query | ||
71 | * front. If we just have a list of b, c, etc... we can | ||
72 | * generate these strings instead of typing them out. | ||
73 | */ | ||
74 | string[] cols = new string[dt.Columns.Count]; | 87 | string[] cols = new string[dt.Columns.Count]; |
75 | for (int i = 0; i < dt.Columns.Count; i++) | 88 | for (int i = 0; i < dt.Columns.Count; i++) |
76 | { | 89 | { |
@@ -95,6 +108,13 @@ namespace OpenSim.Data.SQLite | |||
95 | return cmd; | 108 | return cmd; |
96 | } | 109 | } |
97 | 110 | ||
111 | /// <summary> | ||
112 | /// create an update command | ||
113 | /// </summary> | ||
114 | /// <param name="table">table name</param> | ||
115 | /// <param name="pk"></param> | ||
116 | /// <param name="dt"></param> | ||
117 | /// <returns>the created command</returns> | ||
98 | public static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt) | 118 | public static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt) |
99 | { | 119 | { |
100 | string sql = "update " + table + " set "; | 120 | string sql = "update " + table + " set "; |
@@ -122,7 +142,11 @@ namespace OpenSim.Data.SQLite | |||
122 | return cmd; | 142 | return cmd; |
123 | } | 143 | } |
124 | 144 | ||
125 | 145 | /// <summary> | |
146 | /// | ||
147 | /// </summary> | ||
148 | /// <param name="dt">Data Table</param> | ||
149 | /// <returns></returns> | ||
126 | public static string defineTable(DataTable dt) | 150 | public static string defineTable(DataTable dt) |
127 | { | 151 | { |
128 | string sql = "create table " + dt.TableName + "("; | 152 | string sql = "create table " + dt.TableName + "("; |
@@ -158,15 +182,21 @@ namespace OpenSim.Data.SQLite | |||
158 | **********************************************************************/ | 182 | **********************************************************************/ |
159 | 183 | ||
160 | ///<summary> | 184 | ///<summary> |
185 | /// <para> | ||
161 | /// This is a convenience function that collapses 5 repetitive | 186 | /// This is a convenience function that collapses 5 repetitive |
162 | /// lines for defining SqliteParameters to 2 parameters: | 187 | /// lines for defining SqliteParameters to 2 parameters: |
163 | /// column name and database type. | 188 | /// column name and database type. |
164 | /// | 189 | /// </para> |
190 | /// | ||
191 | /// <para> | ||
165 | /// It assumes certain conventions like :param as the param | 192 | /// It assumes certain conventions like :param as the param |
166 | /// name to replace in parametrized queries, and that source | 193 | /// name to replace in parametrized queries, and that source |
167 | /// version is always current version, both of which are fine | 194 | /// version is always current version, both of which are fine |
168 | /// for us. | 195 | /// for us. |
196 | /// </para> | ||
169 | ///</summary> | 197 | ///</summary> |
198 | /// <param name="name"></param> | ||
199 | /// <param name="type"></param> | ||
170 | ///<returns>a built sqlite parameter</returns> | 200 | ///<returns>a built sqlite parameter</returns> |
171 | public static SqliteParameter createSqliteParameter(string name, Type type) | 201 | public static SqliteParameter createSqliteParameter(string name, Type type) |
172 | { | 202 | { |
@@ -184,6 +214,11 @@ namespace OpenSim.Data.SQLite | |||
184 | * | 214 | * |
185 | **********************************************************************/ | 215 | **********************************************************************/ |
186 | 216 | ||
217 | /// <summary> | ||
218 | /// Type conversion function | ||
219 | /// </summary> | ||
220 | /// <param name="type">a type</param> | ||
221 | /// <returns>a DbType</returns> | ||
187 | public static DbType dbtypeFromType(Type type) | 222 | public static DbType dbtypeFromType(Type type) |
188 | { | 223 | { |
189 | if (type == typeof (String)) | 224 | if (type == typeof (String)) |
@@ -224,8 +259,11 @@ namespace OpenSim.Data.SQLite | |||
224 | } | 259 | } |
225 | } | 260 | } |
226 | 261 | ||
227 | // this is something we'll need to implement for each db | 262 | /// <summary> |
228 | // slightly differently. | 263 | /// </summary> |
264 | /// <param name="type">a Type</param> | ||
265 | /// <returns>a string</returns> | ||
266 | /// <remarks>this is something we'll need to implement for each db slightly differently.</remarks> | ||
229 | public static string sqliteType(Type type) | 267 | public static string sqliteType(Type type) |
230 | { | 268 | { |
231 | if (type == typeof (String)) | 269 | if (type == typeof (String)) |