Ejemplo n.º 1
0
        /// <summary>
        /// Select an entire table and returns a list of the (T) line objects.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public List <T> SelectAll <T>(GenericDatabaseLine myLine)
        {
            string SelectUndlDataEOD = "SELECT * from " + myLine.GetTable();

            using (var connection = new MySqlConnection(connectionString))
            {
                var res = connection.Query <T>(SelectUndlDataEOD);
                return((List <T>)res);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Insert data into a table. Data is passed as a list of DB lines.
        /// The DB line type must (i) be a subclass of GenericDatabaseLine and (ii) match the given table columns.
        /// </summary>
        /// <param name="argTable"></param>
        /// <param name="argLineToInsert"></param>

        /*
         * public void Insert<T>(IDtoken id, List<T> argLineToInsert) where T : GenericDatabaseLine
         * {
         *  foreach (T singleLine in argLineToInsert)
         *  {
         *      Insert<T>(id, singleLine);
         *  }
         * }
         *
         *
         */
        /*
         * public void Insert<T>(IDtoken id, T argLineToInsert) where T : GenericDatabaseLine
         * {
         *  // Identify table to be addressed
         *  string table = argLineToInsert.GetTable();
         *
         *  // Build SQL command string
         *  //DateTime dt = (argLineToInsert as T).GetDate();
         *
         *
         *  string insert_table = "INSERT into " + table;
         *  string insert_fields = "(" + joinString(argLineToInsert.GetAllFields(), " ,", false) + ")";
         *  string insert_values = "values (" + joinStringWithDate(argLineToInsert.GetAllFields(), " ,", true) + ")";
         *  string InsertUndlDataEOD = joinString(new List<string>() { insert_table, insert_fields, insert_values }, " ", false);
         *
         *  // Execute SQL command
         *  using (var connection = new MySqlConnection(connectionString))
         *  {
         *      connection.Execute(InsertUndlDataEOD, argLineToInsert);
         *  }
         *
         * }
         *
         */

        #endregion


        // ************************************************************
        // METHODS -- UPDATE
        // ************************************************************

        #region

        /// <summary>
        /// Update data for a given set of table, ticker and date.
        /// Data is passed in the form of a DB line (subclass of GenericDatabaseLine).
        /// </summary>
        /// <param name="argTable"></param>
        /// <param name="argLineToUpdate"></param>
        /// <param name="updateFields"></param>
        public void Update(GenericDatabaseLine argLineToUpdate, List <string> updateFields)
        {
            // Identify table to be addressed
            string table = argLineToUpdate.GetTable();

            // Construct the command string
            string update_dataValues = buildUpdateStringData(table, argLineToUpdate.GetDataFields());
            string update_keys       = buildUpdateStringKeys(argLineToUpdate.GetKeyFields());
            string updateString      = joinString(new List <string>()
            {
                update_dataValues, update_keys
            }, " ", false);

            // Execute the command
            using (var connection = new MySqlConnection(connectionString))
            {
                connection.Execute(updateString, argLineToUpdate);
            }
        }
Ejemplo n.º 3
0
        // ************************************************************
        // METHODS -- DELETE
        // ************************************************************

        #region Delete

        /// <summary>
        /// Delete an entire line from a table. The keys to identify the line are passed in a DB line (subclass of GenericDatabaseLine).
        /// </summary>
        /// <param name="argTable"></param>
        /// <param name="myLine"></param>
        public void EraseLine(GenericDatabaseLine myLine)
        {
            // Get string with table name
            string table = myLine.GetTable();

            //Check date
            DateTime myStartDate = (myLine.Date == DateTime.MinValue) ? myStartDate = new DateTime(2013, 12, 31) : myStartDate = myLine.Date;

            // Build string from start date
            string startDateForRequest = this.buildDateString(myStartDate);

            // Build mySQL Delete command string
            string mySQLDeleteCommand = joinString(new List <string>()
            {
                buildDeleteStringData(table), buildDeleteStringKeys(myLine.GetKeyFields())
            }, " ", false);

            // Execute the command
            using (var connection = new MySqlConnection(connectionString))
            {
                connection.Execute(mySQLDeleteCommand, myLine);
            }
        }