Exemplo n.º 1
0
        /// <summary>
        /// Adds keys to index of table.
        /// </summary>
        /// <param name="tableDescription">Table description.</param>
        /// <param name="tableDefinition">Table definition.</param>
        /// <param name="indexes">Database indexes.</param>
        private void _AddKeysToTableIndex(TableDescription tableDescription,
                                          ITableDefinition tableDefinition,
                                          ADOX.Indexes indexes)
        {
            ICollection <TableInfo> patternTables = _structureKeeper.GetPattern(ExportType.Access);

            foreach (TableInfo tableInfo in patternTables)
            {
                if (tableInfo.Type != tableDefinition.Type)
                {
                    continue; // skip
                }
                foreach (TableIndex indexDefinition in tableInfo.Indexes)
                {
                    if (_IsIndexFieldSelected(indexDefinition.FieldNames, tableDefinition.Fields))
                    {
                        _AddKeyToTableIndex(tableDescription, indexDefinition, indexes);
                    }
                }

                break; // process done
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds key to index of table.
        /// </summary>
        /// <param name="tableDescription">Table description.</param>
        /// <param name="indexDefinition">Index definition.</param>
        /// <param name="indexes">Database indexes.</param>
        private void _AddKeyToTableIndex(TableDescription tableDescription,
                                         TableIndex indexDefinition,
                                         ADOX.Indexes indexes)
        {
            Debug.Assert(null != tableDescription);
            Debug.Assert(null != indexDefinition);
            Debug.Assert(null != indexes);

            var index = new ADOX.Index();

            ADOX.Columns columns = index.Columns;
            switch (indexDefinition.Type)
            {
            case TableIndexType.Primary:
            case TableIndexType.Simple:
            {
                string field = indexDefinition.FieldNames[0];
                if (TableIndexType.Primary == indexDefinition.Type)
                {
                    index.Name       = INDEX_PRIMARY_KEY;
                    index.PrimaryKey = true;
                    index.Unique     = true;
                }
                else     // simple
                {
                    index.Name = field;
                }

                FieldInfo info = tableDescription.GetFieldInfo(field);
                Debug.Assert(null != info);
                columns.Append(info.Name, _ConvertType(info.Type), info.Size);
                break;
            }

            case TableIndexType.Multiple:
            {
                var sbKeyName = new StringBuilder();
                foreach (string field in indexDefinition.FieldNames)
                {
                    FieldInfo info = tableDescription.GetFieldInfo(field);
                    Debug.Assert(null != info);
                    columns.Append(info.Name, _ConvertType(info.Type), info.Size);

                    if (!string.IsNullOrEmpty(sbKeyName.ToString()))
                    {
                        sbKeyName.Append(SQL_KEY_SYMBOL);
                    }
                    sbKeyName.Append(field);
                }

                index.Name = sbKeyName.ToString();
                break;
            }

            default:
            {
                Debug.Assert(false);     // NOTE: not supported
                break;
            }
            }

            index.IndexNulls = ADOX.AllowNullsEnum.adIndexNullsAllow;
            indexes.Append(index, null);
        }