예제 #1
0
        /// <summary>
        /// Adds fields to table.
        /// </summary>
        /// <param name="tableDefinition">Table definition.</param>
        /// <param name="tableDescription">Table Description.</param>
        /// <param name="columns">Database columns.</param>
        private void _AddFieldsToTable(ITableDefinition tableDefinition,
                                       TableDescription tableDescription,
                                       ADOX.Columns columns)
        {
            Debug.Assert(null != tableDefinition);
            Debug.Assert(null != tableDescription);
            Debug.Assert(null != columns);

            ICollection <string> fields = tableDefinition.Fields;

            foreach (string field in fields)
            {
                FieldInfo info = tableDescription.GetFieldInfo(field);
                Debug.Assert(null != info);
                columns.Append(info.Name, _ConvertType(info.Type), info.Size);

                // make field not required
                ADOX.Column column = columns[info.Name];
                column.Attributes = ADOX.ColumnAttributesEnum.adColNullable;
            }
        }
예제 #2
0
        private void LoadExtraDataForTable()
        {
            try
            {
                if (this._array.Count > 0)
                {
                    ADODB.Connection cnn = new ADODB.Connection();
                    ADOX.Catalog     cat = new ADOX.Catalog();

                    // Open the Connection
                    cnn.Open(dbRoot.ConnectionString, null, null, 0);
                    cat.ActiveConnection = cnn;

                    ADOX.Columns cols = null;
                    cols = cat.Tables[this.Table.Name].Columns;

                    Column col = this._array[0] as Column;

                    f_TypeName = new DataColumn("TYPE_NAME", typeof(string));
                    col._row.Table.Columns.Add(f_TypeName);

                    f_IsAutoKey = new DataColumn("AUTO_INCREMENT", typeof(Boolean));
                    col._row.Table.Columns.Add(f_IsAutoKey);

                    f_AutoKeySeed = new DataColumn("AUTO_KEY_SEED", typeof(System.Int32));
                    col._row.Table.Columns.Add(f_AutoKeySeed);

                    f_AutoKeyIncrement = new DataColumn("AUTO_KEY_INCREMENT", typeof(System.Int32));
                    col._row.Table.Columns.Add(f_AutoKeyIncrement);

                    int         count = this._array.Count;
                    Column      c     = null;
                    ADOX.Column cx    = null;

                    for (int index = 0; index < count; index++)
                    {
                        cx = cols[index];
                        c  = (Column)this[cx.Name];

                        string hyperlink = "False";

                        try
                        {
                            hyperlink = cx.Properties["Jet OLEDB:Hyperlink"].Value.ToString();
                        }
                        catch {}

                        string name = cx.Name;

                        Console.WriteLine("-----------------------------------------");
                        foreach (ADOX.Property prop in cx.Properties)
                        {
                            Console.WriteLine(prop.Attributes.ToString());
                            Console.WriteLine(prop.Name);
                            if (null != prop.Value)
                            {
                                Console.WriteLine(prop.Value.ToString());
                            }
                        }

                        c._row["TYPE_NAME"] = hyperlink == "False" ? cx.Type.ToString() : "Hyperlink";

                        try
                        {
                            if (c.Default == "GenGUID()")
                            {
                                c._row["AUTO_INCREMENT"] = Convert.ToBoolean(cx.Properties["Jet OLEDB:AutoGenerate"].Value);
                            }
                            else
                            {
                                c._row["AUTO_INCREMENT"]     = Convert.ToBoolean(cx.Properties["Autoincrement"].Value);
                                c._row["AUTO_KEY_SEED"]      = Convert.ToInt32(cx.Properties["Seed"].Value);
                                c._row["AUTO_KEY_INCREMENT"] = Convert.ToInt32(cx.Properties["Increment"].Value);
                            }
                        }
                        catch {}
                    }

                    cnn.Close();
                }
            }
            catch {}
        }
예제 #3
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);
        }