MySQL存储过程只返回最后一行数据

MySQL存储过程只返回最后一行数据

本文介绍了MySQL存储过程只返回最后一行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用一个MySQL存储过程,该存储过程应该返回约6000行.但是它仅返回最后一行.看完之后,我看不到为什么它只会返回最后一行信息.

I am calling a MySQL stored procedure that should return about 6000 rows. But it is only returning the very last row. After looking at it, I am unable to see why it will only return the very last row of information.

C#代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Net;
using FileHelpers;
using Stockton;
using System.IO;

namespace MassHistoricalDownload
{
    class Program
    {

        MySqlConnection conn = new MySqlConnection();
        Reference r = new Reference();

        static void Main(string[] args)
        {
            Program p = new Program();
            p.DownloadHistoricData();
        }

        public void DownloadHistoricData()
        {
            conn.ConnectionString = r.getMysqlConnection();
            string historicalDataPath = r.getHistFileLocation();
            string historicalDataExtension = ".csv";

            //Get the list of ticker symbols as well as the last date for which historical data was downloaded for that stock
            conn.Open();
            MySqlCommand myCommand = new MySqlCommand("call stockton.pullHistSymbolAndDate()", conn);
            MySqlDataReader rdr = myCommand.ExecuteReader();

            //Download the files into the HistoricalData file
            while (rdr.Read())
            {
                string stockSymbol = rdr["symbol"].ToString();
                string stockLastDate = rdr["histDate"].ToString();

                //Check if the stockLastDate is empty and put int the oldest date if it is
                if (stockLastDate == null || stockLastDate == string.Empty)
                    stockLastDate = r.getOldestTradeDate().ToString();

                using (WebClient client = new WebClient())
                {
                    using (StreamWriter sw = File.AppendText(Path.Combine(historicalDataPath, stockSymbol + historicalDataExtension)))
                    {

                        sw.Write(client.DownloadString(string.Format(r.getYahooDownloadPart(), stockSymbol, stockLastDate)));
                    }
                }
            }
            conn.Close();
        }
    }

    [IgnoreFirst(1)]
    [DelimitedRecord(",")]
    public class HistoricalStock
    {
        public string infoDate { get; set; }
        public double stockOpen { get; set; }
        public double stockHigh { get; set; }
        public double stockLow { get; set; }
        public double stockClose { get; set; }
        public int stockVolume { get; set; }
        public double adjClose { get; set; }
    }
}

MySQL存储过程

CREATE DEFINER=`meggleston`@`%` PROCEDURE `pullHistSymbolAndDate`()
BEGIN
select
    c.symbol,
    hd.histDate
from
    company c
    left join historical_data hd on
        hd.symbol = c.symbol
        and
        hd.histDate = (select max(histDate) from historical_data where symbol = c.symbol);
END

推荐答案

尝试添加myCommand.CommandType = CommandType.StoredProcedure;

这篇关于MySQL存储过程只返回最后一行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 22:28