private void ExecuteDeleteOnTables(string strDbPathFile, string[] tables = null, string[] exceptions = null)
        {
            using (var conn = new OleDbConnection(m_ado.getMDBConnString(strDbPathFile, "", "")))
            {
                conn.Open();

                string[] strTables = tables;
                if (tables == null || tables.Length == 0)
                {
                    strTables = m_ado.getTableNamesOfSpecificTypes(conn);
                    //In case none of the tables are valid
                    if (strTables.Length == 1 && strTables[0] == "")
                    {
                        return;
                    }
                }

                string column;
                foreach (string table in strTables)
                {
                    if (exceptions != null && exceptions.Contains(table))
                    {
                        continue;
                    }

                    column = null;
                    foreach (string col in m_dictIdentityColumnsToValues.Keys)
                    {
                        if (m_ado.ColumnExist(conn, table, col))
                        {
                            column = col;
                            break;
                        }
                    }

                    if (!String.IsNullOrEmpty(column) && m_dictIdentityColumnsToValues[column].Count > 0)
                    {
                        m_ado.AddIndex(conn, table, column + "_delete_idx", column);
                        if (frmMain.g_bDebug)
                        {
//                            var message = Checked(chkDeletesDisabled)
//                                ? "\r\nCounting records to delete from " + strDbPathFile + " " + table + " using " + column + "\r\n"
//                                : "\r\nDeleting from " + strDbPathFile + " " + table + " using " + column + "\r\n";
                            frmMain.g_oUtils.WriteText(m_strDebugFile, Checked(chkDeletesDisabled)
                                ? "\r\nCounting records to delete from " + strDbPathFile + " " + table + " using " + column + "\r\n"
                                : "\r\nDeleting from " + strDbPathFile + " " + table + " using " + column + "\r\n");
                        }

                        int deletedRecords = BuildAndExecuteDeleteSQLStmts(conn, table, column);
                        AddDeletedCountToDictionary(strDbPathFile, table, deletedRecords);
                        m_ado.SqlNonQuery(conn, String.Format("DROP INDEX {0} ON {1}", column + "_delete_idx", table));
                    }
                }
            }
            if (Checked(chkCompactMDB))
            {
                m_dao.CompactMDB(strDbPathFile);
            }
        }
Beispiel #2
0
        private void ExecuteDeleteOnTables(string strDbPathFile, string[] tables = null, string[] exceptions = null)
        {
            using (var conn = new OleDbConnection(m_ado.getMDBConnString(strDbPathFile, "", "")))
            {
                conn.Open();

                string[] strTables = tables;
                if (tables == null || tables.Length == 0)
                {
                    strTables = m_ado.getTableNamesOfSpecificTypes(conn).Where(s => !(s.Contains("~") || s.Contains(" "))).ToArray();
                    //In case none of the tables are valid
                    if (strTables.Length == 1 && strTables[0] == "")
                    {
                        return;
                    }
                }

                string column;
                foreach (string table in strTables)
                {
                    if (exceptions != null && exceptions.Contains(table))
                    {
                        continue;
                    }

                    column = null;
                    foreach (string col in new string[] { "rxpackage" })
                    {
                        if (m_ado.ColumnExist(conn, table, col))
                        {
                            column = col;
                            break;
                        }
                    }

                    if (!String.IsNullOrEmpty(column))
                    {
                        var strTempIndex = column + "_delete_idx";
                        if (!m_dao.IndexExists(strDbPathFile, table, strTempIndex))
                        {
                            m_ado.AddIndex(conn, table, strTempIndex, column);
                        }

                        if (frmMain.g_bDebug)
                        {
                            frmMain.g_oUtils.WriteText(m_strDebugFile, Checked(chkDeletesDisabled)
                                ? "\r\nCounting records to delete from " + strDbPathFile + " " + table + " using " + column + "\r\n"
                                : "\r\nDeleting from " + strDbPathFile + " " + table + " using " + column + "\r\n");
                        }

                        int deletedRecords = BuildAndExecuteDeleteSQLStmts(conn, table, column);
                        if (deletedRecords > 0)
                        {
                            AddDeletedCountToDictionary(strDbPathFile, table, deletedRecords);
                        }
                        m_ado.SqlNonQuery(conn, String.Format("DROP INDEX {0} ON {1}", strTempIndex, table));
                    }
                }
            }
            if (Checked(chkCompactMDB))
            {
                m_dao.CompactMDB(strDbPathFile);
            }
        }