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

            //return new SqlMemberAssign(member.Member, exp);
            return(exp);
        }
Exemplo n.º 2
0
        protected override SqlExpression GetReturnIdentityExpression(MetaDataMember idMember, bool isOutputFromInsert)
        {
            var name = "CURRVAL('" + PgsqlBuilder.GetSequenceName(idMember, translator.Provider.SqlIdentifier) + "') FROM " + idMember.DeclaringType.Table.TableName;//OracleSqlBuilder.GetSequenceName(idMember, translator.Provider.SqlIdentifier) + ".CURRVAL";

            return(new SqlVariable(idMember.Type, typeProvider.From(idMember.Type), name, this.dominatingExpression));
        }
Exemplo n.º 3
0
        public void CreateDatabase()
        {
            if (DatabaseExists())
            {
                throw SqlClient.Error.CreateDatabaseFailedBecauseSqlCEDatabaseAlreadyExists(dbName);
            }

            var connection = new NpgsqlConnection(GetConnectionString(string.Empty));

            connection.Open();
            try
            {
                Execute(connection, null, PgsqlBuilder.GetCreateDatabaseCommand(dbName, null, null));
            }
            finally
            {
                connection.Close();
            }

            connection.ConnectionString = GetConnectionString(dbName);
            connection.Open();
            var transaction = connection.BeginTransaction();

            try
            {
                var       builder = new PgsqlBuilder(this);
                MetaModel model   = services.Model;
                foreach (MetaTable table in model.GetTables())
                {
                    string createTableCommand = builder.GetCreateTableCommand(table);

                    if (!string.IsNullOrEmpty(createTableCommand))
                    {
                        Execute(connection, transaction, createTableCommand);
                    }
                }
                foreach (MetaTable metaTable in model.GetTables())
                {
                    var command = builder.GetPrimaryKeyCommand(metaTable);
                    if (!string.IsNullOrEmpty(command))
                    {
                        Execute(connection, transaction, command);
                    }
                }
                foreach (MetaTable metaTable in model.GetTables())
                {
                    //创建自动编号列
                    var command = SqlBuilder.GetCreateSquenceCommand(metaTable);
                    if (!string.IsNullOrEmpty(command))
                    {
                        services.Context.ExecuteCommand(command);
                    }
                }
                foreach (MetaTable table in model.GetTables())
                {
                    foreach (string commandText in builder.GetCreateForeignKeyCommands(table))
                    {
                        if (!string.IsNullOrEmpty(commandText))
                        {
                            Execute(connection, transaction, commandText);
                        }
                    }
                }

                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                connection.Close();
            }
        }