Esempio n. 1
0
        protected override SqlExpression GetInsertIdentityExpression(MetaDataMember member)
        {
            var exp = new SqlVariable(member.Type, typeProvider.From(member.Type),
                                      OracleSqlBuilder.GetSequenceName(member, translator.Provider.SqlIdentifier) + ".NEXTVAL", dominatingExpression);

            return(exp);
        }
Esempio n. 2
0
        void IProviderExtend.DeleteTable(MetaTable metaTable)
        {
            var OracleSqlBuilder = new OracleSqlBuilder(this);
            var commands         = OracleSqlBuilder.GetDropTableCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
Esempio n. 3
0
        void IProviderExtend.CreateForeignKeys(MetaTable metaTable)
        {
            //var metaTable = services.Model.GetTable(metaTable);
            var sqlBuilder = new OracleSqlBuilder(this);
            var commands   = sqlBuilder.GetCreateForeignKeyCommands(metaTable);

            foreach (var command in commands)
            {
                services.Context.ExecuteCommand(command);
            }
        }
Esempio n. 4
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();

            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);
            }

            DbConnectionStringBuilder builder = new OracleConnectionStringBuilder()
            {
                DataSource = conn.DataSource,
                UserID     = dbName,
                Password   = passowrd,
            };

            conn = new OracleConnection(builder.ToString());
            conn.Open();
            transaction = conn.BeginTransaction();
            try
            {
                MetaModel model = services.Model;
                foreach (MetaTable table in model.GetTables())
                {
                    //string createTableCommand = OracleSqlBuilder.GetCreateTableCommand(table);
                    //if (!string.IsNullOrEmpty(createTableCommand))
                    //    Execute(conn, transaction, createTableCommand);

                    //string createPrimaryKey = OracleSqlBuilder.GetPrimaryKeyCommand(table);
                    //if (!string.IsNullOrEmpty(createPrimaryKey))
                    //    Execute(conn, transaction, createPrimaryKey);
                    var commands = OracleSqlBuilder.GetCreateTableCommands(table);
                    foreach (var command in commands)
                    {
                        Execute(conn, transaction, command);
                    }
                }

                //创建外建
                foreach (MetaTable table in model.GetTables())
                {
                    foreach (string commandText in OracleSqlBuilder.GetCreateForeignKeyCommands(table))
                    {
                        if (!string.IsNullOrEmpty(commandText))
                        {
                            Execute(conn, transaction, commandText);
                        }
                    }
                }
                ////创建自动编号列
                //foreach (MetaTable table in model.GetTables())
                //{
                //    var create = OracleSqlBuilder.GetCreateSquenceCommand(table);
                //    if (!string.IsNullOrEmpty(create))
                //        Execute(conn, transaction, create);
                //}
                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                conManager.ReleaseConnection(this);
            }
        }
Esempio n. 5
0
        protected override SqlExpression GetReturnIdentityExpression(MetaDataMember idMember, bool isOutputFromInsert)
        {
            var name = OracleSqlBuilder.GetSequenceName(idMember, translator.Provider.SqlIdentifier) + ".CURRVAL";

            return(new SqlVariable(typeof(decimal), typeProvider.From(typeof(decimal)), name, this.dominatingExpression));
        }