Exemplo n.º 1
0
        private static IList <string> GetTablePrimaryKeys(Database db, string table)
        {
            if (table == "_Tables")
            {
                return(new string[] { "Name" });
            }
            else if (table == "_Columns")
            {
                return(new string[] { "Table", "Number" });
            }
            else if (table == "_Storages")
            {
                return(new string[] { "Name" });
            }
            else if (table == "_Streams")
            {
                return(new string[] { "Name" });
            }
            else
            {
                int  hrec;
                uint ret = RemotableNativeMethods.MsiDatabaseGetPrimaryKeys(
                    (int)db.Handle, table, out hrec);
                if (ret != 0)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }

                using (Record rec = new Record((IntPtr)hrec, true, null))
                {
                    string[] keys = new string[rec.FieldCount];
                    for (int i = 0; i < keys.Length; i++)
                    {
                        keys[i] = rec.GetString(i + 1);
                    }

                    return(keys);
                }
            }
        }