Esempio n. 1
0
        public MsiRecords ExecuteQuery(string query)
        {
            ModuleProc PROC   = new ModuleProc(this.DYN_MODULE_NAME, "Method");
            MsiRecords result = new MsiRecords();

            if (_fileHandle == IntPtr.Zero)
            {
                return(result);
            }

            try
            {
                IntPtr viewHandle = IntPtr.Zero;
                IntPtr recHandle  = IntPtr.Zero;

                int hr = MsiNativeHelper.MsiDatabaseOpenView(_fileHandle, query, ref viewHandle);
                if (hr == 0)
                {
                    hr = MsiNativeHelper.MsiViewExecute(viewHandle, IntPtr.Zero);
                    if (hr == 0)
                    {
                        while ((hr = MsiNativeHelper.MsiViewFetch(viewHandle, ref recHandle)) != MsiNativeHelper.ERROR_NO_MORE_ITEMS)
                        {
                            if (recHandle != IntPtr.Zero)
                            {
                                int fields = MsiNativeHelper.MsiRecordGetFieldCount(recHandle);
                                if (fields > 0)
                                {
                                    MsiRecord record = new MsiRecord();
                                    for (int i = 1; i <= fields; i++)
                                    {
                                        int           len = 255;
                                        StringBuilder sb  = new StringBuilder(len);

                                        hr = MsiNativeHelper.MsiRecordGetString(recHandle, i, sb, ref len);
                                        if (hr == 0)
                                        {
                                            record.Add(sb.ToString());
                                        }
                                    }
                                    result.Add(record);
                                }
                                MsiNativeHelper.MsiCloseHandle(recHandle);
                            }
                        }
                    }
                }

                if (viewHandle != IntPtr.Zero)
                {
                    MsiNativeHelper.MsiCloseHandle(viewHandle);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }

            return(result);
        }
Esempio n. 2
0
        public bool Close()
        {
            ModuleProc PROC   = new ModuleProc(this.DYN_MODULE_NAME, "Close");
            bool       result = default(bool);

            try
            {
                if (_fileHandle != IntPtr.Zero)
                {
                    MsiNativeHelper.MsiCloseHandle(_fileHandle);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }

            return(result);
        }
Esempio n. 3
0
        public bool Open()
        {
            ModuleProc PROC   = new ModuleProc(this.DYN_MODULE_NAME, "Open");
            bool       result = default(bool);

            try
            {
                if (_fileHandle != IntPtr.Zero)
                {
                    return(false);
                }

                int status = MsiNativeHelper.MsiOpenDatabase(this.MsiFile, MsiNativeHelper.Persist.MSIDBOPEN_READONLY, ref _fileHandle);
                result = (_fileHandle != IntPtr.Zero);
            }
            catch (Exception ex)
            {
                Log.Exception(PROC, ex);
            }

            return(result);
        }