public static void CreateIndex(FieldInfo fi, SoodaTransaction transaction) { SqlDataSource ds = (SqlDataSource)transaction.OpenDataSource(fi.ParentClass.GetDataSource()); StringWriter sw = new StringWriter(); ds.SqlBuilder.GenerateIndex(sw, fi, null, ""); ds.ExecuteNonQuery(sw.ToString()); }
public static void Add(FieldInfo fi, SoodaTransaction transaction) { ClassInfo ci = fi.ParentClass; fi.ResolveReferences(ci.Schema); SqlDataSource ds = (SqlDataSource)transaction.OpenDataSource(ci.GetDataSource()); LockCookie lockCookie = LockWrite(transaction); try { TableInfo table = Prepare(fi); fi.Table = table; StringWriter sw = new StringWriter(); sw.Write("insert into SoodaDynamicField (class, field, type, nullable, fieldsize, precision) values ({0}, {1}, {2}, {3}, {4}, {5})"); ds.ExecuteNonQuery(sw.ToString(), ci.Name, fi.Name, fi.TypeName, fi.IsNullable ? 1 : 0, NegativeToNull(fi.Size), NegativeToNull(fi.Precision)); sw = new StringWriter(); ds.SqlBuilder.GenerateCreateTable(sw, table, null, ""); ds.ExecuteNonQuery(sw.ToString()); sw = new StringWriter(); ds.SqlBuilder.GeneratePrimaryKey(sw, table, null, ""); ds.ExecuteNonQuery(sw.ToString()); sw = new StringWriter(); ds.SqlBuilder.GenerateForeignKeys(sw, table, ""); string sql = sw.ToString(); if (sql.Length > 0) { ds.ExecuteNonQuery(sql); } ci.LocalTables.Add(table); Resolve(ci); } finally { transaction.Schema._rwLock.DowngradeFromWriterLock(ref lockCookie); } }