Ejemplo n.º 1
0
        public virtual IEnumerable <string> Run(ICreateTableCommand command)
        {
            // TODO: Support CreateForeignKeyCommand in a CREATE TABLE (in sqlite they can only be created with the table)

            var builder = new StringBuilder();

            builder.Append(_dialect.CreateTableString)
            .Append(' ')
            .Append(_dialect.QuoteForTableName(command.Name))
            .Append(" (");

            var appendComma = false;

            foreach (var createColumn in command.TableCommands.OfType <CreateColumnCommand>())
            {
                if (appendComma)
                {
                    builder.Append(", ");
                }
                appendComma = true;

                Run(builder, createColumn);
            }

            // We only create PK statements on columns that don't have IsIdentity since IsIdentity statements also contains the notion of primary key.

            var primaryKeys = command.TableCommands.OfType <CreateColumnCommand>().Where(ccc => ccc.IsPrimaryKey && !ccc.IsIdentity).Select(ccc => _dialect.QuoteForColumnName(ccc.ColumnName)).ToArray();

            if (primaryKeys.Any())
            {
                if (appendComma)
                {
                    builder.Append(", ");
                }

                builder.Append(_dialect.PrimaryKeyString)
                .Append(" ( ")
                .Append(String.Join(", ", primaryKeys.ToArray()))
                .Append(" )");
            }

            builder.Append(" )");
            yield return(builder.ToString());
        }
Ejemplo n.º 2
0
 private void AddIndexColumns(ICreateTableCommand table, List <ContentFieldDefinition> fieldDefinitions)
 {
     foreach (var fieldDefinition in fieldDefinitions)
     {
         if (fieldDefinition.Type == ContentFieldTypes.TextField || fieldDefinition.Type == ContentFieldTypes.ContentPickerField)
         {
             table.Column <string>(fieldDefinition.Name);
         }
         else if (fieldDefinition.Type == ContentFieldTypes.NumericField)
         {
             table.Column <int>(fieldDefinition.Name);
         }
         else if (fieldDefinition.Type == ContentFieldTypes.BooleanField)
         {
             table.Column <bool>(fieldDefinition.Name);
         }
         else if (fieldDefinition.Type == ContentFieldTypes.DateField || fieldDefinition.Type == ContentFieldTypes.DateField)
         {
             table.Column <DateTime>(fieldDefinition.Name);
         }
     }
 }