예제 #1
0
        }// CreateDatabaseFile()

        /// <summary>
        /// Creates a new SQLite database file if missing.
        /// </summary>
        /// <param name="databaseFilePath">Path of the new SQLite database file to create.</param>
        /// <param name="password">Password to set on database.</param>
        /// <exception cref="OrionException">File already exists or database can't be created. <see cref="Exception.Data"/> dictionnary contains <i>DatabaseFilePath</i> key with provided file path as value.</exception>
        /// <seealso cref="OrionException" />
        //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "N/A")]
        static public void CreateDatabaseFile(String databaseFilePath, String password)
        {
            OrionDatabaseSQLite xBase;

            xBase = null;

            // Check if the database file path is not null, not an empty string, and valid.
            OrionDatabaseSQLite.CheckPathValidity(databaseFilePath);

            //** Check if the database file path indicates an existing file **
            if (File.Exists(databaseFilePath) == false)
            {
                try
                {
                    SQLiteConnection.CreateFile(databaseFilePath);
                }
                catch (Exception ex)
                {
                    throw new OrionException("Database can't be created.", ex, "DatabaseFilePath=" + databaseFilePath);
                }

                try
                {
                    xBase = new OrionDatabaseSQLite(databaseFilePath);
                }
                catch (OrionException ex)
                {
                    throw new OrionException("Can't create XDatabaseSQLite object;", ex, "DatabaseFilePath=" + databaseFilePath);
                }

                if (String.IsNullOrWhiteSpace(password) == false)
                {
                    try
                    {
                        xBase.SetPassword(password, false);
                    }
                    catch (Exception ex)
                    {
                        throw new OrionException("Password can't be set.", ex, "DatabaseFilePath=" + databaseFilePath);
                    }
                }
            }
            else
            {
                throw new OrionException("The specified SQLite database file already exists.", "DatabaseFilePath=" + databaseFilePath);
            }
        }// CreateDatabaseFile()
예제 #2
0
        }// OrionDatabaseSQLite()

        #endregion

        #region Initializations
        private void Initialize(String databaseFilePath, String password)
        {
            this.ParameterCharacter = '@';

            //** Check if the database file path is valid and indicates an existing file **
            OrionDatabaseSQLite.CheckPathValidity(databaseFilePath, true);

            this.ConnectionStringBuilder = new SQLiteConnectionStringBuilder();

            base.Initialize();

            this.ConnectionStringBuilder["Data Source"]   = databaseFilePath;
            this.ConnectionStringBuilder["Version"]       = "3";
            this.ConnectionStringBuilder["FailIfMissing"] = Boolean.FalseString;

            // Add password if needed.
            if (String.IsNullOrEmpty(password) == false)
            {
                this.ConnectionStringBuilder["Password"] = password;
            }

            // Create the ADO.Net connection
            this.Connection = new SQLiteConnection(this.ConnectionStringBuilder.ConnectionString, true);
        }// Initialize()
예제 #3
0
        }// CreateDataAdapter()

        #endregion

        #region Public interface
        /// <summary>
        /// Creates a new SQLite database file if missing.
        /// </summary>
        /// <param name="databaseFilePath">Path of the new SQLite database file to create.</param>
        /// <exception cref="OrionException">File already exists or database can't be created. <see cref="Exception.Data"/> dictionnary contains <i>DatabaseFilePath</i> key with provided file path as value.</exception>
        /// <seealso cref="OrionException" />
        static public void CreateDatabaseFile(String databaseFilePath)
        {
            OrionDatabaseSQLite.CreateDatabaseFile(databaseFilePath, null);
        }// CreateDatabaseFile()