31 using Community.CsharpSqlite.Sqlite;
33 using Mono.Data.Sqlite;
36 namespace OpenSim.Data.SQLite
57 public static void createCol(DataTable dt,
string name, Type type)
59 DataColumn col =
new DataColumn(name, type);
91 string[] cols =
new string[dt.Columns.Count];
92 for (
int i = 0; i < dt.Columns.Count; i++)
94 DataColumn col = dt.Columns[i];
95 cols[i] = col.ColumnName;
98 string sql =
"insert into " + table +
"(";
99 sql += String.Join(
", ", cols);
101 sql +=
") values (:";
102 sql += String.Join(
", :", cols);
104 SqliteCommand cmd =
new SqliteCommand(sql);
108 foreach (DataColumn col
in dt.Columns)
110 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
124 string sql =
"update " + table +
" set ";
125 string subsql = String.Empty;
126 foreach (DataColumn col
in dt.Columns)
128 if (subsql.Length > 0)
133 subsql += col.ColumnName +
"= :" + col.ColumnName;
136 sql +=
" where " + pk;
137 SqliteCommand cmd =
new SqliteCommand(sql);
142 foreach (DataColumn col
in dt.Columns)
144 cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
156 string sql =
"create table " + dt.TableName +
"(";
157 string subsql = String.Empty;
158 foreach (DataColumn col
in dt.Columns)
160 if (subsql.Length > 0)
165 subsql += col.ColumnName +
" " + sqliteType(col.DataType);
166 if (dt.PrimaryKey.Length > 0)
168 if (col == dt.PrimaryKey[0])
170 subsql +=
" primary key";
207 SqliteParameter param =
new SqliteParameter();
208 param.ParameterName =
":" + name;
209 param.DbType = dbtypeFromType(type);
210 param.SourceColumn = name;
211 param.SourceVersion = DataRowVersion.Current;
228 if (type == typeof (String))
230 return DbType.String;
232 else if (type == typeof (Int32))
236 else if (type == typeof (UInt32))
238 return DbType.UInt32;
240 else if (type == typeof (Int64))
244 else if (type == typeof (UInt64))
246 return DbType.UInt64;
248 else if (type == typeof (Double))
250 return DbType.Double;
252 else if (type == typeof (Boolean))
254 return DbType.Boolean;
256 else if (type == typeof (Byte[]))
258 return DbType.Binary;
262 return DbType.String;
273 if (type == typeof (String))
275 return "varchar(255)";
277 else if (type == typeof (Int32))
281 else if (type == typeof (UInt32))
285 else if (type == typeof (Int64))
287 return "varchar(255)";
289 else if (type == typeof (UInt64))
291 return "varchar(255)";
293 else if (type == typeof (Double))
297 else if (type == typeof (Boolean))
301 else if (type == typeof (Byte[]))
static SqliteCommand createInsertCommand(string table, DataTable dt)
Create an insert command
static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
create an update command
A base class for methods needed by all SQLite database classes
static string sqliteType(Type type)
static string defineTable(DataTable dt)
static SqliteParameter createSqliteParameter(string name, Type type)
static void createCol(DataTable dt, string name, Type type)
static DbType dbtypeFromType(Type type)
Type conversion function