コード例 #1
0
        public override void InitializeRepository()
        {
            base.InitializeRepository();

            if (_InitCommands == null)
                CreateInitCommands();

            if (_Connection.State != ConnectionState.Open)
            {
                _Connection.Open();
            }

            try
            {
                foreach (ISQLExpression expression in _InitCommands)
                {
                    IDbCommand cmd = null;

                    CreateTableSQLCommand ctCommand = expression as CreateTableSQLCommand;

                    if (ctCommand != null)
                    {

                        DropTableSQLCommand delete_query = new DropTableSQLCommand(ctCommand.TagMapping, ctCommand.TableName);
                        foreach (string sql in _Dialect.RenderQueries(delete_query, _Driver))
                        {
                            try
                            {
                                _Transaction = _Connection.BeginTransaction();

                                cmd = _Driver.CreateCommand(sql, _Connection, _Transaction);

                                if (TraceSqlSwitch.Enabled)
                                {
                                    TraceHelpler.Trace(cmd, _Dialect);
                                }

                                cmd.ExecuteNonQuery();

                                _Transaction.Commit();

                            }
                            catch (Exception e)
                            {
                                _Transaction.Rollback();
                                System.Diagnostics.Trace.WriteLine(e.Message + " on:\n" + sql);
                            }
                        }

                        foreach (string sql in _Dialect.RenderQueries(ctCommand, _Driver))
                        {
                            try
                            {
                                _Transaction = _Connection.BeginTransaction();

                                cmd = _Driver.CreateCommand(sql, _Connection, _Transaction);

                                if (TraceSqlSwitch.Enabled)
                                {
                                    TraceHelpler.Trace(cmd, _Dialect);
                                }

                                cmd.ExecuteNonQuery();

                                _Transaction.Commit();
                            }
                            catch (Exception e)
                            {
                                _Transaction.Rollback();
                                System.Diagnostics.Trace.WriteLine(e.Message + " on:\n" + sql);
                            }
                        }

                    }

                    AlterTableSQLCommand atCommand = expression as AlterTableSQLCommand;

                    if (atCommand != null)
                    {

                        foreach (string sql in _Dialect.RenderQueries(atCommand, _Driver))
                        {
                            try
                            {
                                _Transaction = _Connection.BeginTransaction();

                                cmd = _Driver.CreateCommand(sql, _Connection, _Transaction);

                                if (TraceSqlSwitch.Enabled)
                                {
                                    TraceHelpler.Trace(cmd, _Dialect);
                                }

                                cmd.ExecuteNonQuery();
                                _Transaction.Commit();
                            }
                            catch (Exception e)
                            {
                                _Transaction.Rollback();
                                System.Diagnostics.Trace.WriteLine(e.Message + " on:\n" + sql);
                                // Dropping a constraint might fail during InitializeRepository if it doesn't exist
                            }
                        }
                    }
                }

            }
            finally
            {
                _Connection.Close();
            }

        }
コード例 #2
0
ファイル: DBDialect.cs プロジェクト: npenin/uss
		public virtual void Visit(DropTableSQLCommand command)
		{
            // "DROP TABLE {0} "
            //if (!string.IsNullOrEmpty(schema))
            //    _Query.Append(DROP).Append(TABLE).Append(FormatAttribute(schema + DBDialect.DOT + command.TableName)).Append(SPACE);
            //else
                _Query.Append(DROP).Append(TABLE).Append(FormatAttribute(command.TableName)).Append(SPACE);
		}