예제 #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
        /// <summary>
        /// Add columns to the table
        /// </summary>
        /// <param name="tableName">Table to edit; Cannot be null or empty</param>
        /// <param name="columns">Columns to add to the table; Cannot be null or empty</param>
        /// <param name="msgErr"></param>
        /// <returns></returns>
        public int AddColumns(string tableName, SQLiteColumnsCollection columns, out SQLlog msgErr)
        {
            if (columns == null)
            {
                throw new ArgumentNullException(nameof(columns));
            }
            if (columns.Count == 0)
            {
                throw new ArgumentException("SQLiteColumns cannot be empty", nameof(columns));
            }

            msgErr = SQLlog.Empty;
            int i = 0;

            foreach (SQLiteColumn item in columns.Values)
            {
                AddColumn(tableName, item, out msgErr);
                if (!msgErr.Succes)
                {
                    return(i);
                }

                i++;
            }
            return(i);
        }
예제 #3
0
        /// <summary>
        /// Create a SQL request for a new table with the specified columns
        /// </summary>
        /// <param name="tableName">Table to add; Cannot be null or empty</param>
        /// <param name="columns">Columns assigned to the table; Cannot be null or empty</param>
        static public string SQL_AddTable(string tableName, SQLiteColumnsCollection columns)
        {
            if (string.IsNullOrWhiteSpace(tableName))
            {
                throw new ArgumentNullException(nameof(tableName));
            }
            if (columns == null)
            {
                throw new ArgumentNullException(nameof(columns));
            }
            if (columns.Count == 0)
            {
                throw new ArgumentException("SQLiteColumns cannot be empty", nameof(columns));
            }

            return("CREATE TABLE " + tableName.ToSQLiteFormat() + " (" + columns.ToString() + ")" + ";");
        }
예제 #4
0
 /// <summary>
 /// Create new table with the specified columns
 /// </summary>
 /// <param name="tableName">Table to add; Cannot be null or empty</param>
 /// <param name="columns">Columns assigned to the table; Cannot be null or empty</param>
 /// <param name="msgErr"></param>
 /// <returns></returns>
 public int AddTable(string tableName, SQLiteColumnsCollection columns, out SQLlog msgErr)
 {
     return(ExecuteSQLcommand(SQL_AddTable(tableName, columns), out msgErr));
 }