Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }