Пример #1
0
        void IProviderExtend.CreateTable(MetaTable metaTable)
        {
            //var metaTable = services.Model.GetTable(metaTable);
            var sqlBuilder = new OracleSqlBuilder(this);
            var commands   = sqlBuilder.GetCreateTableCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
Пример #2
0
        public void CreateDatabase()
        {
            if (DatabaseExists())
            {
                throw SqlClient.Error.CreateDatabaseFailedBecauseSqlCEDatabaseAlreadyExists(dbName);
            }
            if (string.IsNullOrEmpty(dbName))
            {
                throw Error.ArgumentNull("Database Name");
            }

            var conn = conManager.UseConnection(this);



            var transaction      = conn.BeginTransaction();
            var OracleSqlBuilder = new OracleSqlBuilder(this);

            try
            {
                Execute(conn, transaction, OracleSqlBuilder.GetCreateDatabaseCommand(dbName, passowrd));
                var commandText = "GRANT DBA TO " + dbName;
                Execute(conn, transaction, commandText);
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                conManager.ReleaseConnection(this);
            }

            var str = string.Format("Data Source={0};User ID={1};Password={2}", conn.DataSource, dbName, passowrd);
            var oracleConnection = new OracleConnection(str);

            oracleConnection.Open();
            var oracleTransaction = oracleConnection.BeginTransaction();

            //var OracleSqlBuilder = new OracleSqlBuilder(this);
            try
            {
                MetaModel model = services.Model;
                foreach (MetaTable table in model.GetTables())
                {
                    var commands = OracleSqlBuilder.GetCreateTableCommands(table);
                    foreach (var command in commands)
                    {
                        Execute(oracleConnection, oracleTransaction, command);
                    }
                }

                foreach (MetaTable table in model.GetTables())
                {
                    foreach (string commandText in OracleSqlBuilder.GetCreateForeignKeyCommands(table))
                    {
                        if (!string.IsNullOrEmpty(commandText))
                        {
                            Execute(oracleConnection, oracleTransaction, commandText);
                        }
                    }
                }

                oracleTransaction.Commit();
            }
            catch
            {
                oracleTransaction.Rollback();
                throw;
            }
            finally
            {
                conManager.ReleaseConnection(this);
            }
        }