public static string KeysValue(this DataSet.Define define) { string result; if (KeysValueCache.TryGetValue(define, out result)) { return(result); } StringBuilder builder = new StringBuilder(); for (int i = 0; i < define.Keys.Count; ++i) { builder.AppendFormat(i == 0 ? "@{0}" : ", @{0}", i); DataSet.Type type = define.Keys[i]; if (type == DataSet.Type.String || type == DataSet.Type.Blob) { builder.Append(", ?"); } } result = builder.ToString(); try { KeysValueCache.Add(define, result); } catch (Exception) { } return(result); }
public static string Where(this DataSet.Define define) { string result; if (WhereCache.TryGetValue(define, out result)) { return(result); } StringBuilder builder = new StringBuilder(); builder.Append(" WHERE 1 = 1"); for (int i = 0; i < define.Keys.Count; ++i) { builder.AppendFormat(" AND Key{0} = @{0}", i); DataSet.Type type = define.Keys[i]; if (type == DataSet.Type.String || type == DataSet.Type.Blob) { builder.AppendFormat(" AND RealKey{0} = ?", i); } } result = builder.ToString(); try { WhereCache.Add(define, result); } catch (Exception) { } return(result); }
public static string CreateTable(this DataSet.Define define, IDictionary <DataSet.Type, string> datatypenames) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("CREATE TABLE '{0}' (", define.Name); for (int i = 0; i < define.Keys.Count; ++i) { DataSet.Type type = define.Keys[i]; switch (type) { case DataSet.Type.String: case DataSet.Type.Blob: builder.AppendFormat(i == 0 ? "Key{0} {1} NOT NULL" : ", Key{0} {1} NOT NULL", i, datatypenames[DataSet.Type.Integer]); builder.AppendFormat(", RealKey{0} {1} NOT NULL", i, datatypenames[type]); break; case DataSet.Type.Bool: builder.AppendFormat(i == 0 ? "Key{0} {1} NOT NULL" : ", Key{0} {1} NOT NULL", i, datatypenames[DataSet.Type.Integer]); break; default: builder.AppendFormat(i == 0 ? "Key{0} {1} NOT NULL" : ", Key{0} {1} NOT NULL", i, datatypenames[type]); break; } } foreach (var column in define.Columns) { builder.AppendFormat(", _{0}_ {1}", column.Key, datatypenames[column.Value]); } builder.AppendFormat(");CREATE INDEX '{0}#Index' ON '{0}' (", define.Name); for (int i = 0; i < define.Keys.Count; ++i) { builder.AppendFormat(i == 0 ? "Key{0}" : ", Key{0}", i); } builder.Append(");"); return(builder.ToString()); }
private static DataSet.Type SelectType(Type type) { DataSet.Type datatype = DataSet.Type.Blob; switch (Type.GetTypeCode(type)) { case TypeCode.Boolean: datatype = DataSet.Type.Bool; break; case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: datatype = DataSet.Type.Integer; break; case TypeCode.Int64: case TypeCode.UInt64: datatype = DataSet.Type.Long; break; case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: datatype = DataSet.Type.Double; break; case TypeCode.Char: case TypeCode.String: datatype = DataSet.Type.String; break; } return(datatype); }
public ColumnAttribute(string name, DataSet.Type type) { Name = name; Auto = false; Type = type; }
public ColumnAttribute(DataSet.Type type) { Auto = true; Type = type; }
public KeyAttribute(uint index, DataSet.Type type) { Index = index; Type = type; }