예제 #1
0
        /// <summary>
        /// Create a new database with the Table containing the columns specify
        /// </summary>
        /// <param name="fileDB"></param>
        /// <param name="tableName">Table to create</param>
        /// <param name="columns">Columns of the Table</param>
        /// <returns></returns>
        static public SQLiteDataBase CreateDataBase(string fileDB, string tableName, SQLiteColumnsCollection columns)
        {
            try
            {
                if (File.Exists(fileDB))
                {
                    throw new InvalidPathException("The target file \"" + fileDB + "\" already exist!");
                }

                SQLiteConnection.CreateFile(fileDB);
                SQLiteDataBase db  = new SQLiteDataBase(fileDB);
                SQLlog         err = SQLlog.Empty;

                db.OpenConnection();
                db._SQLcommand(SQLiteTable.SQL_AddTable(tableName, columns), out err);

                if (!string.IsNullOrWhiteSpace(err.msgErr))
                {
                    throw err.e;
                }
                db.CloseConnection();
                return(db);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        ////////////
        // STATIC //
        ////////////

        /// <summary>
        /// Load a valid SQLite 3 database file.
        /// </summary>
        /// <param name="fileDB"></param>
        /// <returns></returns>
        static public SQLiteDataBase LoadDataBase(string fileDB)
        {
            if (!File.Exists(fileDB))
            {
                throw new FileNotFoundException();
            }

            SQLiteDataBase db;

            using (FileStream fileStream = new FileStream(fileDB, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                byte[] sql3 = Encoding.ASCII.GetBytes("SQLite format 3");

                for (int i = 0; i < sql3.Length; i++)
                {
                    if (sql3[i] != fileStream.ReadByte())
                    {
                        throw new FileLoadException();
                    }
                }

                if (new SQLiteDataBase(fileDB).GetTablesName().Length <= 0)
                {
                    throw new FileLoadException();
                }

                db = new SQLiteDataBase(fileDB);
            }
            if (db == null)
            {
                throw new FileLoadException();
            }

            return(db);
        }
예제 #3
0
        /// <summary>
        /// Create a basic instance for work with <see cref="SQLiteDataBase"/>
        /// </summary>
        /// <remarks>If the connection is opened by this constructor, they will be closed if the instance is dispose.</remarks>
        /// <param name="db">The target database</param>
        /// <param name="openConnection">Open the connection with the data base</param>
        public SQLiteEdit(SQLiteDataBase db, bool openConnection)
        {
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }

            disposed = false;
            DataBase = db;

            OpenOnStart = ConnectionIsOpen;
            if (openConnection && !ConnectionIsOpen && !this.OpenConnection())
            {
                throw new System.Data.SQLite.SQLiteException(System.Data.SQLite.SQLiteErrorCode.CantOpen, "Database is not open");
            }
        }
예제 #4
0
 /// <summary>
 /// Create a basic instance for work with <see cref="SQLiteDataBase"/>
 /// </summary>
 /// <param name="db">The target database</param>
 public SQLiteEdit(SQLiteDataBase db) : this(db, false)
 {
 }
예제 #5
0
 /// <summary>
 /// Create a specialized instance for work with the table content of a <see cref="SQLiteDataBase"/>
 /// </summary>
 /// <remarks>If the connection is opened by this constructor, they will be closed if the instance is dispose.</remarks>
 /// <param name="db">The target database</param>
 /// <param name="openConnection">Open the connection with the data base</param>
 public SQLiteData(SQLiteDataBase db, bool openConnection) : base(db, openConnection)
 {
     clsName = nameof(SQLiteData);
 }
예제 #6
0
 /// <summary>
 /// Create a basic instance for work with <see cref="SQLiteDataBase"/>
 /// </summary>
 /// <param name="db">The target database</param>
 public SQLiteMaster(SQLiteDataBase db) : this(db, false)
 {
 }
예제 #7
0
 /// <summary>
 /// Create a basic instance for work with <see cref="SQLitePragmas"/>
 /// </summary>
 /// <param name="db">The target database</param>
 public SQLitePragmas(SQLiteDataBase db) : base(db, false)
 {
     clsName = nameof(SQLitePragmas);
 }
예제 #8
0
 /// <summary>
 /// Create a basic instance for work with <see cref="SQLiteDataBase"/>
 /// </summary>
 /// <remarks>If the connection is opened by this constructor, they will be closed if the instance is dispose.</remarks>
 /// <param name="db">The target database</param>
 public SQLiteTable(SQLiteDataBase db) : this(db, false)
 {
 }