private static void UpdateAutoIncAndCandidate(VfpConnection connection, DataTable schema) { var tableNames = schema.AsEnumerable().Select(x => x.Field <string>(Index.TableName)).Distinct(); var inserts = string.Join(Environment.NewLine, tableNames.Select(x => string.Format("INSERT INTO curTables VALUES('{0}')", x)).ToArray()); var vfpCode = string.Format(Resources.IndexSchemaAutoIncCandidate, inserts); schema.AsEnumerable().ToList().ForEach(row => { row[Index.AutoInc] = false; row[Index.Candidate] = false; }); connection.ExecuteScript(vfpCode); using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT * FROM curOutput"; #if DEBUG var dt = new DataTable(); var da = new VfpDataAdapter(command); da.Fill(dt); #endif using (var reader = command.ExecuteReader()) { while (reader.Read()) { var tableName = reader.GetString(0); var fieldName = reader.GetString(1); var isAutoInc = !string.IsNullOrEmpty(fieldName); var indexName = reader.GetString(2); var rows = schema.AsEnumerable().Where(x => x.Field <string>(Index.TableName) == tableName); if (string.IsNullOrEmpty(fieldName)) { rows = rows.Where(x => x.Field <string>(Index.IndexName).ToUpper() == indexName); } else { rows = rows.Where(x => x.Field <string>(Index.FieldName).ToUpper() == fieldName); } rows.ToList().ForEach(row => { row[Index.AutoInc] = isAutoInc; row[Index.Candidate] = !isAutoInc; }); } } command.CommandText = "USE"; command.ExecuteNonQuery(); } }
private static DataTable GetProps(VfpConnection connection, DataTable schema) { var tableNames = schema.AsEnumerable().Select(x => x.Field <string>("TABLE_NAME")).Distinct(); var inserts = string.Join(Environment.NewLine, tableNames.Select(x => string.Format("INSERT INTO curViews VALUES('{0}')", x)).ToArray()); var vfpCode = string.Format(Resources.ViewProps, inserts); connection.ExecuteScript(vfpCode); using (var command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT * FROM curOutput"; var props = new DataTable(); var adapter = new VfpDataAdapter(command); adapter.Fill(props); return(props); } }