Exemple #1
0
        internal Database(IDbConnection connection, string mainConnectionString, string databaseName = null)
        {
            Connection = connection;
            this.mainConnectionString = mainConnectionString;
            connectionString          = connection.ConnectionString;
            DatabaseName = databaseName ?? connection.Database;

            Dapper                   = new Infrastructure.Dapper(connection);
            Tables                   = new TableCollection(this);
            NamingConvention         = new NamingConvention(MaxIdentifierLength);
            DataDefinitionLanguage   = new DataDefinitionLanguage(this);
            dataManipulationLanguage = new DataManipulationLanguage(this);
            structuredQueryLanguage  = new StructuredQueryLanguage(this);
            InformationSchema        = new InformationSchema(this);
        }
Exemple #2
0
        /// <summary>
        /// Creates the database in the context given, granting the administrative
        /// control to the user identified by the given name and password.
        /// </summary>
        /// <param name="adminName">The name of the administrator.</param>
        /// <param name="adminPassword">The password used to identify the administrator.</param>
        /// <exception cref="DatabaseSystemException">
        /// If the database context is configured to be in read-only model, if it was not possible
        /// to commit the initial information or if another unhanded error occurred while
        /// creating the database.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If either one of <paramref name="adminName"/> or <paramref name="adminPassword"/>
        /// are <c>null</c> or empty.
        /// </exception>
        /// <remarks>
        /// <para>
        /// The properties used to create the database are extracted from
        /// the underlying context (<see cref="DatabaseContext" />).
        /// </para>
        /// <para>
        /// This method does not automatically open the database: to make it accessible
        /// a call to <see cref="Open" /> is required.
        /// </para>
        /// </remarks>
        /// <seealso cref="IDatabaseContext.Configuration" />
        public void Create(string adminName, string adminPassword)
        {
            if (Context.ReadOnly())
            {
                throw new DatabaseSystemException("Cannot create database in read-only mode.");
            }

            if (String.IsNullOrEmpty(adminName))
            {
                throw new ArgumentNullException("adminName");
            }
            if (String.IsNullOrEmpty(adminPassword))
            {
                throw new ArgumentNullException("adminPassword");
            }

            try {
                // Create the conglomerate
                TableComposite.Create();

                using (var session = this.CreateInitialSystemSession()) {
                    using (var context = session.CreateQuery()) {
                        try {
                            session.CurrentSchema(SystemSchema.Name);

                            // Create the schema information tables
                            CreateSchemata(context);

                            // The system tables that are present in every conglomerate.
                            SystemSchema.CreateTables(context);
                            SystemGroups.Create(context);

                            context.CreatePublicUser();

                            // Create the system views
                            InformationSchema.CreateViews(context);
                            InformationSchema.GrantToPublic(context);

                            this.CreateAdminUser(context, adminName, adminPassword);

                            SetCurrentDataVersion(context);

                            // Set all default system procedures.
                            // TODO: SystemSchema.SetupSystemFunctions(session, username);

                            OnDatabaseCreate(context);

                            try {
                                // Close and commit this transaction.
                                session.Commit();
                            } catch (TransactionException e) {
                                throw new DatabaseSystemException("Could not commit the initial information", e);
                            }
                        } catch (DatabaseSystemException) {
                            throw;
                        } catch (Exception ex) {
                            throw new DatabaseSystemException("An error occurred while creating the database.", ex);
                        }
                    }
                }

                // Close the conglomerate.
                TableComposite.Close();
            } catch (DatabaseSystemException) {
                throw;
            } catch (Exception e) {
                throw new DatabaseSystemException("An error occurred while creating the database.", e);
            }
        }
Exemple #3
0
 private static void GetData(string connectionString, out DataTable tables, out DataTable columns, out DataTable primaryKeys)
 {
     using (var info = new InformationSchema(connectionString))
     {
         tables = info.Tables;
         columns = info.Columns;
         primaryKeys = info.PrimaryKeys;
     }
 }
Exemple #4
0
 internal override string GetColumnDataType(string tableName, string columnName)
 {
     return(InformationSchema.GetColumnDataType(tableName, columnName, "character varying", "character", "numeric", "interval"));
 }
 internal override string GetColumnDataType(string tableName, string columnName)
 {
     return(InformationSchema.GetColumnDataType(tableName, columnName, "decimal", "nvarchar", "nchar", "varchar", "char", "time"));
 }