Esempio n. 1
0
        /// <summary>
        /// Creata data base
        /// </summary>
        /// <returns><see cref="DataBase"/></returns>
        public DataBase Create()
        {
            var connectionBuilder = new ConnectionBuilder(Dialect, Connection);

            if (Dialect is MySQLDialect)
            {
                Connection.ConnectionString = connectionBuilder
                    .With("Server", connectionBuilder.GetValueOfPart("Server"))
                    .With("User Id", connectionBuilder.GetValueOfPart("User Id"))
                    .With("Password", connectionBuilder.GetValueOfPart("Password"))
                    .Builder()
                    .ConnectionString;

                ExecuteCommand(string.Format("CREATE DATABASE IF NOT EXISTS {0};", Connection.Database), Connection);
            }
            else if (Dialect is MsSql2000Dialect)
            {
                Connection.ConnectionString = connectionBuilder
                    .With("Server", connectionBuilder.GetValueOfPart("Server"))
                    .With("User Id", connectionBuilder.GetValueOfPart("User Id"))
                    .With("Password", connectionBuilder.GetValueOfPart("Password"))
                    .Builder()
                    .ConnectionString;

                ExecuteCommand(string.Format("IF NOT(EXISTS(SELECT * FROM sys.sysdatabases where name='{0}')) BEGIN CREATE DATABASE {0}; END", Connection.Database), Connection);
            }

            Connection = ConnectionFactory.Factory(Configuration, Dialect);

            new SchemaExport(SessionManager.Configuration).Create(false, true);

            return this;
        }
Esempio n. 2
0
        private string GetConnectionString()
        {
            var connectionBuilder = new ConnectionBuilder(Dialect, Connection);

            if (Dialect is MySQLDialect)
            {
                return connectionBuilder
                    .With("Server", connectionBuilder.GetValueOfPart("Server"))
                    .With("User Id", connectionBuilder.GetValueOfPart("User Id"))
                    .With("Password", connectionBuilder.GetValueOfPart("Password"))
                    .Builder()
                    .ConnectionString;
            }

            if (Dialect is MsSql2000Dialect)
            {
                return connectionBuilder
                    .With("Server", connectionBuilder.GetValueOfPart("Server"))
                    .With("User Id", connectionBuilder.GetValueOfPart("User Id"))
                    .With("Password", connectionBuilder.GetValueOfPart("Password"))
                    .Builder()
                    .ConnectionString;
            }

            if (Dialect is PostgreSQLDialect)
            {
                return connectionBuilder
                    .With("Host", connectionBuilder.GetValueOfPart("Host"))
                    .With("User Id", connectionBuilder.GetValueOfPart("User Id"))
                    .With("Password", connectionBuilder.GetValueOfPart("Password"))
                    .With("Port", connectionBuilder.GetValueOfPart("Port"))
                    .With("DataBase", connectionBuilder.GetValueOfPart("DataBase"))
                    .Builder()
                    .ConnectionString;
            }

            return string.Empty;
        }
Esempio n. 3
0
        /// <summary>
        /// Drop data base
        /// </summary>
        /// <returns><see cref="DataBase"/></returns>
        public DataBase Drop()
        {
            var connectionBuilder = new ConnectionBuilder(Dialect, Connection);

            if (Dialect is MySQLDialect)
            {
                Connection.ConnectionString = connectionBuilder
                    .With("Server", connectionBuilder.GetValueOfPart("Server"))
                    .With("User Id", connectionBuilder.GetValueOfPart("User Id"))
                    .With("Password", connectionBuilder.GetValueOfPart("Password"))
                    .Builder()
                    .ConnectionString;

                ExecuteCommand(string.Format("DROP DATABASE IF EXISTS {0};", Connection.Database), Connection);
            }

            Connection = ConnectionFactory.Factory(Configuration, Dialect);

            return this;
        }