public static DbTable Create(string name, DbColumn[] columns, string className = null) { if (name == null) throw new ArgumentNullException(nameof(name)); if (columns == null) throw new ArgumentNullException(nameof(columns)); if (columns.Length == 0) throw new ArgumentOutOfRangeException(nameof(columns)); var hasPrimaryKey = false; foreach (var column in columns) { if (column.IsPrimaryKey) { hasPrimaryKey = true; break; } } var tableColumns = new List<DbColumn>(columns.Length + 1); if (!hasPrimaryKey) { tableColumns.Add(DbColumn.PrimaryKey()); } tableColumns.AddRange(columns); return new DbTable(name, tableColumns, className); }
private static void AppendColumnDefinition(StringBuilder buffer, DbColumn column) { buffer.Append('['); buffer.Append(column.Name); buffer.Append(']'); buffer.Append(' '); buffer.Append(column.Type.Name); buffer.Append(' '); buffer.Append(column.IsNullable ? @"NULL" : @"NOT NULL"); if (column.IsPrimaryKey) { buffer.Append(' '); buffer.Append(@"PRIMARY KEY AUTOINCREMENT"); } }
private static void AppendColumnParameterAssignment(StringBuilder buffer, DbColumn column) { AppendColumnName(buffer, column); buffer.Append(' '); buffer.Append('='); buffer.Append(' '); AppendParameterName(buffer, column); }
private static void AppendParameterName(StringBuilder buffer, DbColumn column) { buffer.Append(ParameterPlaceholder); buffer.Append(ParameterPrefix); AppendColumnName(buffer, column); }
private static void AppendColumnName(StringBuilder buffer, DbColumn column) { buffer.Append(column.Name); }