This is currently rendering the module unusable. I tried extended quotes with just a single symbol - GHL and got this error:
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'chg_52_week_low' at row 1: UPDATE {stockapi} SET name=:db_update_placeholder_0, last_trade_price_only=:db_update_placeholder_1, last_trade_date=:db_update_placeholder_2, last_trade_time=:db_update_placeholder_3, chg=:db_update_placeholder_4, pct_chg=:db_update_placeholder_5, volume=:db_update_placeholder_6, avg_daily_volume=:db_update_placeholder_7, bid=:db_update_placeholder_8, ask=:db_update_placeholder_9, previous_close=:db_update_placeholder_10, open=:db_update_placeholder_11, days_range=:db_update_placeholder_12, 52_week_range=:db_update_placeholder_13, eps=:db_update_placeholder_14, pe_ratio=:db_update_placeholder_15, dividend_pay_date=:db_update_placeholder_16, dividend_per_share=:db_update_placeholder_17, dividend_yield=:db_update_placeholder_18, market_cap=:db_update_placeholder_19, exchange=:db_update_placeholder_20, chg_and_pct_chg=:db_update_placeholder_21, short_ratio=:db_update_placeholder_22, one_yr_target_price=:db_update_placeholder_23, eps_est_current_yr=:db_update_placeholder_24, eps_est_next_year=:db_update_placeholder_25, eps_est_next_quarter=:db_update_placeholder_26, price_per_eps_est_current_year=:db_update_placeholder_27, price_per_eps_est_next_year=:db_update_placeholder_28, peg_ratio=:db_update_placeholder_29, book_value=:db_update_placeholder_30, price_per_book=:db_update_placeholder_31, price_per_sales=:db_update_placeholder_32, ebitda=:db_update_placeholder_33, 50_day_moving_average=:db_update_placeholder_34, 200_day_moving_average=:db_update_placeholder_35, last_trade_size=:db_update_placeholder_36, ticker_trend=:db_update_placeholder_37, more_info=:db_update_placeholder_38, trade_links=:db_update_placeholder_39, chg_52_week_low=:db_update_placeholder_40, order_book_rt=:db_update_placeholder_41, after_hours_change_rt=:db_update_placeholder_42, pe_rt=:db_update_placeholder_43, holdings_gain_rt=:db_update_placeholder_44, holdings_gain_pct_rt=:db_update_placeholder_45, days_value_chg_rt=:db_update_placeholder_46, holdings_value_rt=:db_update_placeholder_47, notes=:db_update_placeholder_48, highlimit=:db_update_placeholder_49, lowlimit=:db_update_placeholder_50, annualized_gain=:db_update_placeholder_51, trade_date=:db_update_placeholder_52, holdings_gain=:db_update_placeholder_53, holdings_gain_pct=:db_update_placeholder_54, days_value_change=:db_update_placeholder_55, holdings_value=:db_update_placeholder_56, commission=:db_update_placeholder_57, price_paid=:db_update_placeholder_58, shares_owned=:db_update_placeholder_59, pct_chg_frm_200_day_ma=:db_update_placeholder_60, chg_frm_200_day_ma=:db_update_placeholder_61, pct_chg_frm_50_day_ma=:db_update_placeholder_62, chg_frm_50_day_ma=:db_update_placeholder_63, ex_dividend_date=:db_update_placeholder_64, pct_chg_from_52_wk_high=:db_update_placeholder_65, chg_from_52_wk_high=:db_update_placeholder_66, pct_chg_from_52_wk_low=:db_update_placeholder_67, updated=:db_update_placeholder_68 WHERE (symbol = :db_condition_placeholder_0) ; Array ( [:db_update_placeholder_0] => Apple Inc. [:db_update_placeholder_1] => 426.31 [:db_update_placeholder_2] => 7/22/2013 [:db_update_placeholder_3] => 4:00pm [:db_update_placeholder_4] => +1.36 [:db_update_placeholder_5] => +0.32% [:db_update_placeholder_6] => 7417138 [:db_update_placeholder_7] => 14211800 [:db_update_placeholder_8] => 425.70 [:db_update_placeholder_9] => 425.80 [:db_update_placeholder_10] => 424.95 [:db_update_placeholder_11] => 429.55 [:db_update_placeholder_12] => 425.468 - 429.75 [:db_update_placeholder_13] => 385.10 - 705.07 [:db_update_placeholder_14] => 41.896 [:db_update_placeholder_15] => 10.14 [:db_update_placeholder_16] => May 16 [:db_update_placeholder_17] => 11.00 [:db_update_placeholder_18] => 2.59 [:db_update_placeholder_19] => 0 [:db_update_placeholder_20] => NasdaqNM [:db_update_placeholder_21] => +1.36 - +0.32% [:db_update_placeholder_22] => 2.20 [:db_update_placeholder_23] => 538.44 [:db_update_placeholder_24] => 39.41 [:db_update_placeholder_25] => 43.34 [:db_update_placeholder_26] => 8.08 [:db_update_placeholder_27] => 10.78 [:db_update_placeholder_28] => 9.81 [:db_update_placeholder_29] => 0.52 [:db_update_placeholder_30] => 144.124 [:db_update_placeholder_31] => 2.95 [:db_update_placeholder_32] => 2.36 [:db_update_placeholder_33] => 57.381B [:db_update_placeholder_34] => 425.229 [:db_update_placeholder_35] => 445.366 [:db_update_placeholder_36] => 872 [:db_update_placeholder_37] => 997 [:db_update_placeholder_38] => ++-+== [:db_update_placeholder_39] => cnsprmiIed [:db_update_placeholder_40] => <a href=http://edit.finance.yahoo.com/ef?.intl=us&.done=http://finance.yahoo.com/d/quotes.csvr%3fs%3dGHL%20AAPL%20INTC%20IBM%20HPQ%20GOOG%20MSFT%20GE%20DIS%20DELL%20AMZN%26f%3dsnl1d1t1c1p2va2bapomwerr1dyj1xcs7t8e7e8e9r6r7r5b4p6p5j4m3m4k3t7it6j5i5c8r2g6g5w4v7n4l2l3g3d2g4g1w1v1c3p1s1m6m5m8m7qk5k4j6%26e%3d.csv">Choose Brokerage</a> [:db_update_placeholder_41] => +41.21 [:db_update_placeholder_42] => N/A [:db_update_placeholder_43] => N/A - N/A [:db_update_placeholder_44] => N/A [:db_update_placeholder_45] => N/A [:db_update_placeholder_46] => N/A - N/A [:db_update_placeholder_47] => N/A - N/A [:db_update_placeholder_48] => N/A [:db_update_placeholder_49] => - [:db_update_placeholder_50] => - [:db_update_placeholder_51] => - [:db_update_placeholder_52] => - [:db_update_placeholder_53] => - [:db_update_placeholder_54] => - [:db_update_placeholder_55] => - - - [:db_update_placeholder_56] => - - +0.32% [:db_update_placeholder_57] => - [:db_update_placeholder_58] => 0 [:db_update_placeholder_59] => - [:db_update_placeholder_60] => - [:db_update_placeholder_61] => -4.28% [:db_update_placeholder_62] => -19.056 [:db_update_placeholder_63] => +0.25% [:db_update_placeholder_64] => +1.081 [:db_update_placeholder_65] => May 9 [:db_update_placeholder_66] => -39.54% [:db_update_placeholder_67] => -278.76 [:db_update_placeholder_68] => 1374529739 [:db_condition_placeholder_0] => AAPL ) in stockapi_save() (line 68 of /srv/bindings/1b7a6ee44a4e440694ca9f424e75a47d/code/sites/all/modules/stockapi/stockapi.inc).
As you can see it's trying to drop a whole link tag into that field:
[:db_update_placeholder_40] => <a href=http://edit.finance.yahoo.com/ef?.intl=us&.done=http://finance.yahoo.com/d/quotes.csvr%3fs%3dGHL%20AAPL%20INTC%20IBM%20HPQ%20GOOG%20MSFT%20GE%20DIS%20DELL%20AMZN%26f%3dsnl1d1t1c1p2va2bapomwerr1dyj1xcs7t8e7e8e9r6r7r5b4p6p5j4m3m4k3t7it6j5i5c8r2g6g5w4v7n4l2l3g3d2g4g1w1v1c3p1s1m6m5m8m7qk5k4j6%26e%3d.csv">Choose Brokerage</a>
Looks like the variables are going into the wrong fields, that should have been the trade links field right before chg_52_week_low.
Comments
Comment #1
andy.alexander commentedThis appears to be because some of the fields have commas and aren't being properly enclosed in quotes.
The issue is inside stockapi_fetch(), trying to figure out how to fix it.
Comment #2
andy.alexander commentedThe solution, as far as I can tell, is converting the query from the CSV API to the YQL API, but I'm not familiar with the YQL API
EDIT: This is not correct. More information in comment below.
Comment #3
andy.alexander commentedThis is due to a parsing error.
Some fields have values in the thousands, say, for a given example, 3,600, only this value is unquoted.
This breaks the parsing, because it doesn't expect to be separated there.
As a temporary measure, testing that the correct amount of values is in a particular stock array is a possible solution.
Here's a theoretical way to do it, inside _stockapi_parse_csv():
and to ensure the correct value is calculated for the $quote_length variable, this change to stockapi_get_quotetype():
Doing this requires changing stockapi.install for the new quotetypes (with the 0s included in the query)
Comment #4
andy.alexander commentedI'm also noticing that it appears to be off by 1 (I'm trying to figure out why), so in the mean-time, it may be best to have the conditional be the following:
Comment #5
andy.alexander commentedScrap my old changes to _stockapi_parse_csv, they don't seem to work nice with the changes that were made in the new dev version.
Here's a better warning system:
I'm still getting a lot of error messages with this, but now it just doesn't parse any stocks that cause issues - this will prevent hanging over a given field.
We need to figure out a better solution for the parsing problem though.
One solution would be to redirect aberrant stock values to another function, where we could look for common exceptions - what fields are frequently going to have a comma, for example.
Comment #6
dakalaAt the moment the code in the dev version parses the CSV with commas correctly. See the output in response to your post here: https://www.drupal.org/node/1902212#comment-9342791
If you let me know the symbols and quote types you're having the comma issues with, I can give it a go and find a better way to do the parsing.
Comment #7
dakalaWith the code in dev, here's the output for the extended type:
Each array has 36 elements. I can't see any formatted integers with thousand marks anywhere.
Comment #8
andy.alexander commentedI'm getting 68 keys with the extended?
And I'm using a lot of stocks - it's only on certain stocks that these values appear. I can try to find one for you later.
Comment #9
joseph.olstadUpgrade to 7.x-2.x